diff --git a/.gitignore b/.gitignore index 22aac4910..1d70ba0e5 100755 --- a/.gitignore +++ b/.gitignore @@ -150,4 +150,69 @@ iguana/DB/DEX.log iguana/iguana_notary.o-54f98cc3 +iguana/basilisk.o-2ad8cb38 iguana/pangea_hand.o-02d25ec3 + +iguana/confs/4dfa301d0adf61f0ec08e4d4cb4444f4fc377f45f5d6b1da0814033920d72353 + +iguana/help.json + +iguana/index7778.html + +*.json + +iguana/DB/KMD/utxo.dat + +iguana/unparsed.txt + +iguana/unparsed.txt + +iguana/unparsed.txt + +iguana/DB/SWAPS/.tmpmarker + +iguana/DB/SWAPS/list + +iguana/DB/SWAPS/15974209-4014252807 + +iguana/iguana777.o-0cc60f50 + +iguana/DB/SWAPS/667293271-3414303895 + +iguana/DB/SWAPS/667293271-3414303895.swap + +iguana/DB/SWAPS/548227681-1452262678.swap + +iguana/DB/SWAPS/548227681-1452262678 + +*.bobdeposit + +*.bobpayment + +*.bobreclaim + +*.bobrefund + +*.swap + +iguana/DB/SWAPS/1268007736-526212866 + +iguana/DB/SWAPS/3111936786-3185288772 + +iguana/DB/SWAPS/3368214189-2405641584 + +iguana/DB/SWAPS/1133671270-1840176506 + +iguana/DB/SWAPS/467927158-3437055573 + +iguana/DB/SWAPS/270159951-1269722638 + +iguana/DB/SWAPS/244991424-1008712592 + +iguana/confs/1cc0270abba7f4463a3dcb9908b9d875691a6773fe3cc1b4302233ed76665300 + +iguana/autoAPI.md + +iguana/confs/5228bcea7ae2515a29c3844673de6ee2acba53bf45724744a00ff4306f192912 + +iguana/confs/630929d976025fafde221c7358eb5805f4359bad3c6b8bd50ad3f6e0a9b5ce78 diff --git a/OSlibs/win/libcrypto-1_1.dll b/OSlibs/win/libcrypto-1_1.dll new file mode 100644 index 000000000..4b16b67be Binary files /dev/null and b/OSlibs/win/libcrypto-1_1.dll differ diff --git a/OSlibs/win/libcurl.dll b/OSlibs/win/libcurl.dll new file mode 100644 index 000000000..8c80e23eb Binary files /dev/null and b/OSlibs/win/libcurl.dll differ diff --git a/OSlibs/win/libcurl.exp b/OSlibs/win/libcurl.exp new file mode 100644 index 000000000..a2b9da989 Binary files /dev/null and b/OSlibs/win/libcurl.exp differ diff --git a/OSlibs/win/libcurl.lib b/OSlibs/win/libcurl.lib new file mode 100644 index 000000000..c2b00f3c8 Binary files /dev/null and b/OSlibs/win/libcurl.lib differ diff --git a/OSlibs/win/libssl-1_1.dll b/OSlibs/win/libssl-1_1.dll new file mode 100644 index 000000000..dee38788d Binary files /dev/null and b/OSlibs/win/libssl-1_1.dll differ diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 3ab1ea6a3..ba880e2e6 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -482,6 +482,7 @@ int32_t basilisk_relayid(struct supernet_info *myinfo,uint32_t ipbits) #include "basilisk_ether.c" #include "basilisk_waves.c" #include "basilisk_lisk.c" +#include "smartaddress.c" #include "basilisk_MSG.c" #include "tradebots_marketmaker.c" @@ -492,6 +493,7 @@ int32_t basilisk_relayid(struct supernet_info *myinfo,uint32_t ipbits) #include "basilisk_ping.c" #include "basilisk_vote.c" #include "basilisk_CMD.c" +#include "jumblr.c" void basilisk_functions(struct iguana_info *coin,int32_t protocol) { @@ -870,7 +872,7 @@ int32_t basilisk_issued_purge(struct supernet_info *myinfo,int32_t timepad) void basilisks_loop(void *arg) { static uint32_t counter; - struct iguana_info *relay; struct supernet_info *myinfo = arg; int32_t iter; double startmilli,endmilli; struct dpow_info *dp; + struct iguana_info *relay; struct supernet_info *myinfo = arg; int32_t iter; double startmilli,endmilli; struct dpow_info *dp; iter = 0; relay = iguana_coinfind("RELAY"); printf("start basilisk loop\n"); @@ -951,6 +953,436 @@ void basilisks_init(struct supernet_info *myinfo) #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" +#include "../includes/iguana_apideclares2.h" + +TWO_STRINGS(tradebot,gensvm,base,rel) +{ +#ifdef _WIN + return(clonestr("{\"error\":\"windows doesnt support SVM\"}")); +#else + int32_t numfeatures = 317*61; + struct tradebot_arbpair *pair; + if ( base[0] != 0 && rel[0] != 0 && (pair= tradebots_arbpair_find(base,rel)) != 0 && pair->fp != 0 ) + { + tradebots_calcanswers(pair); + ocas_gen(pair->refc,numfeatures,0,(int32_t)(ftell(pair->fp) / sizeof(pair->rawfeatures))); + return(clonestr("{\"result\":\"success\"}")); + } else return(clonestr("{\"error\":\"cant find arbpair\"}")); +#endif +} + +ZERO_ARGS(tradebot,openliquidity) +{ + int32_t i; cJSON *array = cJSON_CreateArray(); + for (i=0; ilinfos)/sizeof(*myinfo->linfos); i++) + { + if ( myinfo->linfos[i].base[0] != 0 ) + jaddi(array,linfo_json(&myinfo->linfos[i])); + } + return(jprint(array,1)); +} + +ZERO_ARGS(tradebot,allbalances) +{ + int32_t i,n; double value,pending; char *base; cJSON *item,*balances = cJSON_CreateObject(); + if ( myinfo->liquidity_currencies == 0 ) + myinfo->liquidity_currencies = cJSON_Parse("[\"KMD\", \"BTC\"]"); + if ( myinfo->liquidity_currencies != 0 && (n= cJSON_GetArraySize(myinfo->liquidity_currencies)) > 0 ) + { + for (i=0; iliquidity_currencies,i); + value = tradebot_balance(myinfo,base); + pending = tradebot_pending(myinfo,base); + item = cJSON_CreateObject(); + jaddnum(item,"value",value); + jaddnum(item,"pending",pending); + jadd(balances,base,item); + } + } + return(jprint(balances,1)); +} + +ZERO_ARGS(tradebot,anchor) +{ + FILE *fp; char *anchorstr,fname[512]; cJSON *anchor; int32_t retval = -1; + if ( (anchorstr= tradebot_allbalances(myinfo,0,0,0)) != 0 ) + { + if ( (anchor= cJSON_Parse(anchorstr)) != 0 ) + { + if ( jobj(anchor,"error") == 0 ) + { + sprintf(fname,"%s/anchor",GLOBAL_DBDIR), OS_compatible_path(fname); + if ( (fp= fopen(fname,"wb")) != 0 ) + { + if ( fwrite(anchorstr,1,strlen(anchorstr)+1,fp) == strlen(anchorstr)+1 ) + retval = 0; + fclose(fp); + } + } + } + free(anchorstr); + } + if ( retval == 0 ) + return(clonestr("{\"result\":\"success\"}")); + else return(clonestr("{\"error\":\"couldnt make anchor file\"}")); +} + +ZERO_ARGS(tradebot,portfolio) +{ + char *currentstr,*anchorstr,fname[512]; long fsize; cJSON *current,*anchor=0,*portfolio=0; + if ( (currentstr= tradebot_allbalances(myinfo,0,0,0)) != 0 ) + { + if ( (current= cJSON_Parse(currentstr)) != 0 ) + { + sprintf(fname,"%s/anchor",GLOBAL_DBDIR), OS_compatible_path(fname); + if ( (anchorstr= OS_filestr(&fsize,fname)) != 0 ) + { + anchor = cJSON_Parse(anchorstr); + free(anchorstr); + } + if ( anchor == 0 ) + anchor = cJSON_Parse("{}"); + portfolio = tradebot_balancesdiff(myinfo,current,anchor); + free_json(current); + } + free(currentstr); + } + if ( portfolio == 0 ) + return(clonestr("{\"result\":\"success\"}")); + else return(jprint(portfolio,1)); +} + +ARRAY_OBJ_INT(tradebot,goals,currencies,vals,targettime) +{ + static bits256 zero; char *targetcoin; int32_t i,n; + if ( currencies != 0 && vals != 0 ) + { + // init things so automatically updates refli.bid and refli.ask + // volume range with margin + // currency percentage value in BTC? target distribution, max percentage, min percentage` + // min price to sell, max price to buy, max volume + n = cJSON_GetArraySize(currencies); + for (i=0; imyaddr.persistent); + if ( (msgid= juint(vals,"msgid")) == 0 ) + { + msgid = (uint32_t)time(NULL); + jdelete(vals,"msgid"); + jaddnum(vals,"msgid",msgid); + } + if ( myinfo->NOTARY.RELAYID >= 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 ) + { + channel = juint(vals,"channel"); + width = juint(vals,"width"); + retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width); + //printf("getmessage.(%s)\n",retstr); + return(retstr); + } + //printf("getmessage not relay.%d dexsock.%d subsock.%d\n",myinfo->NOTARY.RELAYID,myinfo->dexsock,myinfo->subsock); + return(basilisk_standardservice("MSG",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,1)); +} + +HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) +{ + int32_t keylen,datalen,allocsize = 65536; uint8_t key[BASILISK_KEYSIZE],*space,*space2,*data,*ptr = 0; char *retstr=0; + space = calloc(1,allocsize); + space2 = calloc(1,allocsize); + data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,&space[BASILISK_KEYSIZE],allocsize-BASILISK_KEYSIZE,hexstr); + if ( myinfo->subsock >= 0 || myinfo->dexsock >= 0 || (myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0) ) + { + keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash")); + if ( data != 0 ) + { + retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); + } else printf("no get_dataptr\n"); + if ( retstr != 0 ) + free(retstr); + } //else printf("not notary.%d relayid.%d\n",myinfo->IAMNOTARY,myinfo->NOTARY.RELAYID); + if ( vals != 0 && juint(vals,"fanout") == 0 ) + jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); + if ( BASILISK_KEYSIZE+datalen < allocsize ) + { + memcpy(space2,key,BASILISK_KEYSIZE); + if ( data != 0 && datalen != 0 ) + memcpy(&space2[BASILISK_KEYSIZE],data,datalen); + dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE,1,""); + } else printf("sendmessage space too small error for %d\n",datalen); + free(space); + free(space2); + if ( ptr != 0 ) + free(ptr); + return(basilisk_standardservice("OUT",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,0)); +} + +HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) +{ + char *retstr=0,*symbol,*coinaddr,*infostr; cJSON *retjson,*sobj,*info,*addrs,*txoutjson,*txjson,*array; uint32_t basilisktag,blocktime; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height,n,m; + if ( vals == 0 ) + return(clonestr("{\"error\":\"null valsobj\"}")); + //if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 ) + // return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}")); + //if ( coin == 0 ) + { + if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 ) + coin = iguana_coinfind(symbol); + } + if ( jobj(vals,"fanout") == 0 ) + jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + txid = jbits256(vals,"txid"); + vout = jint(vals,"vout"); + if ( coin != 0 ) + { + if ( coin->FULLNODE < 0 ) + { + if ( (txoutjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 ) + { + if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= SATOSHIDEN*jdouble(txoutjson,"value")) != 0 ) + { + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"address",coinaddr); + jadd64bits(retjson,"satoshis",value); + jaddnum(retjson,"value",dstr(value)); + jaddnum(retjson,"amount",dstr(value)); + height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,0,coin); + jaddnum(retjson,"height",height); + jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations")); + jaddbits256(retjson,"txid",txid); + jaddnum(retjson,"vout",vout); + jaddstr(retjson,"coin",coin->symbol); + } + else + { + free_json(txoutjson); + return(clonestr("{\"error\":\"return from gettxout missing fields\"}")); + } + free_json(txoutjson); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"null return from gettxout\"}")); + } + if ( (basilisktag= juint(vals,"basilisktag")) == 0 ) + basilisktag = rand(); + if ( (timeoutmillis= juint(vals,"timeout")) <= 0 ) + timeoutmillis = BASILISK_TIMEOUT; + if ( coin->FULLNODE > 0 && (ptr= basilisk_bitcoinvalue(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 ) + { + retstr = ptr->retstr, ptr->retstr = 0; + ptr->finished = OS_milliseconds() + 10000; + return(retstr); + } + } + if ( myinfo->reqsock >= 0 ) + { + if ( (retstr= _dex_getrawtransaction(myinfo,symbol,txid)) != 0 ) + { + if ( (txoutjson= cJSON_Parse(retstr)) != 0 ) + { + //printf("TX.(%s)\n",jprint(txoutjson,0)); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations")); + if ( (array= jarray(&n,txoutjson,"vout")) != 0 && vout < n && (txjson= jitem(array,vout)) != 0 ) + { + //printf("txjson.(%s)\n",jprint(txjson,0)); + if ( (value= jdouble(txjson,"value") * SATOSHIDEN) != 0 ) + { + if ( (sobj= jobj(txjson,"scriptPubKey")) != 0 && (addrs= jarray(&m,sobj,"addresses")) != 0 && (coinaddr= jstri(addrs,0)) != 0 ) + jaddstr(retjson,"address",coinaddr); + jadd64bits(retjson,"satoshis",value); + jaddnum(retjson,"value",dstr(value)); + if ( (infostr= _dex_getinfo(myinfo,symbol)) != 0 ) + { + if ( (info= cJSON_Parse(infostr)) != 0 ) + { + if ( (height= jint(info,"blocks")) > 0 ) + { + height -= jint(txoutjson,"confirmations"); + jaddnum(retjson,"height",height); + } + free_json(info); + } + free(infostr); + } + jaddbits256(retjson,"txid",txid); + jaddnum(retjson,"vout",vout); + jaddstr(retjson,"coin",symbol); + free(retstr); + free_json(txoutjson); + return(jprint(retjson,1)); + } + } + free_json(txoutjson); + return(jprint(retjson,1)); + } + return(retstr); + } + } + return(basilisk_standardservice("VAL",myinfo,0,hash,vals,hexstr,1)); +} + +HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr) +{ + char *retstr=0,*symbol; uint32_t basilisktag; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray; + if ( vals == 0 ) + return(clonestr("{\"error\":\"null valsobj\"}")); + //if ( coin == 0 ) + { + if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 ) + coin = iguana_coinfind(symbol); + } + if ( jobj(vals,"numrequired") == 0 ) + jaddnum(vals,"numrequired",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + if ( jobj(vals,"fanout") == 0 ) + jaddnum(vals,"fanout",MAX(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + if ( coin != 0 ) + { + //if ( juint(vals,"burn") == 0 ) + // jaddnum(vals,"burn",0.0001); + if ( (basilisktag= juint(vals,"basilisktag")) == 0 ) + basilisktag = rand(); + if ( (timeoutmillis= juint(vals,"timeout")) <= 0 ) + timeoutmillis = BASILISK_TIMEOUT; + if ( (retstr= basilisk_bitcoinrawtx(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals,0)) != 0 ) + { + printf("rawtx.(%s)\n",retstr); + if ( (amount= j64bits(vals,"satoshis")) == 0 ) + amount = jdouble(vals,"value") * SATOSHIDEN; + if ( (txfee= j64bits(vals,"txfee")) == 0 ) + txfee = coin->chain->txfee; + if ( txfee == 0 ) + txfee = 10000; + retval = -1; + if ( (retarray= cJSON_Parse(retstr)) != 0 ) + { + if ( is_cJSON_Array(retarray) != 0 ) + { + for (i=0; iFULLNODE >= 0 ) + return(clonestr("{\"error\":\"no passphrase or no native komodod\"}")); + else + { + safecopy(myinfo->jumblr_passphrase,passphrase,sizeof(myinfo->jumblr_passphrase)); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr); + myinfo->jumblr_depositkey = curve25519(privkey,curve25519_basepoint9()); + bitcoin_priv2wif(wifstr,privkey,coin->chain->wiftype); + if ( coin->FULLNODE < 0 ) + jumblr_importprivkey(myinfo,coin,wifstr); + jaddstr(retjson,"KMDdeposit",KMDaddr); + jaddstr(retjson,"BTCdeposit",BTCaddr); + if ( (coinbtc= iguana_coinfind("BTC")) != 0 ) + { + bitcoin_priv2wif(wifstr,privkey,coinbtc->chain->wiftype); + if ( coinbtc->FULLNODE < 0 ) + jumblr_importprivkey(myinfo,coinbtc,wifstr); + jaddnum(retjson,"BTCdeposits",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr))); + } + privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,""); + smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr); + 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))); + return(jprint(retjson,1)); + } +} + +ZERO_ARGS(jumblr,status) +{ + cJSON *retjson; char KMDaddr[64],BTCaddr[64]; struct jumblr_item *ptr,*tmp; struct iguana_info *coinbtc; int64_t received,deposited,jumblred,step_t2z,step_z2z,step_z2t,finished,pending,maxval,minval; + if ( strcmp(coin->symbol,"KMD") == 0 && coin->FULLNODE < 0 && myinfo->jumblr_passphrase[0] != 0 ) + { + jumblr_opidsupdate(myinfo,coin); + retjson = cJSON_CreateObject(); + step_t2z = step_z2z = step_z2t = deposited = finished = pending = 0; + jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + jaddstr(retjson,"KMDdeposit",KMDaddr); + jaddstr(retjson,"BTCdeposit",BTCaddr); + if ( (coinbtc= iguana_coinfind("BTC")) != 0 ) + jaddnum(retjson,"BTCdeposits",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr))); + received = jumblr_receivedby(myinfo,coin,KMDaddr); + deposited = jumblr_balance(myinfo,coin,KMDaddr); + jumblr_privkey(myinfo,BTCaddr,KMDaddr,""); + jaddstr(retjson,"KMDjumblr",KMDaddr); + jaddstr(retjson,"BTCjumblr",BTCaddr); + if ( coinbtc != 0 ) + jaddnum(retjson,"BTCjumbled",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr))); + finished = jumblr_receivedby(myinfo,coin,KMDaddr); + jumblred = jumblr_balance(myinfo,coin,KMDaddr); + HASH_ITER(hh,myinfo->jumblrs,ptr,tmp) + { + if ( strlen(ptr->src) >= 40 ) + { + if ( strlen(ptr->dest) >= 40 ) + step_z2z += ptr->amount; + else step_z2t += ptr->amount; + } else step_t2z += ptr->amount; + } + jaddstr(retjson,"result","success"); + jaddnum(retjson,"deposits",dstr(deposited)); + jaddnum(retjson,"t_to_z",dstr(step_t2z)); + jaddnum(retjson,"z_to_z",dstr(step_z2z)); + jaddnum(retjson,"z_to_t",dstr(step_z2t)); + maxval = MAX(step_t2z,MAX(step_z2z,step_z2t)); + minval = MIN(step_t2z,MIN(step_z2z,step_z2t)); + if ( maxval > minval ) + { + pending = (maxval - minval); + if ( pending < finished*.1 ) + pending = 0; + } + jaddnum(retjson,"pending",dstr(pending)); + jaddnum(retjson,"jumbled",dstr(jumblred)); + jaddnum(retjson,"received",dstr(received)); + jaddnum(retjson,"finished",dstr(finished)); + return(jprint(retjson,1)); + } + else + { + printf("(%s) (%s) %d\n",coin->symbol,myinfo->jumblr_passphrase,coin->FULLNODE); + return(clonestr("{\"error\":\"jumblr status no passphrase or no native komodod\"}")); + } +} HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr) { @@ -1084,9 +1516,16 @@ int32_t utxocmp(cJSON *utxo,cJSON *utxo2) else return(-1); } +ZERO_ARGS(basilisk,cancelrefresh) +{ + myinfo->cancelrefresh = 1; + return(clonestr("{\"result\":\"refresh cancel started\"}")); +} + TWO_STRINGS(basilisk,refresh,symbol,address) { cJSON *array=0,*array2=0,*array3,*item,*item2; char *retstr; int32_t i,j,n,m,vout; bits256 txid; + myinfo->cancelrefresh = 0; if ( symbol != 0 && iguana_isnotarychain(symbol) >= 0 && address != 0 && address[0] != 0 ) { if ( (retstr= _dex_listunspent(myinfo,symbol,address)) != 0 ) @@ -1109,6 +1548,8 @@ TWO_STRINGS(basilisk,refresh,symbol,address) //printf("MERGE %s and %s\n",jprint(array,0),jprint(array2,0)); for (j=0; jcancelrefresh != 0 ) + break; item2 = jitem(array2,j); for (i=0; icancelrefresh != 0 ) + break; item = jitem(array,i); txid = jbits256(item,"txid"); vout = jint(item,"vout"); @@ -1150,9 +1593,11 @@ TWO_STRINGS(basilisk,refresh,symbol,address) } } free_json(array); + myinfo->cancelrefresh = 0; return(jprint(array3,1)); } else return(clonestr("[]")); } + myinfo->cancelrefresh = 0; return(clonestr("{\"error\":\"invalid coin or address specified\"}")); } @@ -1166,8 +1611,7 @@ STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore) changeaddr = jstr(vals,"changeaddr"); if ( destaddr != 0 && changeaddr != 0 && symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 ) { - if ( (txfee= jdouble(vals,"txfee") * SATOSHIDEN) == 0 ) - txfee = coin->txfee; + txfee = jdouble(vals,"txfee") * SATOSHIDEN; return(iguana_utxorawtx(myinfo,coin,timelock,destaddr,changeaddr,satoshis,txfee,&completed,sendflag,utxos)); } return(clonestr("{\"error\":\"invalid coin or address specified\"}")); @@ -1175,5 +1619,249 @@ STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore) //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) +{ + double retvals[4],aveprice; cJSON *retjson = cJSON_CreateObject(); + aveprice = instantdex_avehbla(myinfo,retvals,base,rel,basevolume); + jaddstr(retjson,"result","success"); + jaddnum(retjson,"aveprice",aveprice); + jaddnum(retjson,"avebid",retvals[0]); + jaddnum(retjson,"bidvol",retvals[1]); + jaddnum(retjson,"aveask",retvals[2]); + jaddnum(retjson,"askvol",retvals[3]); + return(jprint(retjson,1)); +} + +ZERO_ARGS(InstantDEX,allcoins) +{ + struct iguana_info *tmp; cJSON *native,*notarychains,*basilisk,*virtual,*full,*retjson = cJSON_CreateObject(); + full = cJSON_CreateArray(); + native = cJSON_CreateArray(); + basilisk = cJSON_CreateArray(); + virtual = cJSON_CreateArray(); + notarychains = cJSON_CreateArray(); + HASH_ITER(hh,myinfo->allcoins,coin,tmp) + { + if ( coin->FULLNODE < 0 ) + jaddistr(native,coin->symbol); + //else if ( coin->virtualchain != 0 ) + // jaddistr(virtual,coin->symbol); + else if ( coin->FULLNODE > 0 )//|| coin->VALIDATENODE > 0 ) + jaddistr(full,coin->symbol); + //else if ( coin->notarychain >= 0 ) + // jaddistr(notarychains,coin->symbol); + else jaddistr(basilisk,coin->symbol); + } + jadd(retjson,"native",native); + jadd(retjson,"basilisk",basilisk); + jadd(retjson,"full",full); + //jadd(retjson,"virtual",virtual); + //jadd(retjson,"notarychains",notarychains); + return(jprint(retjson,1)); +} + +STRING_ARG(InstantDEX,available,source) +{ + 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 ( myinfo->expiration != 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)); + if ( (n= cJSON_GetArraySize(unspents)) > 0 ) + { + for (i=0; i %.8f\n",jprint(item,0),dstr(total)); + } + } + free_json(unspents); + } + retjson = cJSON_CreateObject(); + jaddnum(retjson,"result",dstr(total)); + printf(" n.%d total %.8f (%s)\n",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\"}")); + } + printf("InstantDEX_available: %s is not active\n",source!=0?source:""); + return(clonestr("{\"error\":\"specified coin is not active\"}")); +} + +HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) +{ + uint8_t serialized[512]; bits256 privkey; char buf[512],BTCaddr[64],KMDaddr[64]; struct basilisk_request R; int32_t jumblr,iambob,optionhours; cJSON *reqjson; uint32_t datalen=0,DEX_channel; struct iguana_info *bobcoin,*alicecoin; + myinfo->DEXactive = (uint32_t)time(NULL) + 3*BASILISK_TIMEOUT + 60; + jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN * SATOSHIDEN); + if ( jobj(vals,"desthash") == 0 ) + jaddbits256(vals,"desthash",hash); + jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN); + jadd64bits(vals,"destsatoshis",jdouble(vals,"destamount") * SATOSHIDEN); + jaddnum(vals,"timestamp",time(NULL)); + if ( (jumblr= jint(vals,"usejumblr")) != 0 ) + privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,jumblr == 1 ? JUMBLR_DEPOSITPREFIX : ""); + else privkey = myinfo->persistent_priv; + hash = curve25519(privkey,curve25519_basepoint9()); + if ( jobj(vals,"srchash") == 0 ) + jaddbits256(vals,"srchash",hash); + printf("service.(%s)\n",jprint(vals,0)); + memset(&R,0,sizeof(R)); + if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 ) + { + iambob = bitcoin_coinptrs(hash,&bobcoin,&alicecoin,R.src,R.dest,privkey,GENESIS_PUBKEY); + if ( (optionhours= jint(vals,"optionhours")) != 0 ) + { + printf("iambob.%d optionhours.%d R.requestid.%u vs calc %u, q.%u\n",iambob,R.optionhours,R.requestid,basilisk_requestid(&R),R.quoteid); + if ( iambob != 0 && optionhours > 0 ) + { + sprintf(buf,"{\"error\":\"illegal call option request hours.%d when iambob.%d\"}",optionhours,iambob); + printf("ERROR.(%s)\n",buf); + return(clonestr(buf)); + } + else if ( iambob == 0 && optionhours < 0 ) + { + sprintf(buf,"{\"error\":\"illegal put option request hours.%d when iambob.%d\"}",optionhours,iambob); + printf("ERROR.(%s)\n",buf); + return(clonestr(buf)); + } + } + //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 0 ) + { + 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,hash,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 ) + { + //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\"}")); + } + return(clonestr("{\"error\":\"DEX message not sent\"}")); +} + +INT_ARG(InstantDEX,automatched,requestid) +{ + // return quoteid + myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; + return(clonestr("{\"result\":\"automatched not yet\"}")); +} + +int32_t InstantDEX_incoming_func(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) +{ + //int32_t i; + //for (i=0; iDEXpoll) + 2*drift; + if ( width < (drift+1) ) + width = 2*drift+1; + else if ( width > 64 ) + width = 64; + myinfo->DEXpoll = now; + 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,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 ) + { + jaddstr(retjson,"result","success"); + } else jaddstr(retjson,"error","cant process InstantDEX retarray"); + jadd(retjson,"responses",retarray); + } + else + { + jaddstr(retjson,"error","cant do InstantDEX channelget"); + printf("error channelget\n"); + } + return(jprint(retjson,1)); +} + +/*TWO_INTS(InstantDEX,swapstatus,requestid,quoteid) + { + cJSON *vals; char *retstr; + myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; + //if ( myinfo->IAMLP != 0 ) + // return(basilisk_respond_swapstatus(myinfo,myinfo->myaddr.persistent,requestid,quoteid)); + //else + { + vals = cJSON_CreateObject(); + jaddnum(vals,"requestid",(uint32_t)requestid); + jaddnum(vals,"quoteid",(uint32_t)quoteid); + jaddbits256(vals,"hash",myinfo->myaddr.persistent); + retstr = basilisk_standardservice("SWP",myinfo,0,myinfo->myaddr.persistent,vals,"",1); + free_json(vals); + return(retstr); + } + }*/ + +TWO_INTS(InstantDEX,accept,requestid,quoteid) +{ + cJSON *vals; char *retstr; + myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; + if ( myinfo->IAMLP != 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 ) + return(basilisk_respond_accept(myinfo,myinfo->persistent_priv,requestid,quoteid,&myinfo->DEXaccept)); + else + { + vals = cJSON_CreateObject(); + jaddnum(vals,"quoteid",(uint32_t)quoteid); + jaddnum(vals,"requestid",(uint32_t)requestid); + retstr = basilisk_standardservice("ACC",myinfo,0,myinfo->myaddr.persistent,vals,"",1); + free_json(vals); + return(retstr); + } +} + +ZERO_ARGS(InstantDEX,init) +{ + basilisk_swaps_init(myinfo); + return(clonestr("{\"result\":\"success\"}")); +} + +ZERO_ARGS(InstantDEX,getswaplist) +{ + return(basilisk_swaplist(myinfo)); +} + + #include "../includes/iguana_apiundefs.h" diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 45bbdd6b2..b15b9032f 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -16,7 +16,7 @@ #ifndef H_BASILISK_H #define H_BASILISK_H -//#define BASILISK_DISABLESENDTX +#define BASILISK_DISABLESENDTX #define BASILISK_DISABLEWAITTX #include "../iguana/iguana777.h" @@ -37,13 +37,16 @@ #define INSTANTDEX_INSURANCEDIV 777 #define INSTANTDEX_PUBKEY "03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc06" #define INSTANTDEX_RMD160 "ca1e04745e8ca0c60d8c5881531d51bec470743f" +#define JUMBLR_RMD160 "5177f8b427e5f47342a4b8ab5dac770815d4389e" #define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146" #define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" #define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" +struct basilisk_swap; + struct basilisk_rawtxinfo { - char destaddr[64]; + char destaddr[64],coinstr[16]; bits256 txid,signedtxid,actualtxid; uint64_t amount,change,inputsum; int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys; @@ -57,8 +60,9 @@ struct basilisk_rawtx struct iguana_msgtx msgtx; struct basilisk_rawtxinfo I; struct iguana_info *coin; + char vinstr[8192]; cJSON *vins; - uint8_t *txbytes,spendscript[512],redeemscript[1024],extraspace[1024]; + uint8_t txbytes[16384],spendscript[512],redeemscript[1024],extraspace[4096]; }; struct basilisk_swapinfo @@ -67,27 +71,16 @@ struct basilisk_swapinfo char bobstr[64],alicestr[64]; bits256 myhash,otherhash,orderhash; uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration; - int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent; + int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad; uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance; bits256 myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn; uint32_t crcs_mypub[2],crcs_mychoosei[2],crcs_myprivs[2],crcs_mypriv[2]; - int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate; + int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate,pad2; uint8_t secretAm[20],secretBn[20]; uint8_t secretAm256[32],secretBn256[32]; }; -struct basilisk_swap -{ - struct supernet_info *myinfo; struct iguana_info *bobcoin,*alicecoin; - void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob); - struct basilisk_swapinfo I; - struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim; - bits256 privkeys[INSTANTDEX_DECKSIZE]; - uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; - uint8_t verifybuf[65536]; -}; - struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; }; struct basilisk_item @@ -135,7 +128,7 @@ int32_t basilisk_update(char *symbol,uint32_t reftimestamp); void basilisk_seqresult(struct supernet_info *myinfo,char *retstr); struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj); void basilisk_alicepayment(struct supernet_info *myinfo,struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn); -void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33); +void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33,int32_t jumblrflag); void basilisk_setmyid(struct supernet_info *myinfo); int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_request *rp); cJSON *basilisk_requestjson(struct basilisk_request *rp); diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 607d32099..5ec6fcaed 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -229,15 +229,17 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2 return(-1); } -char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration) +char *basilisk_start(struct supernet_info *myinfo,bits256 privkey,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration) { - cJSON *retjson; struct basilisk_request *rp=0; int32_t i; + cJSON *retjson; bits256 tmpprivkey; struct basilisk_request *rp=0; int32_t i,srcmatch,destmatch; 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) ) + srcmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->srchash) >= 0; + destmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->desthash) >= 0; + if ( srcmatch != 0 || destmatch != 0 ) { for (i=0; inumswaps; i++) if ( myinfo->swaps[i]->I.req.requestid == _rp->requestid ) @@ -251,12 +253,11 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u *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); myinfo->lastdexrequestid = rp->requestid; - if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 ) + if ( basilisk_thread_start(myinfo,privkey,rp,statebits,optionduration,0) != 0 ) { basilisk_request_enqueue(myinfo,rp); return(clonestr("{\"result\":\"started atomic swap thread\"}")); - } - else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); + } else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); } else { @@ -275,8 +276,8 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u void basilisk_requests_poll(struct supernet_info *myinfo) { static uint32_t lastpoll; - 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 ) + char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; uint32_t msgid,channel; int32_t datalen,i,n; struct basilisk_request issueR; bits256 privkey; double hwm = 0.; + if ( myinfo->IAMNOTARY != 0 || time(NULL) < lastpoll+20 || (myinfo->IAMLP == 0 && myinfo->DEXactive < time(NULL)) ) return; lastpoll = (uint32_t)time(NULL); memset(&issueR,0,sizeof(issueR)); @@ -299,42 +300,15 @@ void basilisk_requests_poll(struct supernet_info *myinfo) channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); if ( hwm > 0. ) { - //printf("hwm %f\n",hwm); - //for (i=0; iDEXaccept = issueR; - /*issueR.quoteid = basilisk_quoteid(&issueR); - datalen = basilisk_rwDEXquote(1,data,&issueR); - msgid = (uint32_t)time(NULL); - keylen = basilisk_messagekey(key,0,msgid,issueR.srchash,issueR.desthash); - if ( (retstr= basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,BASILISK_DEXDURATION)) != 0 ) - free(retstr);*/ - if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request + if ( smartaddress_pubkey(myinfo,&privkey,issueR.srchash) >= 0 ) { + printf("matched dex_smartpubkey\n"); 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 ) + if ( (retstr= basilisk_start(myinfo,privkey,&issueR,1,issueR.optionhours * 3600)) != 0 ) free(retstr); - 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); - 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 ) - { - printf("didnt get back what was sent\n"); - sleep(3); - basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60); - numiters++; - } - if ( crc != 0 ) - { - printf("crc.%08x -> basilisk_starta\n",crc); - if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 ) - free(retstr); - } // else printf("couldnt accept offer\n");*/ } else if ( issueR.requestid != myinfo->lastdexrequestid )//if ( issueR.quoteid == 0 ) { @@ -346,24 +320,8 @@ void basilisk_requests_poll(struct supernet_info *myinfo) 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 ) + if ( (retstr= basilisk_start(myinfo,myinfo->persistent_priv,&issueR,0,issueR.optionhours * 3600)) != 0 ) free(retstr); - /*crcs[0] = crcs[1] = 0; - numiters = 0; - 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 ) - { - //printf("didnt get back what was sent\n"); - sleep(3); - basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2); - numiters++; - } - if ( crc != 0 ) - { - printf("crc.%08x -> basilisk_start\n",crc); - if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 ) - free(retstr); - }*/ } //else printf("basilisk_requests_poll unexpected hwm issueR\n"); } } @@ -489,7 +447,7 @@ char *basilisk_respond_requests(struct supernet_info *myinfo,bits256 hash,uint32 return(jprint(retjson,1)); } -char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,uint32_t quoteid,struct basilisk_request *refrp) +char *basilisk_respond_accept(struct supernet_info *myinfo,bits256 privkey,uint32_t requestid,uint32_t quoteid,struct basilisk_request *refrp) { int32_t i,num=0; char *retstr=0; struct basilisk_request *requests,*rp; uint8_t space[4096]; portable_mutex_lock(&myinfo->DEX_reqmutex); @@ -501,7 +459,7 @@ char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,ui if ( rp->requestid == requestid && rp->quoteid == quoteid ) { printf("start from accept\n"); - retstr = basilisk_start(myinfo,rp,1,0); + retstr = basilisk_start(myinfo,privkey,rp,1,0); break; } } @@ -513,51 +471,6 @@ char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,ui retstr = clonestr("{\"error\":\"couldnt find to requestid to choose\"}"); return(retstr); } - -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume) -{ - double retvals[4],aveprice; cJSON *retjson = cJSON_CreateObject(); - aveprice = instantdex_avehbla(myinfo,retvals,base,rel,basevolume); - jaddstr(retjson,"result","success"); - jaddnum(retjson,"aveprice",aveprice); - jaddnum(retjson,"avebid",retvals[0]); - jaddnum(retjson,"bidvol",retvals[1]); - jaddnum(retjson,"aveask",retvals[2]); - jaddnum(retjson,"askvol",retvals[3]); - return(jprint(retjson,1)); -} - -ZERO_ARGS(InstantDEX,allcoins) -{ - struct iguana_info *tmp; cJSON *native,*notarychains,*basilisk,*virtual,*full,*retjson = cJSON_CreateObject(); - full = cJSON_CreateArray(); - native = cJSON_CreateArray(); - basilisk = cJSON_CreateArray(); - virtual = cJSON_CreateArray(); - notarychains = cJSON_CreateArray(); - HASH_ITER(hh,myinfo->allcoins,coin,tmp) - { - if ( coin->FULLNODE < 0 ) - jaddistr(native,coin->symbol); - //else if ( coin->virtualchain != 0 ) - // jaddistr(virtual,coin->symbol); - else if ( coin->FULLNODE > 0 )//|| coin->VALIDATENODE > 0 ) - jaddistr(full,coin->symbol); - //else if ( coin->notarychain >= 0 ) - // jaddistr(notarychains,coin->symbol); - else jaddistr(basilisk,coin->symbol); - } - jadd(retjson,"native",native); - jadd(retjson,"basilisk",basilisk); - jadd(retjson,"full",full); - //jadd(retjson,"virtual",virtual); - //jadd(retjson,"notarychains",notarychains); - return(jprint(retjson,1)); -} - cJSON *basilisk_unspents(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr) { cJSON *unspents=0,*array=0; char *retstr; @@ -570,7 +483,7 @@ cJSON *basilisk_unspents(struct supernet_info *myinfo,struct iguana_info *coin,c } else if ( coin->FULLNODE == 0 ) { - if ( (retstr= _dex_listunspent(myinfo,coin->symbol,coinaddr)) != 0 ) + if ( (retstr= dex_listunspent(myinfo,coin,0,0,coin->symbol,coinaddr)) != 0 ) { unspents = cJSON_Parse(retstr); free(retstr); @@ -600,191 +513,3 @@ char *basilisk_sendrawtransaction(struct supernet_info *myinfo,struct iguana_inf return(retstr); } -STRING_ARG(InstantDEX,available,source) -{ - 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 ( myinfo->expiration != 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)); - if ( (n= cJSON_GetArraySize(unspents)) > 0 ) - { - for (i=0; i %.8f\n",jprint(item,0),dstr(total)); - } - } - free_json(unspents); - } - retjson = cJSON_CreateObject(); - jaddnum(retjson,"result",dstr(total)); - printf(" n.%d total %.8f (%s)\n",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\"}")); - } - printf("InstantDEX_available: %s is not active\n",source!=0?source:""); - return(clonestr("{\"error\":\"specified coin is not active\"}")); -} - -HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) -{ - uint8_t serialized[512]; char buf[512]; struct basilisk_request R; int32_t iambob,optionhours; cJSON *reqjson; uint32_t datalen=0,DEX_channel; struct iguana_info *bobcoin,*alicecoin; - myinfo->DEXactive = (uint32_t)time(NULL) + 3*BASILISK_TIMEOUT + 60; - jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN); - if ( jobj(vals,"srchash") == 0 ) - jaddbits256(vals,"srchash",myinfo->myaddr.persistent); - if ( jobj(vals,"desthash") == 0 ) - jaddbits256(vals,"desthash",hash); - jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN); - jadd64bits(vals,"destsatoshis",jdouble(vals,"destamount") * SATOSHIDEN); - 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 ) - { - iambob = bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,R.src,R.dest,myinfo->myaddr.persistent,GENESIS_PUBKEY); - if ( (optionhours= jint(vals,"optionhours")) != 0 ) - { - printf("iambob.%d optionhours.%d R.requestid.%u vs calc %u, q.%u\n",iambob,R.optionhours,R.requestid,basilisk_requestid(&R),R.quoteid); - if ( iambob != 0 && optionhours > 0 ) - { - sprintf(buf,"{\"error\":\"illegal call option request hours.%d when iambob.%d\"}",optionhours,iambob); - printf("ERROR.(%s)\n",buf); - return(clonestr(buf)); - } - else if ( iambob == 0 && optionhours < 0 ) - { - sprintf(buf,"{\"error\":\"illegal put option request hours.%d when iambob.%d\"}",optionhours,iambob); - printf("ERROR.(%s)\n",buf); - return(clonestr(buf)); - } - } - //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 0 ) - { - 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 ) - { - //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\"}")); - } - return(clonestr("{\"error\":\"DEX message not sent\"}")); -} - -INT_ARG(InstantDEX,automatched,requestid) -{ - // return quoteid - myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; - return(clonestr("{\"result\":\"automatched not yet\"}")); -} - -int32_t InstantDEX_incoming_func(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) -{ - //int32_t i; - //for (i=0; iDEXpoll) + 2*drift; - if ( width < (drift+1) ) - width = 2*drift+1; - else if ( width > 64 ) - width = 64; - myinfo->DEXpoll = now; - 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,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 ) - { - jaddstr(retjson,"result","success"); - } else jaddstr(retjson,"error","cant process InstantDEX retarray"); - jadd(retjson,"responses",retarray); - } - else - { - jaddstr(retjson,"error","cant do InstantDEX channelget"); - printf("error channelget\n"); - } - return(jprint(retjson,1)); -} - -/*TWO_INTS(InstantDEX,swapstatus,requestid,quoteid) -{ - cJSON *vals; char *retstr; - myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; - //if ( myinfo->IAMLP != 0 ) - // return(basilisk_respond_swapstatus(myinfo,myinfo->myaddr.persistent,requestid,quoteid)); - //else - { - vals = cJSON_CreateObject(); - jaddnum(vals,"requestid",(uint32_t)requestid); - jaddnum(vals,"quoteid",(uint32_t)quoteid); - jaddbits256(vals,"hash",myinfo->myaddr.persistent); - retstr = basilisk_standardservice("SWP",myinfo,0,myinfo->myaddr.persistent,vals,"",1); - free_json(vals); - return(retstr); - } -}*/ - -TWO_INTS(InstantDEX,accept,requestid,quoteid) -{ - cJSON *vals; char *retstr; - myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; - if ( myinfo->IAMLP != 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 ) - return(basilisk_respond_accept(myinfo,requestid,quoteid,&myinfo->DEXaccept)); - else - { - vals = cJSON_CreateObject(); - jaddnum(vals,"quoteid",(uint32_t)quoteid); - jaddnum(vals,"requestid",(uint32_t)requestid); - retstr = basilisk_standardservice("ACC",myinfo,0,myinfo->myaddr.persistent,vals,"",1); - free_json(vals); - return(retstr); - } -} -#include "../includes/iguana_apiundefs.h" diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index e80e37f73..0fba54c91 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -98,12 +98,16 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ // char str[65],str2[65]; printf("MSGiterate (%s) -> (%s)\n",bits256_str(str,srchash),bits256_str(str2,desthash)); array = cJSON_CreateArray(); portable_mutex_lock(&myinfo->messagemutex); - //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); + //printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; ikey,msg->keylen)) != 0 ) + { + jaddbits256(msgjson,"src",srchash); + jaddbits256(msgjson,"dest",desthash); jaddi(array,msgjson); + } } } if ( now > msg->expiration+60 ) @@ -217,7 +237,11 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); QUEUEITEMS++; portable_mutex_unlock(&myinfo->messagemutex); -//printf("add message keylen.%d [%d]\n",msg->keylen,datalen); + { + bits256 srchash,desthash; uint32_t channel,msgid; + basilisk_messagekeyread(key,&channel,&msgid,&srchash,&desthash); + //printf("add message keylen.%d [%d] msgid.%x channel.%x\n",msg->keylen,datalen,msgid,channel); + } //if ( myinfo->NOTARY.RELAYID >= 0 ) // dpow_handler(myinfo,msg); if ( sendping != 0 ) @@ -259,66 +283,41 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha return(retstr); } -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) +cJSON *dpow_getmessage(struct supernet_info *myinfo,char *jsonstr) { - uint32_t msgid,width,channel; char *retstr; - if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"srchash")) == 0 ) - jaddbits256(vals,"srchash",hash); - if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"desthash")) == 0 ) - jaddbits256(vals,"desthash",myinfo->myaddr.persistent); - if ( (msgid= juint(vals,"msgid")) == 0 ) + cJSON *valsobj,*retjson = 0; char *retstr; + if ( (valsobj= cJSON_Parse(jsonstr)) != 0 ) { - msgid = (uint32_t)time(NULL); - jdelete(vals,"msgid"); - jaddnum(vals,"msgid",msgid); - } - if ( myinfo->NOTARY.RELAYID >= 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 ) - { - channel = juint(vals,"channel"); - width = juint(vals,"width"); - retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width); - //printf("getmessage.(%s)\n",retstr); - return(retstr); + retstr = basilisk_iterate_MSG(myinfo,juint(valsobj,"channel"),juint(valsobj,"msgid"),jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),juint(valsobj,"width")); + retjson = cJSON_Parse(retstr); + free(retstr); } - //printf("getmessage not relay.%d dexsock.%d subsock.%d\n",myinfo->NOTARY.RELAYID,myinfo->dexsock,myinfo->subsock); - return(basilisk_standardservice("MSG",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,1)); + return(retjson); } -HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) +cJSON *dpow_addmessage(struct supernet_info *myinfo,char *jsonstr) { - int32_t keylen,datalen,allocsize = 65536; uint8_t key[BASILISK_KEYSIZE],*space,*space2,*data,*ptr = 0; char *retstr=0; - space = calloc(1,allocsize); - space2 = calloc(1,allocsize); - data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,&space[BASILISK_KEYSIZE],allocsize-BASILISK_KEYSIZE,hexstr); - if ( myinfo->subsock >= 0 || myinfo->dexsock >= 0 || (myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0) ) + cJSON *vals,*retjson=0; char *retstr=0,*datastr; int32_t datalen,keylen; uint8_t *data=0,key[BASILISK_KEYSIZE]; + if ( (vals= cJSON_Parse(jsonstr)) != 0 ) { keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash")); - if ( data != 0 ) + if ( (datastr= jstr(vals,"data")) != 0 ) { - retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); - } else printf("no get_dataptr\n"); + datalen = (int32_t)strlen(datastr) >> 1; + data = malloc(datalen); + decode_hex(data,datalen,datastr); + if ( (retstr= basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration"))) != 0 ) + retjson = cJSON_Parse(retstr); + } if ( retstr != 0 ) free(retstr); - } //else printf("not notary.%d relayid.%d\n",myinfo->IAMNOTARY,myinfo->NOTARY.RELAYID); - if ( vals != 0 && juint(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); - if ( BASILISK_KEYSIZE+datalen < allocsize ) - { - memcpy(space2,key,BASILISK_KEYSIZE); - if ( data != 0 && datalen != 0 ) - memcpy(&space2[BASILISK_KEYSIZE],data,datalen); - dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE,1,""); - } else printf("sendmessage space too small error for %d\n",datalen); - free(space); - free(space2); - if ( ptr != 0 ) - free(ptr); - return(basilisk_standardservice("OUT",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,0)); + if ( data != 0 ) + free(data); + } + if ( retjson == 0 ) + retjson = cJSON_Parse("{\"error\":\"couldnt add message\"}"); + return(retjson); } -#include "../includes/iguana_apiundefs.h" 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) { @@ -384,9 +383,16 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 jaddnum(valsobj,"numrequired",1); jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"desthash",desthash); - if ( (retstr= basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0)) != 0 ) + if ( myinfo->IAMNOTARY != 0 ) + retstr = basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0); + else + { + //char str[65],str2[65]; + retstr = _dex_getmessage(myinfo,jprint(valsobj,0)); + //printf("channel.%u msgid.%u gotmessage.(%d) %s %s %s\n",channel,msgid,(int32_t)strlen(retstr),strlen(retstr) < 100 ? retstr : "(too long)",bits256_str(str,srchash),bits256_str(str2,desthash)); + } + if ( retstr != 0 ) { - //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 ) diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index c6bdadf34..8dec9ae69 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -473,6 +473,23 @@ void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,s return(ptr); } +int64_t iguana_getestimatedfee(struct supernet_info *myinfo,struct iguana_info *coin) +{ + char *retstr; cJSON *retjson; double x; int64_t txfeeperbyte = 200; + if ( (retstr= _dex_getinfo(myinfo,coin->symbol)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (x= jdouble(retjson,"estimatefee")) > SMALLVAL ) + txfeeperbyte = 1 + (x * SATOSHIDEN) / 1024; + printf("SET txfeeperbyte %lld (%s)\n",(long long)txfeeperbyte,retstr); + free(retjson); + } + free(retstr); + } + return(txfeeperbyte); +} + int32_t basilisk_voutvin_validate(struct iguana_info *coin,char *rawtx,uint64_t inputsum,uint64_t amount,uint64_t txfee) { //static int counter; @@ -543,13 +560,32 @@ int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info * return(retval); } +int64_t iguana_esttxfee(struct supernet_info *myinfo,struct iguana_info *coin,char *rawtx,char *signedtx,int32_t numvins) +{ + int64_t txfee = 0; + if ( coin->estimatedfee == 0 ) + coin->estimatedfee = iguana_getestimatedfee(myinfo,coin); + if ( signedtx != 0 ) + { + txfee = coin->estimatedfee * (strlen(signedtx)/2 + numvins); + free(signedtx); + } + else if ( rawtx != 0 ) + { + txfee = coin->estimatedfee * (strlen(rawtx)/2 + numvins * 110); + free(rawtx); + } + return(txfee); +} + char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *pubkey33,uint64_t satoshis,int32_t duplicates,int32_t *completedp,bits256 *signedtxidp,int32_t sendflag,cJSON *addresses) { - uint8_t script[35]; int32_t i,spendlen; cJSON *txobj=0,*vins=0; char *rawtx=0,*signedtx,changeaddr[64]; + uint8_t script[35]; int64_t txfee; int32_t i,spendlen; cJSON *txobj=0,*vins=0; char *rawtx=0,*signedtx=0,changeaddr[64]; *completedp = 0; if ( signedtxidp != 0 ) memset(signedtxidp,0,sizeof(*signedtxidp)); bitcoin_address(changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33); + txfee = (coin->txfee + duplicates*coin->txfee*2); if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,0,1,0)) != 0 ) { if ( duplicates <= 0 ) @@ -557,19 +593,28 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi spendlen = bitcoin_pubkeyspend(script,0,pubkey33); for (i=0; itxfee + duplicates*coin->txfee/5,addresses,0,0,0,0,"127.0.0.1",0,1); + rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,satoshis * duplicates,changeaddr,txfee,addresses,0,0,0,0,"127.0.0.1",0,1); + if ( cJSON_GetArraySize(vins) > duplicates/4 ) + { + free(rawtx); + rawtx = 0; + fprintf(stderr,"No point to recycle utxo when trying to create utxo duplicates, numvins.%d vs duplicates.%d\n",cJSON_GetArraySize(vins),duplicates); + free_json(vins); + return(rawtx); + } //printf("duplicatesTX.(%s)\n",rawtx); if ( signedtxidp != 0 ) { if ( (signedtx= iguana_signrawtx(myinfo,coin,0,signedtxidp,completedp,vins,rawtx,0,0)) != 0 ) { - free(rawtx); - if ( *completedp != 0 && sendflag != 0 ) + if ( *completedp != 0 ) { printf("splitfunds signedtx.(%s)\n",signedtx); - iguana_sendrawtransaction(myinfo,coin,signedtx); + if ( sendflag != 0 ) + iguana_sendrawtransaction(myinfo,coin,signedtx); + free(rawtx); + rawtx = signedtx, signedtx = 0; } - rawtx = signedtx; } else printf("error signing raw utxoduplicates tx\n"); } } @@ -615,7 +660,7 @@ int64_t iguana_verifytimelock(struct supernet_info *myinfo,struct iguana_info *c char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t timelock,char *destaddr,char *changeaddr,uint64_t satoshis,uint64_t txfee,int32_t *completedp,int32_t sendflag,cJSON *utxos) { - uint8_t script[35],p2shscript[128],rmd160[20],addrtype; bits256 txid; int32_t p2shlen,spendlen; cJSON *retjson,*txobj=0,*vins=0; char *rawtx=0,*signedtx=0; uint32_t timelocked = 0; + uint8_t script[35],p2shscript[128],rmd160[20],addrtype; bits256 txid; int32_t p2shlen,iter,spendlen; cJSON *retjson,*txcopy,*txobj=0,*vins=0; char *rawtx=0,*signedtx=0; uint32_t timelocked = 0; *completedp = 0; if ( iguana_addressvalidate(coin,&addrtype,destaddr) < 0 || iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 ) return(clonestr("{\"error\":\"invalid coin address\"}")); @@ -625,6 +670,8 @@ char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int bitcoin_addr2rmd160(&addrtype,rmd160,destaddr); if ( addrtype != coin->chain->pubtype ) return(clonestr("{\"error\":\"invalid dest address type\"}")); + if ( txfee == 0 && strcmp(coin->symbol,"BTC") != 0 && (txfee= coin->txfee) == 0 ) + txfee = coin->chain->txfee; retjson = cJSON_CreateObject(); if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,0,1,0)) != 0 ) { @@ -641,23 +688,42 @@ char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int printf("timelock.%d spend timelocked %u\n",timelock,timelocked); } bitcoin_txoutput(txobj,script,spendlen,satoshis); - if ( (rawtx= iguana_calcutxorawtx(myinfo,coin,&vins,txobj,satoshis,changeaddr,txfee,utxos,"",0,0)) != 0 ) + for (iter=0; iter<2; iter++) { - jaddstr(retjson,"rawtx",rawtx); - if ( (signedtx= iguana_signrawtx(myinfo,coin,0,&txid,completedp,vins,rawtx,0,0)) != 0 ) + txcopy = jduplicate(txobj); + if ( (rawtx= iguana_calcutxorawtx(myinfo,coin,&vins,txobj,satoshis,changeaddr,txfee,utxos,"",0,0)) != 0 ) { - if ( *completedp != 0 ) + if ( iter == 1 || txfee != 0 ) + jaddstr(retjson,"rawtx",rawtx); + if ( (signedtx= iguana_signrawtx(myinfo,coin,0,&txid,completedp,vins,rawtx,0,0)) != 0 ) { - jaddbits256(retjson,"txid",txid); - jaddstr(retjson,"signedtx",signedtx); - if ( sendflag != 0 ) + if ( (iter == 1 || txfee != 0) && *completedp != 0 ) { - //printf("send signedtx.(%s)\n",signedtx); - txid = iguana_sendrawtransaction(myinfo,coin,signedtx); - jaddbits256(retjson,"sent",txid); + jaddbits256(retjson,"txid",txid); + jaddstr(retjson,"signedtx",signedtx); + if ( sendflag != 0 ) + { + //printf("send signedtx.(%s)\n",signedtx); + txid = iguana_sendrawtransaction(myinfo,coin,signedtx); + jaddbits256(retjson,"sent",txid); + } } - } - } else printf("error signing raw utxoduplicates tx\n"); + } else printf("error signing raw utxorawtx tx\n"); + } else printf("null rawtx from calcutxorawtx\n"); + if ( txfee != 0 ) + { + free_json(txcopy); + break; + } + else // must be BTC and txfee == 0 + { + txfee = iguana_esttxfee(myinfo,coin,rawtx,signedtx,cJSON_GetArraySize(vins)); + free_json(vins); + rawtx = signedtx = 0; + vins = 0; + *completedp = 0; + txobj = txcopy; + } } } if ( timelock != 0 ) @@ -692,9 +758,14 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi if ( (amount= j64bits(valsobj,"satoshis")) == 0 ) amount = jdouble(valsobj,"value") * SATOSHIDEN; if ( (txfee= j64bits(valsobj,"txfee")) == 0 ) - txfee = coin->chain->txfee; - if ( txfee == 0 ) - txfee = 10000; + { + //if ( strcmp(coin->symbol,"BTC") != 0 ) + { + txfee = coin->chain->txfee; + if ( txfee < 50000 ) + txfee = 50000; + } + } spendscriptstr = jstr(valsobj,"spendscript"); minconf = juint(valsobj,"minconf"); locktime = jint(valsobj,"locktime"); @@ -703,7 +774,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi addresses = iguana_getaddressesbyaccount(myinfo,coin,"*"); jadd(valsobj,"addresses",addresses); } - //printf("use addresses.(%s)\n",jprint(addresses,0)); + printf("use addresses.(%s)\n",jprint(addresses,0)); //printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr); if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 ) return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}")); @@ -731,7 +802,15 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi oplen = 0; } 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); + rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,1); + if ( txfee == 0 ) + { + txfee = iguana_esttxfee(myinfo,coin,rawtx,0,vins != 0 ? cJSON_GetArraySize(vins): 0); + if ( vins != 0 ) + free_json(vins), vins = 0; + rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,1); + printf("new txfee %.8f (%s)\n",dstr(txfee),rawtx); + } //printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):""); } if ( rawtx != 0 ) @@ -977,175 +1056,6 @@ cJSON *BTC_makeclaimfunc(struct supernet_info *myinfo,struct exchange_info *exch } #endif - -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) -{ - char *retstr=0,*symbol,*coinaddr,*infostr; cJSON *retjson,*sobj,*info,*addrs,*txoutjson,*txjson,*array; uint32_t basilisktag,blocktime; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height,n,m; - if ( vals == 0 ) - return(clonestr("{\"error\":\"null valsobj\"}")); - //if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 ) - // return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}")); - //if ( coin == 0 ) - { - if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 ) - coin = iguana_coinfind(symbol); - } - if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); - txid = jbits256(vals,"txid"); - vout = jint(vals,"vout"); - if ( coin != 0 ) - { - if ( coin->FULLNODE < 0 ) - { - if ( (txoutjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 ) - { - if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= SATOSHIDEN*jdouble(txoutjson,"value")) != 0 ) - { - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result","success"); - jaddstr(retjson,"address",coinaddr); - jadd64bits(retjson,"satoshis",value); - jaddnum(retjson,"value",dstr(value)); - jaddnum(retjson,"amount",dstr(value)); - height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,0,coin); - jaddnum(retjson,"height",height); - jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations")); - jaddbits256(retjson,"txid",txid); - jaddnum(retjson,"vout",vout); - jaddstr(retjson,"coin",coin->symbol); - } - else - { - free_json(txoutjson); - return(clonestr("{\"error\":\"return from gettxout missing fields\"}")); - } - free_json(txoutjson); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"null return from gettxout\"}")); - } - if ( (basilisktag= juint(vals,"basilisktag")) == 0 ) - basilisktag = rand(); - if ( (timeoutmillis= juint(vals,"timeout")) <= 0 ) - timeoutmillis = BASILISK_TIMEOUT; - if ( coin->FULLNODE > 0 && (ptr= basilisk_bitcoinvalue(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 ) - { - retstr = ptr->retstr, ptr->retstr = 0; - ptr->finished = OS_milliseconds() + 10000; - return(retstr); - } - } - if ( myinfo->reqsock >= 0 ) - { - if ( (retstr= _dex_getrawtransaction(myinfo,symbol,txid)) != 0 ) - { - if ( (txoutjson= cJSON_Parse(retstr)) != 0 ) - { - //printf("TX.(%s)\n",jprint(txoutjson,0)); - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result","success"); - jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations")); - if ( (array= jarray(&n,txoutjson,"vout")) != 0 && vout < n && (txjson= jitem(array,vout)) != 0 ) - { - //printf("txjson.(%s)\n",jprint(txjson,0)); - if ( (value= jdouble(txjson,"value") * SATOSHIDEN) != 0 ) - { - if ( (sobj= jobj(txjson,"scriptPubKey")) != 0 && (addrs= jarray(&m,sobj,"addresses")) != 0 && (coinaddr= jstri(addrs,0)) != 0 ) - jaddstr(retjson,"address",coinaddr); - jadd64bits(retjson,"satoshis",value); - jaddnum(retjson,"value",dstr(value)); - if ( (infostr= _dex_getinfo(myinfo,symbol)) != 0 ) - { - if ( (info= cJSON_Parse(infostr)) != 0 ) - { - if ( (height= jint(info,"blocks")) > 0 ) - { - height -= jint(txoutjson,"confirmations"); - jaddnum(retjson,"height",height); - } - free_json(info); - } - free(infostr); - } - jaddbits256(retjson,"txid",txid); - jaddnum(retjson,"vout",vout); - jaddstr(retjson,"coin",symbol); - free(retstr); - free_json(txoutjson); - return(jprint(retjson,1)); - } - } - free_json(txoutjson); - return(jprint(retjson,1)); - } - return(retstr); - } - } - return(basilisk_standardservice("VAL",myinfo,0,hash,vals,hexstr,1)); -} - -HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr) -{ - char *retstr=0,*symbol; uint32_t basilisktag; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray; - if ( vals == 0 ) - return(clonestr("{\"error\":\"null valsobj\"}")); - //if ( coin == 0 ) - { - if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 ) - coin = iguana_coinfind(symbol); - } - if ( jobj(vals,"numrequired") == 0 ) - jaddnum(vals,"numrequired",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); - if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",MAX(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); - if ( coin != 0 ) - { - //if ( juint(vals,"burn") == 0 ) - // jaddnum(vals,"burn",0.0001); - if ( (basilisktag= juint(vals,"basilisktag")) == 0 ) - basilisktag = rand(); - if ( (timeoutmillis= juint(vals,"timeout")) <= 0 ) - timeoutmillis = BASILISK_TIMEOUT; - if ( (retstr= basilisk_bitcoinrawtx(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals,0)) != 0 ) - { - printf("rawtx.(%s)\n",retstr); - if ( (amount= j64bits(vals,"satoshis")) == 0 ) - amount = jdouble(vals,"value") * SATOSHIDEN; - if ( (txfee= j64bits(vals,"txfee")) == 0 ) - txfee = coin->chain->txfee; - if ( txfee == 0 ) - txfee = 10000; - retval = -1; - if ( (retarray= cJSON_Parse(retstr)) != 0 ) - { - if ( is_cJSON_Array(retarray) != 0 ) - { - for (i=0; iI.actualtxid); jaddnum(argjson,"vout",0); jaddstr(argjson,"coin",rawtx->coin->symbol); - if ( (valstr= basilisk_value(myinfo,rawtx->coin,0,0,myinfo->myaddr.persistent,argjson,0)) != 0 ) + if ( (valstr= basilisk_value(myinfo,rawtx->coin,0,0,swap->persistent_pubkey,argjson,0)) != 0 ) { //char str[65]; printf("%s %s valstr.(%s)\n",rawtx->name,bits256_str(str,rawtx->I.actualtxid),valstr); if ( (valuearray= cJSON_Parse(valstr)) != 0 ) @@ -310,15 +317,10 @@ bits256 basilisk_swap_broadcast(char *name,struct supernet_info *myinfo,struct b return(txid); } -int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr) +int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_t timestamp,uint32_t locktime,uint32_t sequenceid,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr) { - char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; uint32_t timestamp,sequenceid=0xffffffff; struct vin_info *V; uint32_t locktime=0; - V = calloc(16,sizeof(*V)); - timestamp = swap->I.started; - if ( dest == &swap->aliceclaim ) - locktime = swap->bobdeposit.I.locktime + 1, sequenceid = 0; - else if ( dest == &swap->bobreclaim ) - locktime = swap->bobpayment.I.locktime + 1, sequenceid = 0; + char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; struct vin_info *V; + V = calloc(256,sizeof(*V)); V[0].signers[0].privkey = privkey; bitcoin_pubkey33(myinfo->ctx,V[0].signers[0].pubkey,privkey); privkeys = cJSON_CreateArray(); @@ -350,6 +352,7 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b needsig = 0; #endif } + //printf("rawtx B\n"); if ( bits256_nonz(rawtx->I.actualtxid) != 0 ) jaddbits256(item,"txid",rawtx->I.actualtxid); else jaddbits256(item,"txid",rawtx->I.signedtxid); @@ -369,17 +372,19 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b jaddi(vins,item); jdelete(txobj,"vin"); jadd(txobj,"vin",vins); - //printf("basilisk_rawtx_sign locktime.%u/%u for %s spendscript.%s -> %s, suppress.%d\n",rawtx->locktime,dest->locktime,rawtx->name,hexstr,dest->name,dest->suppress_pubkeys); + //printf("basilisk_rawtx_sign locktime.%u/%u for %s spendscript.%s -> %s, suppress.%d\n",rawtx->I.locktime,dest->I.locktime,rawtx->name,hexstr,dest->name,dest->I.suppress_pubkeys); txobj = bitcoin_txoutput(txobj,dest->spendscript,dest->I.spendlen,dest->I.amount); if ( (rawtxbytes= bitcoin_json2hex(myinfo,rawtx->coin,&dest->I.txid,txobj,V)) != 0 ) { + //printf("rawtx.(%s) vins.%p\n",rawtxbytes,vins); if ( needsig == 0 ) signedtx = rawtxbytes; if ( signedtx != 0 || (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&dest->I.signedtxid,&dest->I.completed,vins,rawtxbytes,privkeys,V)) != 0 ) { dest->I.datalen = (int32_t)strlen(signedtx) >> 1; - dest->txbytes = calloc(1,dest->I.datalen); - decode_hex(dest->txbytes,dest->I.datalen,signedtx); + if ( dest->I.datalen <= sizeof(dest->txbytes) ) + decode_hex(dest->txbytes,dest->I.datalen,signedtx); + else printf("DEX tx is too big %d vs %d\n",dest->I.datalen,(int32_t)sizeof(dest->txbytes)); if ( signedtx != rawtxbytes ) free(signedtx); if ( dest->I.completed != 0 ) @@ -390,12 +395,188 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b } else printf("error making rawtx\n"); free_json(privkeys); free_json(txobj); + free(V); + return(retval); +} + +int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr) +{ + uint32_t timestamp,locktime=0,sequenceid = 0xffffffff; + timestamp = swap->I.started; + if ( dest == &swap->aliceclaim ) + locktime = swap->bobdeposit.I.locktime + 1, sequenceid = 0; + else if ( dest == &swap->bobreclaim ) + locktime = swap->bobpayment.I.locktime + 1, sequenceid = 0; + return(_basilisk_rawtx_sign(myinfo,height,timestamp,locktime,sequenceid,dest,rawtx,privkey,privkey2,userdata,userdatalen,ignore_cltverr)); +} + +cJSON *basilisk_privkeyarray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins) +{ + cJSON *privkeyarray,*item,*sobj; struct iguana_waddress *waddr; struct iguana_waccount *wacct; char coinaddr[64],account[128],wifstr[64],str[65],*hexstr; uint8_t script[1024]; int32_t i,n,len,vout; bits256 txid,privkey; + privkeyarray = cJSON_CreateArray(); + //printf("%s persistent.(%s) (%s) change.(%s) scriptstr.(%s)\n",coin->symbol,myinfo->myaddr.BTC,coinaddr,coin->changeaddr,scriptstr); + if ( (n= cJSON_GetArraySize(vins)) > 0 ) + { + for (i=0; i= 0 ) + { + iguana_txidcategory(myinfo,coin,account,coinaddr,txid,vout); + if ( coinaddr[0] == 0 && (sobj= jobj(item,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && is_hexstr(hexstr,0) > 0 ) + { + len = (int32_t)strlen(hexstr) >> 1; + if ( len < (sizeof(script) << 1) ) + { + decode_hex(script,len,hexstr); + if ( len == 25 && script[0] == 0x76 && script[1] == 0xa9 && script[2] == 0x14 ) + bitcoin_address(coinaddr,coin->chain->pubtype,script+3,20); + } + } + if ( coinaddr[0] != 0 ) + { + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) + { + bitcoin_priv2wif(wifstr,waddr->privkey,coin->chain->wiftype); + jaddistr(privkeyarray,waddr->wifstr); + } + else if ( smartaddress(myinfo,&privkey,coinaddr) >= 0 ) + { + bitcoin_priv2wif(wifstr,privkey,coin->chain->wiftype); + jaddistr(privkeyarray,wifstr); + } + else printf("cant find (%s) in wallet\n",coinaddr); + } else printf("cant coinaddr from (%s).v%d\n",bits256_str(str,txid),vout); + } else printf("invalid txid/vout %d of %d\n",i,n); + } + } + return(privkeyarray); +} + +int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct basilisk_rawtx *rawtx,cJSON *item,int32_t lockinputs,struct vin_info *V) +{ + char *signedtx,*txbytes; cJSON *vins,*privkeyarray; int32_t i,n,retval = -1; + if ( (txbytes= jstr(item,"rawtx")) != 0 && (vins= jobj(item,"vins")) != 0 ) + { + privkeyarray = basilisk_privkeyarray(myinfo,rawtx->coin,vins); + if ( (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&rawtx->I.signedtxid,&rawtx->I.completed,vins,txbytes,privkeyarray,V)) != 0 ) + { + if ( lockinputs != 0 ) + { + //printf("lockinputs\n"); + iguana_RTunspentslock(myinfo,rawtx->coin,vins); + if ( (n= cJSON_GetArraySize(vins)) != 0 ) + { + bits256 txid; int32_t vout; + for (i=0; iI.datalen = (int32_t)strlen(signedtx) >> 1; + //rawtx->txbytes = calloc(1,rawtx->I.datalen); + decode_hex(rawtx->txbytes,rawtx->I.datalen,signedtx); + //printf("%s SIGNEDTX.(%s)\n",rawtx->name,signedtx); + free(signedtx); + retval = 0; + } else printf("error signrawtx\n"); //do a very short timeout so it finishes via local poll + free_json(privkeyarray); + } + return(retval); +} + +int32_t _basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swapstarted,uint8_t *pubkey33,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,*jsonstr,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); + if ( rawtx->coin->changeaddr[0] == 0 ) + { + bitcoin_address(rawtx->coin->changeaddr,rawtx->coin->chain->pubtype,pubkey33,33); + printf("set change address.(%s)\n",rawtx->coin->changeaddr); + } + init_hexbytes_noT(scriptstr,script,scriptlen); + basilisktag = (uint32_t)rand(); + valsobj = cJSON_CreateObject(); + jaddstr(valsobj,"coin",rawtx->coin->symbol); + jaddstr(valsobj,"spendscript",scriptstr); + jaddstr(valsobj,"changeaddr",rawtx->coin->changeaddr); + jadd64bits(valsobj,"satoshis",rawtx->I.amount); + jadd64bits(valsobj,"txfee",txfee); + jaddnum(valsobj,"minconf",minconf); + jaddnum(valsobj,"locktime",locktime); + jaddnum(valsobj,"timeout",30000); + jaddnum(valsobj,"timestamp",swapstarted+delay); + addresses = cJSON_CreateArray(); + bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,pubkey33,33); + jaddistr(addresses,coinaddr); + jadd(valsobj,"addresses",addresses); + rawtx->I.locktime = locktime; + //printf("%s locktime.%u\n",rawtx->name,locktime); + V = calloc(256,sizeof(*V)); + if ( (retstr= basilisk_bitcoinrawtx(myinfo,rawtx->coin,"",basilisktag,jint(valsobj,"timeout"),valsobj,V)) != 0 ) + { + //printf("%s %s basilisk_bitcoinrawtx.(%s)\n",rawtx->name,str,retstr); + flag = 0; + if ( (retarray= cJSON_Parse(retstr)) != 0 ) + { + if ( is_cJSON_Array(retarray) != 0 ) + { + n = cJSON_GetArraySize(retarray); + for (i=0; icoin->longestchain,rawtx,jitem(retarray,i),lockinputs,V)) == 0 ) + { + rawtx->vins = jduplicate(jobj(jitem(retarray,i),"vins")); + jsonstr = jprint(rawtx->vins,0); + safecopy(rawtx->vinstr,jsonstr,sizeof(rawtx->vinstr)); + free(jsonstr); + break; + } + } + } + else + { + retval = basilisk_rawtx_return(myinfo,rawtx->coin->longestchain,rawtx,retarray,lockinputs,V); + rawtx->vins = jduplicate(jobj(retarray,"vins")); + jsonstr = jprint(rawtx->vins,0); + safecopy(rawtx->vinstr,jsonstr,sizeof(rawtx->vinstr)); + free(jsonstr); + } + free(retarray); + } else printf("error parsing.(%s)\n",retstr); + free(retstr); + } else printf("error creating %s feetx\n",iambob != 0 ? "BOB" : "ALICE"); + free_json(valsobj); + free(V); + return(retval); +} + +int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swapstarted,uint8_t *pubkey33,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 retval,len; uint64_t newtxfee; struct iguana_info *coin; + if ( (coin= rawtx->coin) == 0 || strcmp(coin->symbol,"BTC") != 0 ) + return(_basilisk_rawtx_gen(str,myinfo,swapstarted,pubkey33,iambob,lockinputs,rawtx,locktime,script,scriptlen,txfee,minconf,delay)); + retval = _basilisk_rawtx_gen(str,myinfo,swapstarted,pubkey33,iambob,0,rawtx,locktime,script,scriptlen,txfee,minconf,delay); + len = rawtx->I.datalen; + if ( coin->estimatedfee == 0 ) + coin->estimatedfee = iguana_getestimatedfee(myinfo,coin); + newtxfee = coin->estimatedfee * len; + if ( newtxfee > txfee ) + { + retval = _basilisk_rawtx_gen(str,myinfo,swapstarted,pubkey33,iambob,lockinputs,rawtx,locktime,script,scriptlen,newtxfee,minconf,delay); + printf("txfee %.8f -> newtxfee %.8f\n",dstr(txfee),dstr(newtxfee)); + } return(retval); } struct basilisk_rawtx *basilisk_swapdata_rawtx(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx) { - if ( rawtx->txbytes != 0 && rawtx->I.datalen <= maxlen ) + if ( rawtx->I.datalen != 0 && rawtx->I.datalen <= maxlen ) { memcpy(data,rawtx->txbytes,rawtx->I.datalen); return(rawtx); @@ -407,16 +588,17 @@ int32_t basilisk_verify_otherfee(struct supernet_info *myinfo,void *ptr,uint8_t { struct basilisk_swap *swap = ptr; // add verification and broadcast - swap->otherfee.txbytes = calloc(1,datalen); + //swap->otherfee.txbytes = calloc(1,datalen); memcpy(swap->otherfee.txbytes,data,datalen); + swap->otherfee.I.datalen = datalen; swap->otherfee.I.actualtxid = swap->otherfee.I.signedtxid = bits256_doublesha256(0,data,datalen); basilisk_txlog(myinfo,swap,&swap->otherfee,-1); return(0); } -int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys) +int32_t basilisk_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys) { - int32_t datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr; + int32_t datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr; bits256 txid; datalen = recvbuf[0]; datalen += (int32_t)recvbuf[1] << 8; if ( datalen > 65536 ) @@ -426,9 +608,9 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_ if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 ) memcpy(rawtx->redeemscript,&data[datalen],rawtx->I.redeemlen); //printf("recvlen.%d datalen.%d redeemlen.%d\n",recvlen,datalen,rawtx->redeemlen); - if ( rawtx->txbytes == 0 ) + if ( rawtx->I.datalen == 0 ) { - rawtx->txbytes = calloc(1,datalen); + //rawtx->txbytes = calloc(1,datalen); memcpy(rawtx->txbytes,data,datalen); rawtx->I.datalen = datalen; } @@ -443,6 +625,10 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_ printf("%s rawtx data compare error, len %d vs %d <<<<<<<<<< warning\n",rawtx->name,rawtx->I.datalen,datalen); return(-1); } + txid = bits256_doublesha256(0,data,datalen); + char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid)); + if ( bits256_cmp(txid,rawtx->I.actualtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 ) + rawtx->I.actualtxid = txid; if ( (txobj= bitcoin_data2json(rawtx->coin,height,&rawtx->I.signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys)) != 0 ) { rawtx->I.actualtxid = rawtx->I.signedtxid; @@ -457,7 +643,8 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_ { decode_hex(rawtx->spendscript,hexlen,hexstr); rawtx->I.spendlen = hexlen; - basilisk_txlog(myinfo,swap,rawtx,-1); // bobdeposit, bobpayment or alicepayment + if ( swap != 0 ) + basilisk_txlog(swap->myinfoptr,swap,rawtx,-1); // bobdeposit, bobpayment or alicepayment retval = 0; } } else printf("%s ERROR.(%s)\n",rawtx->name,jprint(txobj,0)); @@ -467,7 +654,7 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_ return(retval); } -int32_t basilisk_swapuserdata(struct basilisk_swap *swap,uint8_t *userdata,bits256 privkey,int32_t ifpath,bits256 signpriv,uint8_t *redeemscript,int32_t redeemlen) +int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,bits256 signpriv,uint8_t *redeemscript,int32_t redeemlen) { int32_t i,len = 0; #ifdef DISABLE_CHECKSIG @@ -495,10 +682,10 @@ int32_t basilisk_swapuserdata(struct basilisk_swap *swap,uint8_t *userdata,bits2 int32_t basilisk_verify_bobdeposit(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) { uint8_t userdata[512]; int32_t i,retval,len = 0; static bits256 zero; struct basilisk_swap *swap = ptr; - if ( basilisk_rawtx_spendscript(myinfo,swap,swap->bobcoin->blocks.hwmchain.height,&swap->bobdeposit,0,data,datalen,0) == 0 ) + if ( basilisk_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) { - len = basilisk_swapuserdata(swap,userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); - if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1)) == 0 ) + len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->longestchain,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1)) == 0 ) { for (i=0; ibobdeposit.I.datalen; i++) printf("%02x",swap->bobdeposit.txbytes[i]); @@ -517,8 +704,8 @@ int32_t basilisk_verify_bobdeposit(struct supernet_info *myinfo,void *ptr,uint8_ int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t delay) { uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65]; - len = basilisk_swapuserdata(swap,userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); - if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0)) == 0 ) + len = basilisk_swapuserdata(userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->longestchain,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0)) == 0 ) { for (i=0; ibobrefund.I.datalen; i++) printf("%02x",swap->bobrefund.txbytes[i]); @@ -540,8 +727,8 @@ int32_t basilisk_bobpayment_reclaim(struct supernet_info *myinfo,struct basilisk { uint8_t userdata[512]; int32_t i,retval,len = 0; static bits256 zero; printf("basilisk_bobpayment_reclaim\n"); - len = basilisk_swapuserdata(swap,userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); - if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1)) == 0 ) + len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->longestchain,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1)) == 0 ) { for (i=0; ibobreclaim.I.datalen; i++) printf("%02x",swap->bobreclaim.txbytes[i]); @@ -556,13 +743,13 @@ int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,void *ptr,uint8_t * { uint8_t userdata[512]; int32_t i,retval,len = 0; bits256 revAm; struct basilisk_swap *swap = ptr; memset(revAm.bytes,0,sizeof(revAm)); - if ( basilisk_rawtx_spendscript(myinfo,swap,swap->bobcoin->blocks.hwmchain.height,&swap->bobpayment,0,data,datalen,0) == 0 ) + if ( basilisk_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 ) { for (i=0; i<32; i++) revAm.bytes[i] = swap->I.privAm.bytes[31-i]; - len = basilisk_swapuserdata(swap,userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); - char str[65]; printf("bobpaid.(%s)\n",bits256_str(str,swap->I.privAm)); - if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1)) == 0 ) + len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + char str[65],str2[65]; printf("bobpaid privAm.(%s) myprivs[0].(%s)\n",bits256_str(str,swap->I.privAm),bits256_str(str2,swap->I.myprivs[0])); + if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->longestchain,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1)) == 0 ) { for (i=0; ibobpayment.I.datalen; i++) printf("%02x",swap->bobpayment.txbytes[i]); @@ -578,186 +765,150 @@ int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,void *ptr,uint8_t * return(-1); } +void basilisk_alicepayment(struct supernet_info *myinfo,struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn) +{ + alicepayment->I.spendlen = basilisk_alicescript(alicepayment->redeemscript,&alicepayment->I.redeemlen,alicepayment->spendscript,0,alicepayment->I.destaddr,coin->chain->p2shtype,pubAm,pubBn); + basilisk_rawtx_gen("alicepayment",myinfo,swap->I.started,swap->persistent_pubkey33,0,1,alicepayment,alicepayment->I.locktime,alicepayment->spendscript,alicepayment->I.spendlen,coin->chain->txfee,1,0); +} + int32_t basilisk_alicepayment_spend(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *dest) { int32_t i,retval; - //printf("alicepayment_spend\n"); + printf("alicepayment_spend\n"); swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,swap->alicecoin->chain->p2shtype,swap->I.pubAm,swap->I.pubBn); - if ( (retval= basilisk_rawtx_sign(myinfo,swap->alicecoin->blocks.hwmchain.height,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1)) == 0 ) + printf("alicepayment_spend len.%d\n",swap->alicepayment.I.spendlen); + if ( (retval= basilisk_rawtx_sign(myinfo,swap->alicecoin->longestchain,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1)) == 0 ) { for (i=0; iI.datalen; i++) printf("%02x",dest->txbytes[i]); printf(" <- msigspend\n\n"); - swap->I.bobspent = 1; + if ( dest == &swap->bobspend ) + swap->I.bobspent = 1; basilisk_txlog(myinfo,swap,dest,0); // bobspend or alicereclaim return(retval); } return(-1); } -int32_t basilisk_verify_alicepaid(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) +int32_t basilisk_bobpayment_spendclone(struct supernet_info *myinfo,struct iguana_info *bobcoin,struct basilisk_rawtx *dest,struct basilisk_rawtx *src,uint32_t swapstarted,uint8_t *changepubkey33,uint32_t quoteid,uint64_t amount,bits256 privAm,bits256 myprivs0,uint8_t *data,int32_t datalen,int32_t jumblrflag) { - struct basilisk_swap *swap = ptr; - if ( basilisk_rawtx_spendscript(myinfo,swap,swap->alicecoin->blocks.hwmchain.height,&swap->alicepayment,0,data,datalen,0) == 0 ) - return(0); - else return(-1); + bits256 revAm; uint8_t userdata[512]; int32_t i,len,numconfirms = 0,retval = -1; uint32_t sequenceid = 0xffffffff; + basilisk_rawtx_setparms("bobpayment",quoteid,src,bobcoin,numconfirms,0,amount,3,0,jumblrflag); + dest->I.suppress_pubkeys = 1; + basilisk_rawtx_gen("bobpayment",myinfo,swapstarted,changepubkey33,1,1,src,src->I.locktime,src->spendscript,src->I.spendlen,bobcoin->chain->txfee,1,0); + if ( basilisk_rawtx_spendscript(0,bobcoin->longestchain,src,0,data,datalen,0) == 0 ) + { + memset(revAm.bytes,0,sizeof(revAm)); + for (i=0; i<32; i++) + revAm.bytes[i] = privAm.bytes[31-i]; + len = basilisk_swapuserdata(userdata,revAm,0,myprivs0,src->redeemscript,src->I.redeemlen); + if ( (retval= _basilisk_rawtx_sign(myinfo,bobcoin->longestchain,swapstarted,src->I.locktime,sequenceid,dest,src,myprivs0,0,userdata,len,1)) == 0 ) + { + } + } + return(retval); } -int32_t basilisk_verify_pubpair(int32_t *wrongfirstbytep,struct basilisk_swap *swap,int32_t ind,uint8_t pub0,bits256 pubi,uint64_t txid) +int32_t basilisk_bobpayment_reclaimclone(struct supernet_info *myinfo,struct iguana_info *bobcoin,struct basilisk_rawtx *dest,struct basilisk_rawtx *src,uint32_t swapstarted,uint8_t *changepubkey33,uint32_t quoteid,uint64_t amount,bits256 myprivs1,uint8_t *data,int32_t datalen,int32_t jumblrflag) { - if ( pub0 != (swap->I.iambob ^ 1) + 0x02 ) - { - (*wrongfirstbytep)++; - printf("wrongfirstbyte[%d] %02x\n",ind,pub0); - return(-1); - } - else if ( swap->otherdeck[ind][1] != pubi.txid ) - { - printf("otherdeck[%d] priv ->pub mismatch %llx != %llx\n",ind,(long long)swap->otherdeck[ind][1],(long long)pubi.txid); - return(-1); - } - else if ( swap->otherdeck[ind][0] != txid ) - { - printf("otherdeck[%d] priv mismatch %llx != %llx\n",ind,(long long)swap->otherdeck[ind][0],(long long)txid); - return(-1); + bits256 zero; uint8_t userdata[512]; int32_t len,numconfirms = 0,retval = -1; uint32_t sequenceid = 0xffffffff; + basilisk_rawtx_setparms("bobpayment",quoteid,src,bobcoin,numconfirms,0,amount,3,0,jumblrflag); + dest->I.suppress_pubkeys = 1; + basilisk_rawtx_gen("bobpayment",myinfo,swapstarted,changepubkey33,1,1,src,src->I.locktime,src->spendscript,src->I.spendlen,bobcoin->chain->txfee,1,0); + if ( basilisk_rawtx_spendscript(0,bobcoin->longestchain,src,0,data,datalen,0) == 0 ) + { + memset(zero.bytes,0,sizeof(zero)); + len = basilisk_swapuserdata(userdata,zero,1,myprivs1,src->redeemscript,src->I.redeemlen); + if ( (retval= _basilisk_rawtx_sign(myinfo,bobcoin->longestchain,swapstarted,src->I.locktime,sequenceid,dest,src,myprivs1,0,userdata,len,1)) == 0 ) + { + } } - return(0); + return(retval); } -cJSON *basilisk_privkeyarray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins) +int32_t basilisk_bobdeposit_refundclone(struct supernet_info *myinfo,struct iguana_info *bobcoin,struct basilisk_rawtx *dest,struct basilisk_rawtx *src,uint32_t swapstarted,uint8_t *changepubkey33,uint32_t quoteid,uint64_t amount,bits256 myprivs0,bits256 privBn,uint8_t *data,int32_t datalen,int32_t jumblrflag) { - cJSON *privkeyarray,*item,*sobj; struct iguana_waddress *waddr; struct iguana_waccount *wacct; char coinaddr[64],account[128],wifstr[64],str[65],*hexstr; uint8_t script[1024]; int32_t i,n,len,vout; bits256 txid; - privkeyarray = cJSON_CreateArray(); - //printf("%s persistent.(%s) (%s) change.(%s) scriptstr.(%s)\n",coin->symbol,myinfo->myaddr.BTC,coinaddr,coin->changeaddr,scriptstr); - if ( (n= cJSON_GetArraySize(vins)) > 0 ) - { - for (i=0; iI.suppress_pubkeys = 1; + basilisk_rawtx_gen("bobdeposit",myinfo,swapstarted,changepubkey33,1,1,src,src->I.locktime,src->spendscript,src->I.spendlen,bobcoin->chain->txfee,1,0); + if ( basilisk_rawtx_spendscript(0,bobcoin->longestchain,src,0,data,datalen,0) == 0 ) + { + len = basilisk_swapuserdata(userdata,privBn,0,myprivs0,src->redeemscript,src->I.redeemlen); + if ( (retval= _basilisk_rawtx_sign(myinfo,bobcoin->longestchain,swapstarted,src->I.locktime,sequenceid,dest,src,myprivs0,0,userdata,len,0)) == 0 ) { - item = jitem(vins,i); - txid = jbits256(item,"txid"); - vout = jint(item,"vout"); - if ( bits256_nonz(txid) != 0 && vout >= 0 ) - { - iguana_txidcategory(myinfo,coin,account,coinaddr,txid,vout); - if ( coinaddr[0] == 0 && (sobj= jobj(item,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && is_hexstr(hexstr,0) > 0 ) - { - len = (int32_t)strlen(hexstr) >> 1; - if ( len < (sizeof(script) << 1) ) - { - decode_hex(script,len,hexstr); - if ( len == 25 && script[0] == 0x76 && script[1] == 0xa9 && script[2] == 0x14 ) - bitcoin_address(coinaddr,coin->chain->pubtype,script+3,20); - } - } - if ( coinaddr[0] != 0 ) - { - if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) - { - bitcoin_priv2wif(wifstr,waddr->privkey,coin->chain->wiftype); - jaddistr(privkeyarray,waddr->wifstr); - } else printf("cant find (%s) in wallet\n",coinaddr); - } else printf("cant coinaddr from (%s).v%d\n",bits256_str(str,txid),vout); - } else printf("invalid txid/vout %d of %d\n",i,n); } } - return(privkeyarray); + return(retval); } -int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct basilisk_rawtx *rawtx,cJSON *item,int32_t lockinputs,struct vin_info *V) +int32_t basilisk_bobdeposit_claimclone(struct supernet_info *myinfo,struct iguana_info *bobcoin,struct basilisk_rawtx *dest,struct basilisk_rawtx *src,uint32_t swapstarted,uint8_t *changepubkey33,uint32_t quoteid,uint64_t amount,bits256 myprivs0,uint8_t *data,int32_t datalen,int32_t jumblrflag) { - char *signedtx,*txbytes; cJSON *vins,*privkeyarray; int32_t i,n,retval = -1; - if ( (txbytes= jstr(item,"rawtx")) != 0 && (vins= jobj(item,"vins")) != 0 ) - { - privkeyarray = basilisk_privkeyarray(myinfo,rawtx->coin,vins); - if ( (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&rawtx->I.signedtxid,&rawtx->I.completed,vins,txbytes,privkeyarray,V)) != 0 ) + bits256 zero; uint8_t userdata[512]; int32_t len,numconfirms = 0,retval = -1; uint32_t sequenceid = 0xffffffff; + basilisk_rawtx_setparms("bobdeposit",quoteid,src,bobcoin,numconfirms,0,amount,4,0,jumblrflag); + dest->I.suppress_pubkeys = 1; + basilisk_rawtx_gen("bobdeposit",myinfo,swapstarted,changepubkey33,1,1,src,src->I.locktime,src->spendscript,src->I.spendlen,bobcoin->chain->txfee,1,0); + if ( basilisk_rawtx_spendscript(0,bobcoin->longestchain,src,0,data,datalen,0) == 0 ) + { + memset(zero.bytes,0,sizeof(zero)); + len = basilisk_swapuserdata(userdata,zero,1,myprivs0,src->redeemscript,src->I.redeemlen); + if ( (retval= _basilisk_rawtx_sign(myinfo,bobcoin->longestchain,swapstarted,src->I.locktime,sequenceid,dest,src,myprivs0,0,userdata,len,1)) == 0 ) { - if ( lockinputs != 0 ) - { - //printf("lockinputs\n"); - iguana_RTunspentslock(myinfo,rawtx->coin,vins); - if ( (n= cJSON_GetArraySize(vins)) != 0 ) - { - bits256 txid; int32_t vout; - for (i=0; iI.datalen = (int32_t)strlen(signedtx) >> 1; - rawtx->txbytes = calloc(1,rawtx->I.datalen); - decode_hex(rawtx->txbytes,rawtx->I.datalen,signedtx); - printf("%s SIGNEDTX.(%s)\n",rawtx->name,signedtx); - free(signedtx); - retval = 0; - } else printf("error signrawtx\n"); //do a very short timeout so it finishes via local poll - free_json(privkeyarray); + } } return(retval); } -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) +//basilisk_alicepayment_clone(myinfo,&dest,&src,swapstarted,changepubkey33,alicecoin,quoteid,amount,privAm,pubAm,privBn,pubBn); + +int32_t basilisk_alicepayment_spendclone(struct supernet_info *myinfo,struct iguana_info *alicecoin,struct basilisk_rawtx *dest,struct basilisk_rawtx *src,uint32_t swapstarted,uint8_t *changepubkey33,uint32_t quoteid,uint64_t amount,bits256 privAm,bits256 privBn,int32_t jumblrflag) { - 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); - if ( rawtx->coin->changeaddr[0] == 0 ) + uint8_t pubAm33[33],pubBn33[33]; bits256 pubAm,pubBn; int32_t retval,numconfirms = 0; uint32_t sequenceid = 0xffffffff; + bitcoin_pubkey33(myinfo->ctx,pubAm33,privAm); + memcpy(pubAm.bytes,pubAm33+1,32); + bitcoin_pubkey33(myinfo->ctx,pubBn33,privBn); + memcpy(pubBn.bytes,pubBn33+1,32); + memset(src,0,sizeof(*src)); + memset(dest,0,sizeof(*dest)); + basilisk_rawtx_setparms("alicepayment",quoteid,src,alicecoin,numconfirms,0,amount,2,0,jumblrflag); + src->I.spendlen = basilisk_alicescript(src->redeemscript,&src->I.redeemlen,src->spendscript,0,src->I.destaddr,alicecoin->chain->p2shtype,pubAm,pubBn); + basilisk_rawtx_gen("alicepayment",myinfo,swapstarted,changepubkey33,0,1,src,src->I.locktime,src->spendscript,src->I.spendlen,alicecoin->chain->txfee,1,0); + if ( (retval= _basilisk_rawtx_sign(myinfo,alicecoin->longestchain,swapstarted,src->I.locktime,sequenceid,dest,src,privAm,&privBn,0,0,1)) == 0 ) { - bitcoin_address(rawtx->coin->changeaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33); - printf("set change address.(%s)\n",rawtx->coin->changeaddr); + } - init_hexbytes_noT(scriptstr,script,scriptlen); - basilisktag = (uint32_t)rand(); - valsobj = cJSON_CreateObject(); - jaddstr(valsobj,"coin",rawtx->coin->symbol); - jaddstr(valsobj,"spendscript",scriptstr); - jaddstr(valsobj,"changeaddr",rawtx->coin->changeaddr); - jadd64bits(valsobj,"satoshis",rawtx->I.amount); - jadd64bits(valsobj,"txfee",txfee); - jaddnum(valsobj,"minconf",minconf); - jaddnum(valsobj,"locktime",locktime); - jaddnum(valsobj,"timeout",30000); - 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; - //printf("%s locktime.%u\n",rawtx->name,locktime); - V = calloc(256,sizeof(*V)); - if ( (retstr= basilisk_bitcoinrawtx(myinfo,rawtx->coin,"",basilisktag,jint(valsobj,"timeout"),valsobj,V)) != 0 ) - { - //printf("%s %s basilisk_bitcoinrawtx.(%s)\n",rawtx->name,str,retstr); - flag = 0; - if ( (retarray= cJSON_Parse(retstr)) != 0 ) - { - if ( is_cJSON_Array(retarray) != 0 ) - { - n = cJSON_GetArraySize(retarray); - for (i=0; icoin->blocks.hwmchain.height,rawtx,jitem(retarray,i),lockinputs,V)) == 0 ) - { - rawtx->vins = jobj(jitem(retarray,i),"vins"); - break; - } - } - } - else - { - retval = basilisk_rawtx_return(myinfo,rawtx->coin->blocks.hwmchain.height,rawtx,retarray,lockinputs,V); - rawtx->vins = jobj(retarray,"vins"); - } - free(retarray); - } else printf("error parsing.(%s)\n",retstr); - free(retstr); - } else printf("error creating %s feetx\n",iambob != 0 ? "BOB" : "ALICE"); - free_json(valsobj); - free(V); return(retval); } +int32_t basilisk_verify_alicepaid(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) +{ + struct basilisk_swap *swap = ptr; + if ( basilisk_rawtx_spendscript(swap,swap->alicecoin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 ) + return(0); + else return(-1); +} + +int32_t basilisk_verify_pubpair(int32_t *wrongfirstbytep,struct basilisk_swap *swap,int32_t ind,uint8_t pub0,bits256 pubi,uint64_t txid) +{ + if ( pub0 != (swap->I.iambob ^ 1) + 0x02 ) + { + (*wrongfirstbytep)++; + printf("wrongfirstbyte[%d] %02x\n",ind,pub0); + return(-1); + } + else if ( swap->otherdeck[ind][1] != pubi.txid ) + { + printf("otherdeck[%d] priv ->pub mismatch %llx != %llx\n",ind,(long long)swap->otherdeck[ind][1],(long long)pubi.txid); + return(-1); + } + else if ( swap->otherdeck[ind][0] != txid ) + { + printf("otherdeck[%d] priv mismatch %llx != %llx\n",ind,(long long)swap->otherdeck[ind][0],(long long)txid); + return(-1); + } + return(0); +} + int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t depositflag,int32_t genflag) { int32_t i,j; //char str[65]; @@ -769,17 +920,17 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa //for (i=0; ibobpayment.redeemlen; i++) // printf("%02x",swap->bobpayment.redeemscript[i]); //printf(" <- bobpayment.%d\n",i); - if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.txbytes == 0 ) + if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.I.datalen == 0 ) { 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); - if ( swap->bobpayment.txbytes == 0 || swap->bobpayment.I.spendlen == 0 ) + basilisk_rawtx_gen("payment",myinfo,swap->I.started,swap->persistent_pubkey33,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.I.spendlen == 0 || swap->bobpayment.I.datalen == 0 ) { printf("error bob generating %p payment.%d\n",swap->bobpayment.txbytes,swap->bobpayment.I.spendlen); - sleep(3); + sleep(DEX_SLEEP); } else { @@ -797,22 +948,21 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa } } } - return(0); } 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); - if ( genflag != 0 && (swap->bobdeposit.txbytes == 0 || swap->bobrefund.txbytes == 0) ) + if ( genflag != 0 && (swap->bobdeposit.I.datalen == 0 || swap->bobrefund.I.datalen == 0) ) { 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); - if ( swap->bobdeposit.txbytes == 0 || swap->bobdeposit.I.spendlen == 0 ) + basilisk_rawtx_gen("deposit",myinfo,swap->I.started,swap->persistent_pubkey33,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.I.datalen == 0 || swap->bobdeposit.I.spendlen == 0 ) { printf("error bob generating %p deposit.%d\n",swap->bobdeposit.txbytes,swap->bobdeposit.I.spendlen); - sleep(3); + sleep(DEX_SLEEP); } else { @@ -830,12 +980,11 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa } } } - return(0); //for (i=0; ibobdeposit.redeemlen; i++) // printf("%02x",swap->bobdeposit.redeemscript[i]); //printf(" <- bobdeposit.%d\n",i); } - return(-1); + return(0); } int32_t basilisk_verify_privi(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) @@ -879,28 +1028,209 @@ int32_t basilisk_process_swapverify(struct supernet_info *myinfo,void *ptr,int32 else return(0); } +void basilisk_swapgotdata(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t crc32,bits256 srchash,bits256 desthash,uint32_t quoteid,uint32_t msgbits,uint8_t *data,int32_t datalen,int32_t reinit) +{ + int32_t i; struct basilisk_swapmessage *mp; + for (i=0; inummessages; i++) + if ( crc32 == swap->messages[i].crc32 && msgbits == swap->messages[i].msgbits && bits256_cmp(srchash,swap->messages[i].srchash) == 0 && bits256_cmp(desthash,swap->messages[i].desthash) == 0 ) + return; + printf(" new message.[%d] datalen.%d Q.%x msg.%x [%llx]\n",swap->nummessages,datalen,quoteid,msgbits,*(long long *)data); + swap->messages = realloc(swap->messages,sizeof(*swap->messages) * (swap->nummessages + 1)); + mp = &swap->messages[swap->nummessages++]; + mp->crc32 = crc32; + mp->srchash = srchash; + mp->desthash = desthash; + mp->msgbits = msgbits; + mp->quoteid = quoteid; + mp->data = malloc(datalen); + mp->datalen = datalen; + memcpy(mp->data,data,datalen); + if ( reinit == 0 && swap->fp != 0 ) + { + fwrite(mp,1,sizeof(*mp),swap->fp); + fwrite(data,1,datalen,swap->fp); + fflush(swap->fp); + } +} + +FILE *basilisk_swap_save(struct supernet_info *myinfo,struct basilisk_swap *swap,bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration,int32_t reinit) +{ + FILE *fp=0; char fname[512]; + sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,rp->requestid,rp->quoteid), OS_compatible_path(fname); + if ( (fp= fopen(fname,"rb+")) == 0 ) + { + if ( (fp= fopen(fname,"wb+")) != 0 ) + { + fwrite(privkey.bytes,1,sizeof(privkey),fp); + fwrite(rp,1,sizeof(*rp),fp); + fwrite(&statebits,1,sizeof(statebits),fp); + fwrite(&optionduration,1,sizeof(optionduration),fp); + fflush(fp); + } + } + else if ( reinit != 0 ) + { + } + return(fp); +} + +int32_t basilisk_swap_load(uint32_t requestid,uint32_t quoteid,bits256 *privkeyp,struct basilisk_request *rp,uint32_t *statebitsp,int32_t *optiondurationp) +{ + FILE *fp=0; char fname[512]; int32_t retval = -1; + sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname); + if ( (fp= fopen(fname,"rb+")) != 0 ) + { + if ( fread(privkeyp,1,sizeof(*privkeyp),fp) == sizeof(*privkeyp) && + fread(rp,1,sizeof(*rp),fp) == sizeof(*rp) && + fread(statebitsp,1,sizeof(*statebitsp),fp) == sizeof(*statebitsp) && + fread(optiondurationp,1,sizeof(*optiondurationp),fp) == sizeof(*optiondurationp) ) + retval = 0; + fclose(fp); + } + return(retval); +} + +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); + +void basilisk_swaps_init(struct supernet_info *myinfo) +{ + char fname[512]; uint32_t iter,swapcompleted,requestid,quoteid,optionduration,statebits; FILE *fp; bits256 privkey;struct basilisk_request R; struct basilisk_swapmessage M; struct basilisk_swap *swap = 0; + sprintf(fname,"%s/SWAPS/list",GLOBAL_DBDIR), OS_compatible_path(fname); + if ( (myinfo->swapsfp= fopen(fname,"rb+")) != 0 ) + { + while ( fread(&requestid,1,sizeof(requestid),myinfo->swapsfp) == sizeof(requestid) && fread("eid,1,sizeof(quoteid),myinfo->swapsfp) == sizeof(quoteid) ) + { + sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname); + printf("%s\n",fname); + if ( (fp= fopen(fname,"rb+")) != 0 ) // check to see if completed + { + memset(&M,0,sizeof(M)); + swapcompleted = 1; + for (iter=0; iter<2; iter++) + { + if ( fread(privkey.bytes,1,sizeof(privkey),fp) == sizeof(privkey) && + fread(&R,1,sizeof(R),fp) == sizeof(R) && + fread(&statebits,1,sizeof(statebits),fp) == sizeof(statebits) && + fread(&optionduration,1,sizeof(optionduration),fp) == sizeof(optionduration) ) + { + while ( 0 && fread(&M,1,sizeof(M),fp) == sizeof(M) ) + { + M.data = 0; + //printf("entry iter.%d crc32.%x datalen.%d\n",iter,M.crc32,M.datalen); + if ( M.datalen < 100000 ) + { + M.data = malloc(M.datalen); + fread(M.data,1,M.datalen,fp); + if ( calc_crc32(0,M.data,M.datalen) == M.crc32 ) + { + if ( iter == 1 ) + { + if ( swap == 0 ) + { + swap = basilisk_thread_start(myinfo,privkey,&R,statebits,optionduration,1); + swap->I.choosei = swap->I.otherchoosei = -1; + } + if ( swap != 0 ) + basilisk_swapgotdata(myinfo,swap,M.crc32,M.srchash,M.desthash,M.quoteid,M.msgbits,M.data,M.datalen,1); + } + } else printf("crc mismatch %x vs %x\n",calc_crc32(0,M.data,M.datalen),M.crc32); + free(M.data), M.data = 0; + } + } + } + if ( swapcompleted != 0 ) + break; + rewind(fp); + } + } + } + } +} + +void basilisk_psockinit(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t amlp); + 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 datalen; uint32_t crc; - if ( (crc= basilisk_crcrecv(myinfo,0,swap->verifybuf,sizeof(swap->verifybuf),&datalen,swap->I.otherhash,swap->I.myhash,swap->I.req.quoteid,msgbits)) != 0 ) + uint8_t *ptr; bits256 srchash,desthash; uint32_t crc32,_msgbits,quoteid; int32_t i,size,offset,retval = -1; struct basilisk_swapmessage *mp = 0; + while ( (size= nn_recv(swap->subsock,&ptr,NN_MSG,0)) >= 0 ) + { + swap->lasttime = (uint32_t)time(NULL); + memset(srchash.bytes,0,sizeof(srchash)); + memset(desthash.bytes,0,sizeof(desthash)); + //printf("gotmsg.[%d] crc.%x\n",size,crc32); + offset = 0; + for (i=0; i<32; i++) + srchash.bytes[i] = ptr[offset++]; + for (i=0; i<32; i++) + desthash.bytes[i] = ptr[offset++]; + offset += iguana_rwnum(0,&ptr[offset],sizeof(uint32_t),"eid); + offset += iguana_rwnum(0,&ptr[offset],sizeof(uint32_t),&_msgbits); + crc32 = calc_crc32(0,&ptr[offset],size-offset); + if ( size > offset ) + { + //printf("size.%d offset.%d datalen.%d\n",size,offset,size-offset); + basilisk_swapgotdata(myinfo,swap,crc32,srchash,desthash,quoteid,_msgbits,&ptr[offset],size-offset,0); + } + if ( ptr != 0 ) + nn_freemsg(ptr), ptr = 0; + } + //char str[65],str2[65]; + for (i=0; inummessages; i++) { - if ( datalen > 0 && datalen < maxlen ) + //printf("%d: %s vs %s\n",i,bits256_str(str,swap->messages[i].srchash),bits256_str(str2,swap->messages[i].desthash)); + if ( bits256_cmp(swap->messages[i].desthash,swap->I.myhash) == 0 ) { - memcpy(data,swap->verifybuf,datalen); - return((*basilisk_verify_func)(myinfo,swap,data,datalen)); + if ( swap->messages[i].msgbits == msgbits ) + { + if ( swap->I.iambob == 0 && swap->lasttime != 0 && time(NULL) > swap->lasttime+360 ) + { + printf("nothing received for a while from Bob, try new sockets\n"); + if ( swap->pushsock >= 0 ) + nn_close(swap->pushsock), swap->pushsock = -1; + if ( swap->subsock >= 0 ) + nn_close(swap->subsock), swap->subsock = -1; + swap->connected = 0; + basilisk_psockinit(myinfo,swap,0); + } + mp = &swap->messages[i]; + if ( msgbits != 0x80000000 ) + break; + } } } - return(-1); + if ( mp != 0 ) + retval = (*basilisk_verify_func)(myinfo,swap,mp->data,mp->datalen); + //printf("mine/other %s vs %s\n",bits256_str(str,swap->I.myhash),bits256_str(str2,swap->I.otherhash)); + return(retval); } 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 ) - // 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 ) - //return(nextbits); - dex_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen); //INSTANTDEX_LOCKTIME*2 - return(0); + uint8_t *buf; int32_t sentbytes,offset=0,i; + buf = malloc(datalen + sizeof(msgbits) + sizeof(swap->I.req.quoteid) + sizeof(bits256)*2); + for (i=0; i<32; i++) + buf[offset++] = swap->I.myhash.bytes[i]; + for (i=0; i<32; i++) + buf[offset++] = swap->I.otherhash.bytes[i]; + offset += iguana_rwnum(1,&buf[offset],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); + offset += iguana_rwnum(1,&buf[offset],sizeof(msgbits),&msgbits); + if ( datalen > 0 ) + memcpy(&buf[offset],data,datalen), offset += datalen; + if ( (sentbytes= nn_send(swap->pushsock,buf,offset,0)) != offset ) + { + printf("sentbytes.%d vs offset.%d\n",sentbytes,offset); + if ( sentbytes < 0 ) + { + if ( swap->pushsock >= 0 ) + nn_close(swap->pushsock), swap->pushsock = -1; + if ( swap->subsock >= 0 ) + nn_close(swap->subsock), swap->subsock = -1; + swap->connected = 0; + } + } + //else printf("send.[%d] %x offset.%d datalen.%d [%llx]\n",sentbytes,msgbits,offset,datalen,*(long long *)data); + free(buf); + return(nextbits); } int32_t basilisk_priviextract(struct supernet_info *myinfo,struct iguana_info *coin,char *name,bits256 *destp,uint8_t secret160[20],bits256 srctxid,int32_t srcvout) @@ -917,7 +1247,7 @@ int32_t basilisk_priviextract(struct supernet_info *myinfo,struct iguana_info *c if ( memcmp(secret160,rmd160,sizeof(rmd160)) == sizeof(rmd160) ) { *destp = privkey; - printf("found %s (%s)\n",name,bits256_str(str,privkey)); + printf("found privi %s (%s)\n",name,bits256_str(str,privkey)); return(0); } } @@ -929,11 +1259,11 @@ int32_t basilisk_privBn_extract(struct supernet_info *myinfo,struct basilisk_swa { if ( basilisk_priviextract(myinfo,swap->bobcoin,"privBn",&swap->I.privBn,swap->I.secretBn,swap->bobrefund.I.actualtxid,0) == 0 ) { - + printf("extracted privBn from blockchain\n"); } if ( basilisk_swapget(myinfo,swap,0x40000000,data,maxlen,basilisk_verify_privi) == 0 ) { - if ( bits256_nonz(swap->I.privBn) != 0 && swap->alicereclaim.txbytes == 0 ) + if ( bits256_nonz(swap->I.privBn) != 0 && swap->alicereclaim.I.datalen == 0 ) { char str[65]; printf("have privBn.%s\n",bits256_str(str,swap->I.privBn)); return(basilisk_alicepayment_spend(myinfo,swap,&swap->alicereclaim)); @@ -948,7 +1278,7 @@ int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swa { } - if ( bits256_nonz(swap->I.privAm) != 0 && swap->bobspend.txbytes == 0 ) + if ( bits256_nonz(swap->I.privAm) != 0 && swap->bobspend.I.datalen == 0 ) { char str[65]; printf("have privAm.%s\n",bits256_str(str,swap->I.privAm)); return(basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend)); @@ -956,15 +1286,15 @@ int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swa return(-1); } -bits256 instantdex_derivekeypair(struct supernet_info *myinfo,bits256 *newprivp,uint8_t pubkey[33],bits256 privkey,bits256 orderhash) +bits256 instantdex_derivekeypair(void *ctx,bits256 *newprivp,uint8_t pubkey[33],bits256 privkey,bits256 orderhash) { bits256 sharedsecret; sharedsecret = curve25519_shared(privkey,orderhash); vcalc_sha256cat(newprivp->bytes,orderhash.bytes,sizeof(orderhash),sharedsecret.bytes,sizeof(sharedsecret)); - return(bitcoin_pubkey33(myinfo->ctx,pubkey,*newprivp)); + return(bitcoin_pubkey33(ctx,pubkey,*newprivp)); } -int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte) +int32_t instantdex_pubkeyargs(void *ctx,struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte) { char buf[3]; int32_t i,n,m,len=0; bits256 pubi,reveal; uint64_t txid; uint8_t secret160[20],pubkey[33]; sprintf(buf,"%c0",'A' - 0x02 + firstbyte); @@ -972,12 +1302,12 @@ int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap { if ( swap->I.numpubs+2 >= numpubs ) return(numpubs); - printf(">>>>>> start generating %s\n",buf); + //fprintf(stderr,">>>>>> start generating %s\n",buf); } for (i=n=m=0; iname,name); rawtx->coin = coin; + strcpy(rawtx->I.coinstr,coin->symbol); rawtx->I.numconfirms = numconfirms; - if ( (rawtx->I.amount= satoshis) < 10000 ) - rawtx->I.amount = 10000; + if ( (rawtx->I.amount= satoshis) < 50000 ) + rawtx->I.amount = 50000; rawtx->I.vintype = vintype; // 0 -> std, 2 -> 2of2, 3 -> spend bobpayment, 4 -> spend bobdeposit rawtx->I.vouttype = vouttype; // 0 -> fee, 1 -> std, 2 -> 2of2, 3 -> bobpayment, 4 -> bobdeposit if ( rawtx->I.vouttype == 0 ) { - if ( strcmp(coin->symbol,"BTC") == 0 && (swap->I.req.quoteid % 10) == 0 ) - decode_hex(rawtx->I.rmd160,20,TIERNOLAN_RMD160); - else decode_hex(rawtx->I.rmd160,20,INSTANTDEX_RMD160); + if ( jumblrflag == 0 ) + { + if ( strcmp(coin->symbol,"BTC") == 0 && (quoteid % 10) == 0 ) + decode_hex(rawtx->I.rmd160,20,TIERNOLAN_RMD160); + else decode_hex(rawtx->I.rmd160,20,INSTANTDEX_RMD160); + } else decode_hex(rawtx->I.rmd160,20,JUMBLR_RMD160); bitcoin_address(rawtx->I.destaddr,rawtx->coin->chain->pubtype,rawtx->I.rmd160,20); } if ( pubkey33 != 0 ) @@ -1050,34 +1384,15 @@ void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basi } 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(bits256 pubkey,struct iguana_info **bobcoinp,struct iguana_info **alicecoinp,char *src,char *dest,bits256 srchash,bits256 desthash) { struct iguana_info *coin = iguana_coinfind(src); if ( coin == 0 || iguana_coinfind(dest) == 0 ) return(0); *bobcoinp = *alicecoinp = 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); - *alicecoinp = iguana_coinfind(dest); - } - else if ( (coin= iguana_coinfind(dest)) != 0 && coin->chain->havecltv != 0 ) - { - *bobcoinp = iguana_coinfind(dest); - *alicecoinp = iguana_coinfind(src); - } - else return(0); - if ( bits256_cmp(myinfo->myaddr.persistent,srchash) == 0 ) + *bobcoinp = iguana_coinfind(dest); + *alicecoinp = iguana_coinfind(src); + if ( bits256_cmp(pubkey,srchash) == 0 ) { if ( strcmp(src,(*bobcoinp)->symbol) == 0 ) return(1); @@ -1085,7 +1400,7 @@ int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobco return(-1); else return(0); } - else if ( bits256_cmp(myinfo->myaddr.persistent,desthash) == 0 ) + else if ( bits256_cmp(pubkey,desthash) == 0 ) { if ( strcmp(src,(*bobcoinp)->symbol) == 0 ) return(-1); @@ -1096,136 +1411,167 @@ int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobco return(0); } -struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t optionduration) +void basilisk_swap_saveupdate(struct supernet_info *myinfo,struct basilisk_swap *swap) { - struct iguana_info *coin,*bobcoin,*alicecoin; uint8_t *alicepub33=0,*bobpub33=0; int32_t x = -1; - swap->I.putduration = swap->I.callduration = INSTANTDEX_LOCKTIME; - if ( optionduration < 0 ) - swap->I.putduration -= optionduration; - else if ( optionduration > 0 ) - swap->I.callduration += optionduration; - if ( strcmp("BTC",swap->I.req.src) == 0 ) + FILE *fp; char fname[512]; + sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid), OS_compatible_path(fname); + if ( (fp= fopen(fname,"wb")) != 0 ) + { + fwrite(&swap->I,1,sizeof(swap->I),fp); + /*fwrite(&swap->bobdeposit,1,sizeof(swap->bobdeposit),fp); + fwrite(&swap->bobpayment,1,sizeof(swap->bobpayment),fp); + fwrite(&swap->alicepayment,1,sizeof(swap->alicepayment),fp); + fwrite(&swap->myfee,1,sizeof(swap->myfee),fp); + fwrite(&swap->otherfee,1,sizeof(swap->otherfee),fp); + fwrite(&swap->aliceclaim,1,sizeof(swap->aliceclaim),fp); + fwrite(&swap->alicespend,1,sizeof(swap->alicespend),fp); + fwrite(&swap->bobreclaim,1,sizeof(swap->bobreclaim),fp); + fwrite(&swap->bobspend,1,sizeof(swap->bobspend),fp); + fwrite(&swap->bobrefund,1,sizeof(swap->bobrefund),fp); + fwrite(&swap->alicereclaim,1,sizeof(swap->alicereclaim),fp);*/ + fwrite(swap->privkeys,1,sizeof(swap->privkeys),fp); + fwrite(swap->otherdeck,1,sizeof(swap->otherdeck),fp); + fwrite(swap->deck,1,sizeof(swap->deck),fp); + fclose(fp); + } +} + +int32_t basilisk_swap_loadtx(struct basilisk_rawtx *rawtx,FILE *fp,char *bobcoinstr,char *alicecoinstr) +{ + if ( fread(rawtx,1,sizeof(*rawtx),fp) == sizeof(*rawtx) ) { - swap->bobcoin = iguana_coinfind("BTC"); - swap->I.bobsatoshis = swap->I.req.srcamount; - swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1)); - swap->alicecoin = iguana_coinfind(swap->I.req.dest); - swap->I.alicesatoshis = swap->I.req.destamount; - swap->I.aliceconfirms = swap->I.bobconfirms * 3; + rawtx->coin = 0; + rawtx->vins = 0; + if ( strcmp(rawtx->I.coinstr,bobcoinstr) == 0 || strcmp(rawtx->I.coinstr,alicecoinstr) == 0 ) + { + rawtx->coin = iguana_coinfind(rawtx->I.coinstr); + if ( rawtx->vinstr[0] != 0 ) + rawtx->vins = cJSON_Parse(rawtx->vinstr); + printf("loaded.%s len.%d\n",rawtx->name,rawtx->I.datalen); + return(0); + } } - else if ( strcmp("BTC",swap->I.req.dest) == 0 ) + return(-1); +} + +struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits,int32_t reinit) +{ + FILE *fp; char fname[512]; uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag,x = -1; + if ( reinit != 0 ) { - swap->bobcoin = iguana_coinfind("BTC"); - swap->I.bobsatoshis = swap->I.req.destamount; - swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1)); - swap->alicecoin = iguana_coinfind(swap->I.req.src); - swap->I.alicesatoshis = swap->I.req.srcamount; - swap->I.aliceconfirms = swap->I.bobconfirms * 3; + sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid), OS_compatible_path(fname); + printf("reinit.(%s)\n",fname); + if ( (fp= fopen(fname,"rb")) != 0 ) + { + fread(&swap->I,1,sizeof(swap->I),fp); + if ( swap->bobcoin == 0 ) + swap->bobcoin = iguana_coinfind(swap->I.req.dest); + if ( swap->alicecoin == 0 ) + swap->alicecoin = iguana_coinfind(swap->I.req.src); + if ( swap->alicecoin != 0 && swap->bobcoin != 0 ) + { + /*basilisk_swap_loadtx(&swap->bobdeposit,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobpayment,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->alicepayment,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->myfee,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->otherfee,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->aliceclaim,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->alicespend,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobreclaim,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobspend,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobrefund,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->alicereclaim,fp,swap->bobcoin->symbol,swap->alicecoin->symbol);*/ + } else printf("missing coins (%p %p)\n",swap->bobcoin,swap->alicecoin); + fread(swap->privkeys,1,sizeof(swap->privkeys),fp); + fread(swap->otherdeck,1,sizeof(swap->otherdeck),fp); + fread(swap->deck,1,sizeof(swap->deck),fp); + fclose(fp); + } else printf("cant find.(%s)\n",fname); } else { - if ( (coin= iguana_coinfind(swap->I.req.src)) != 0 ) + swap->I.putduration = swap->I.callduration = INSTANTDEX_LOCKTIME; + if ( optionduration < 0 ) + swap->I.putduration -= optionduration; + else if ( optionduration > 0 ) + swap->I.callduration += optionduration; + swap->I.bobsatoshis = swap->I.req.destamount; + swap->I.alicesatoshis = swap->I.req.srcamount; + if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < 50000 ) + swap->I.bobinsurance = 50000; + if ( (swap->I.aliceinsurance= (swap->I.alicesatoshis / INSTANTDEX_INSURANCEDIV)) < 50000 ) + swap->I.aliceinsurance = 50000; + strcpy(swap->I.bobstr,swap->I.req.dest); + strcpy(swap->I.alicestr,swap->I.req.src); + swap->I.started = (uint32_t)time(NULL); + swap->I.expiration = swap->I.req.timestamp + swap->I.putduration + swap->I.callduration; + OS_randombytes((uint8_t *)&swap->I.choosei,sizeof(swap->I.choosei)); + if ( swap->I.choosei < 0 ) + swap->I.choosei = -swap->I.choosei; + swap->I.choosei %= INSTANTDEX_DECKSIZE; + swap->I.otherchoosei = -1; + swap->I.myhash = pubkey25519; + if ( statebits != 0 ) { - if ( coin->chain->havecltv != 0 ) - { - swap->bobcoin = coin; - swap->I.bobsatoshis = swap->I.req.srcamount; - swap->alicecoin = iguana_coinfind(swap->I.req.dest); - swap->I.alicesatoshis = swap->I.req.destamount; - } - else if ( (coin= iguana_coinfind(swap->I.req.dest)) != 0 ) - { - if ( coin->chain->havecltv != 0 ) - { - swap->bobcoin = coin; - swap->I.bobsatoshis = swap->I.req.destamount; - swap->alicecoin = iguana_coinfind(swap->I.req.src); - 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); + swap->I.iambob = 0; + swap->I.otherhash = swap->I.req.desthash; + } + else + { + swap->I.iambob = 1; + swap->I.otherhash = swap->I.req.srchash; + } + if ( bits256_nonz(privkey) == 0 || (x= instantdex_pubkeyargs(myinfo->ctx,swap,2 + INSTANTDEX_DECKSIZE,privkey,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE ) + { + char str[65]; printf("couldnt generate privkeys %d %s\n",x,bits256_str(str,privkey)); + return(0); + } } + swap->bobcoin = iguana_coinfind(swap->I.req.dest); + swap->alicecoin = iguana_coinfind(swap->I.req.src); if ( swap->bobcoin == 0 || swap->alicecoin == 0 ) { 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); return(0); } + swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1)); + swap->I.aliceconfirms = swap->I.bobconfirms * 3; if ( swap->I.bobconfirms == 0 ) swap->I.bobconfirms = swap->bobcoin->chain->minconfirms; if ( swap->I.aliceconfirms == 0 ) swap->I.aliceconfirms = swap->alicecoin->chain->minconfirms; - if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 ) - swap->I.bobinsurance = 10000; - if ( (swap->I.aliceinsurance= (swap->I.alicesatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 ) - swap->I.aliceinsurance = 10000; - strcpy(swap->I.bobstr,swap->bobcoin->symbol); - strcpy(swap->I.alicestr,swap->alicecoin->symbol); - swap->I.started = (uint32_t)time(NULL); - swap->I.expiration = swap->I.req.timestamp + swap->I.putduration + swap->I.callduration; - OS_randombytes((uint8_t *)&swap->I.choosei,sizeof(swap->I.choosei)); - if ( swap->I.choosei < 0 ) - swap->I.choosei = -swap->I.choosei; - swap->I.choosei %= INSTANTDEX_DECKSIZE; - swap->I.otherchoosei = -1; - swap->I.myhash = myinfo->myaddr.persistent; - if ( bits256_cmp(swap->I.myhash,swap->I.req.srchash) == 0 ) - { - swap->I.otherhash = swap->I.req.desthash; - if ( strcmp(swap->I.req.src,swap->I.bobstr) == 0 ) - swap->I.iambob = 1; - } - else if ( bits256_cmp(swap->I.myhash,swap->I.req.desthash) == 0 ) - { - swap->I.otherhash = swap->I.req.srchash; - if ( strcmp(swap->I.req.dest,swap->I.bobstr) == 0 ) - swap->I.iambob = 1; - } - else - { - printf("neither src nor dest error\n"); - return(0); - } - 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("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); - } - 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 ) - { - printf("couldnt generate privkeys %d\n",x); - return(0); - } + jumblrflag = (bits256_cmp(pubkey25519,myinfo->jumblr_pubkey) == 0 || bits256_cmp(pubkey25519,myinfo->jumblr_depositkey) == 0); if ( swap->I.iambob != 0 ) { - basilisk_rawtx_setparms("myfee",myinfo,swap,&swap->myfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0); - basilisk_rawtx_setparms("otherfee",myinfo,swap,&swap->otherfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0); - bobpub33 = myinfo->persistent_pubkey33; + basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0,jumblrflag); + basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0,jumblrflag); + bobpub33 = pubkey33; } else { - basilisk_rawtx_setparms("otherfee",myinfo,swap,&swap->otherfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0); - basilisk_rawtx_setparms("myfee",myinfo,swap,&swap->myfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0); - alicepub33 = myinfo->persistent_pubkey33; + basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0,jumblrflag); + basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0,jumblrflag); + alicepub33 = pubkey33; } - basilisk_rawtx_setparms("bobdeposit",myinfo,swap,&swap->bobdeposit,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3) + swap->bobcoin->txfee,4,0); - basilisk_rawtx_setparms("bobrefund",myinfo,swap,&swap->bobrefund,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,bobpub33); + basilisk_rawtx_setparms("bobdeposit",swap->I.req.quoteid,&swap->bobdeposit,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3) + swap->bobcoin->txfee,4,0,jumblrflag); + basilisk_rawtx_setparms("bobrefund",swap->I.req.quoteid,&swap->bobrefund,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,bobpub33,jumblrflag); swap->bobrefund.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("aliceclaim",myinfo,swap,&swap->aliceclaim,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,alicepub33); + basilisk_rawtx_setparms("aliceclaim",swap->I.req.quoteid,&swap->aliceclaim,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,alicepub33,jumblrflag); swap->aliceclaim.I.suppress_pubkeys = 1; swap->aliceclaim.I.locktime = swap->I.started + swap->I.putduration+swap->I.callduration + 1; - basilisk_rawtx_setparms("bobpayment",myinfo,swap,&swap->bobpayment,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin->txfee,3,0); - basilisk_rawtx_setparms("alicespend",myinfo,swap,&swap->alicespend,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33); + basilisk_rawtx_setparms("bobpayment",swap->I.req.quoteid,&swap->bobpayment,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin->txfee,3,0,jumblrflag); + basilisk_rawtx_setparms("alicespend",swap->I.req.quoteid,&swap->alicespend,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33,jumblrflag); swap->alicespend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("bobreclaim",myinfo,swap,&swap->bobreclaim,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33); + basilisk_rawtx_setparms("bobreclaim",swap->I.req.quoteid,&swap->bobreclaim,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33,jumblrflag); swap->bobreclaim.I.suppress_pubkeys = 1; swap->bobreclaim.I.locktime = swap->I.started + swap->I.putduration + 1; - basilisk_rawtx_setparms("alicepayment",myinfo,swap,&swap->alicepayment,swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis+swap->alicecoin->txfee,2,0); - basilisk_rawtx_setparms("bobspend",myinfo,swap,&swap->bobspend,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33); + basilisk_rawtx_setparms("alicepayment",swap->I.req.quoteid,&swap->alicepayment,swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis+swap->alicecoin->txfee,2,0,jumblrflag); + basilisk_rawtx_setparms("bobspend",swap->I.req.quoteid,&swap->bobspend,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33,jumblrflag); swap->bobspend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("alicereclaim",myinfo,swap,&swap->alicereclaim,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33); + basilisk_rawtx_setparms("alicereclaim",swap->I.req.quoteid,&swap->alicereclaim,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33,jumblrflag); swap->alicereclaim.I.suppress_pubkeys = 1; printf("IAMBOB.%d\n",swap->I.iambob); return(swap); @@ -1234,12 +1580,15 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil void basilisk_rawtx_purge(struct basilisk_rawtx *rawtx) { - if ( rawtx->txbytes != 0 ) - free(rawtx->txbytes), rawtx->txbytes = 0; + if ( rawtx->vins != 0 ) + free_json(rawtx->vins); + //if ( rawtx->txbytes != 0 ) + // free(rawtx->txbytes), rawtx->txbytes = 0; } void basilisk_swap_finished(struct supernet_info *myinfo,struct basilisk_swap *swap) { + int32_t i; swap->I.finished = (uint32_t)time(NULL); // save to permanent storage basilisk_rawtx_purge(&swap->bobdeposit); @@ -1247,11 +1596,17 @@ void basilisk_swap_finished(struct supernet_info *myinfo,struct basilisk_swap *s basilisk_rawtx_purge(&swap->alicepayment); basilisk_rawtx_purge(&swap->myfee); basilisk_rawtx_purge(&swap->otherfee); - basilisk_rawtx_purge(&swap->alicereclaim); + basilisk_rawtx_purge(&swap->aliceclaim); basilisk_rawtx_purge(&swap->alicespend); basilisk_rawtx_purge(&swap->bobreclaim); basilisk_rawtx_purge(&swap->bobspend); basilisk_rawtx_purge(&swap->bobrefund); + basilisk_rawtx_purge(&swap->alicereclaim); + for (i=0; inummessages; i++) + if ( swap->messages[i].data != 0 ) + free(swap->messages[i].data), swap->messages[i].data = 0; + free(swap->messages), swap->messages = 0; + swap->nummessages = 0; } void basilisk_swap_purge(struct supernet_info *myinfo,struct basilisk_swap *swap) @@ -1274,10 +1629,12 @@ void basilisk_swap_purge(struct supernet_info *myinfo,struct basilisk_swap *swap int32_t basilisk_verify_otherstatebits(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) { - struct basilisk_swap *swap = ptr; + int32_t retval; struct basilisk_swap *swap = ptr; if ( datalen == sizeof(swap->I.otherstatebits) ) - return(iguana_rwnum(0,data,sizeof(swap->I.otherstatebits),&swap->I.otherstatebits)); - else return(-1); + { + retval = iguana_rwnum(0,data,sizeof(swap->I.otherstatebits),&swap->I.otherstatebits); + return(retval); + } else return(-1); } int32_t basilisk_verify_choosei(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) @@ -1376,9 +1733,31 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t return(errs); } -uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits) +void basilisk_dontforget(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t locktime,bits256 triggertxid) +{ + char fname[512],str[65]; FILE *fp; int32_t i; + sprintf(fname,"%s/SWAPS/%u-%u.%s",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid,rawtx->name), OS_compatible_path(fname); + if ( (fp= fopen(fname,"wb")) != 0 ) + { + fprintf(fp,"{\"name\":\"%s\",\"coin\":\"%s\"",rawtx->name,rawtx->coin->symbol); + if ( rawtx->I.datalen > 0 ) + { + fprintf(fp,",\"tx\":\""); + for (i=0; iI.datalen; i++) + fprintf(fp,"%02x",rawtx->txbytes[i]); + fprintf(fp,"\",\"txid\":\"%s\"",bits256_str(str,bits256_doublesha256(0,rawtx->txbytes,rawtx->I.datalen))); + } + fprintf(fp,",\"lock\":%u",locktime); + if ( bits256_nonz(triggertxid) != 0 ) + fprintf(fp,",\"trigger\":\"%s\"",bits256_str(str,triggertxid)); + fprintf(fp,"}\n"); + fclose(fp); + } +} + +uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits,int32_t suppress_swapsend) { - uint8_t sendbuf[32768]; int32_t sendlen; + uint8_t sendbuf[32768]; int32_t sendlen; bits256 triggertxid; if ( basilisk_swapdata_rawtx(myinfo,swap,data,maxlen,rawtx) != 0 ) { if ( bits256_nonz(rawtx->I.signedtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 ) @@ -1399,12 +1778,47 @@ uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilis memcpy(&sendbuf[sendlen],rawtx->redeemscript,rawtx->I.redeemlen); sendlen += rawtx->I.redeemlen; } + memset(triggertxid.bytes,0,sizeof(triggertxid)); + if ( swap->I.iambob != 0 ) + { + if ( rawtx == &swap->bobdeposit ) + { + basilisk_dontforget(myinfo,swap,&swap->bobdeposit,0,triggertxid); + basilisk_dontforget(myinfo,swap,&swap->bobrefund,0,triggertxid); + } + else if ( rawtx == &swap->bobpayment ) + { + basilisk_dontforget(myinfo,swap,&swap->bobpayment,0,triggertxid); + basilisk_dontforget(myinfo,swap,&swap->bobreclaim,swap->bobpayment.I.locktime,triggertxid); + } + else if ( rawtx == &swap->bobspend ) + basilisk_dontforget(myinfo,swap,&swap->bobspend,0,triggertxid); + } + else + { + if ( rawtx == &swap->alicepayment ) + { + basilisk_dontforget(myinfo,swap,&swap->alicepayment,0,triggertxid); + } + else if ( rawtx == &swap->alicespend ) + { + basilisk_dontforget(myinfo,swap,&swap->alicespend,0,triggertxid); + //basilisk_alicepayment_spend(myinfo,swap,&swap->alicereclaim); + basilisk_dontforget(myinfo,swap,&swap->alicereclaim,0,swap->bobrefund.I.actualtxid); + } + } //printf("sendlen.%d datalen.%d redeemlen.%d\n",sendlen,rawtx->datalen,rawtx->redeemlen); - return(basilisk_swapsend(myinfo,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->I.crcs)); + if ( suppress_swapsend == 0 ) + return(basilisk_swapsend(myinfo,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->I.crcs)); + else + { + printf("suppress swapsend %x\n",msgbits); + return(0); + } } } return(nextbits); - } else printf("error from basilisk_swapdata_rawtx %p len.%d\n",rawtx->txbytes,rawtx->I.datalen); + } else printf("error from basilisk_swapdata_rawtx.%s %p len.%d\n",rawtx->name,rawtx->txbytes,rawtx->I.datalen); return(0); } @@ -1412,7 +1826,7 @@ void basilisk_sendpubkeys(struct supernet_info *myinfo,struct basilisk_swap *swa { int32_t datalen; datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen); - //printf("send deck.%d\n",datalen); + printf("send deck.%d\n",datalen); swap->I.statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01,swap->I.crcs_mypub); } @@ -1430,7 +1844,7 @@ int32_t basilisk_checkdeck(struct supernet_info *myinfo,struct basilisk_swap *sw void basilisk_sendstate(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) { - int32_t datalen; + int32_t datalen=0; datalen = iguana_rwnum(1,data,sizeof(swap->I.statebits),&swap->I.statebits); basilisk_swapsend(myinfo,swap,0x80000000,data,datalen,0,0); } @@ -1460,7 +1874,7 @@ void basilisk_sendchoosei(struct supernet_info *myinfo,struct basilisk_swap *swa void basilisk_waitchoosei(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) { - uint8_t pubkey33[33]; //char str[65],str2[65]; + uint8_t pubkey33[33]; char str[65],str2[65]; //printf("check otherchoosei\n"); if ( basilisk_swapget(myinfo,swap,0x08,data,maxlen,basilisk_verify_choosei) == 0 ) { @@ -1473,7 +1887,7 @@ void basilisk_waitchoosei(struct supernet_info *myinfo,struct basilisk_swap *swa revcalc_rmd160_sha256(swap->I.secretBn,swap->I.privBn);//.bytes,sizeof(swap->privBn)); vcalc_sha256(0,swap->I.secretBn256,swap->I.privBn.bytes,sizeof(swap->I.privBn)); swap->I.pubBn = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->I.privBn); - //printf("set privBn.%s %s\n",bits256_str(str,swap->privBn),bits256_str(str2,*(bits256 *)swap->secretBn256)); + printf("set privBn.%s %s\n",bits256_str(str,swap->I.privBn),bits256_str(str2,*(bits256 *)swap->I.secretBn256)); basilisk_bobscripts_set(myinfo,swap,1,1); } } @@ -1486,7 +1900,7 @@ void basilisk_waitchoosei(struct supernet_info *myinfo,struct basilisk_swap *swa revcalc_rmd160_sha256(swap->I.secretAm,swap->I.privAm);//.bytes,sizeof(swap->privAm)); vcalc_sha256(0,swap->I.secretAm256,swap->I.privAm.bytes,sizeof(swap->I.privAm)); swap->I.pubAm = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->I.privAm); - //printf("set privAm.%s %s\n",bits256_str(str,swap->privAm),bits256_str(str2,*(bits256 *)swap->secretAm256)); + char str[65],str2[65]; printf("set privAm.%s %s\n",bits256_str(str,swap->I.privAm),bits256_str(str2,*(bits256 *)swap->I.secretAm256)); //basilisk_bobscripts_set(myinfo,swap,0); } } @@ -1525,17 +1939,13 @@ void basilisk_sendmostprivs(struct supernet_info *myinfo,struct basilisk_swap *s swap->I.statebits |= basilisk_swapsend(myinfo,swap,0x20,data,datalen,0x10,swap->I.crcs_myprivs); } -void basilisk_alicepayment(struct supernet_info *myinfo,struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn) -{ - alicepayment->I.spendlen = basilisk_alicescript(alicepayment->redeemscript,&alicepayment->I.redeemlen,alicepayment->spendscript,0,alicepayment->I.destaddr,coin->chain->p2shtype,pubAm,pubBn); - basilisk_rawtx_gen("alicepayment",myinfo,swap,0,1,alicepayment,alicepayment->I.locktime,alicepayment->spendscript,alicepayment->I.spendlen,coin->chain->txfee,1,0); -} - int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) { int32_t j,datalen,retval = 0; while ( ((swap->I.otherstatebits & 0x80) == 0 || (swap->I.statebits & 0x80) == 0) && retval == 0 && time(NULL) < swap->I.expiration ) { + if ( swap->connected == 0 ) + basilisk_psockinit(myinfo,swap,swap->I.iambob != 0); printf("D 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.statebits & 0x80) == 0 ) // wait for fee { @@ -1550,14 +1960,18 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); if ( (swap->I.otherstatebits & 0x80) != 0 && (swap->I.statebits & 0x80) != 0 ) break; - sleep(3 + (swap->I.iambob == 0)*1); + sleep(DEX_SLEEP + (swap->I.iambob == 0)*1); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); basilisk_sendstate(myinfo,swap,data,maxlen); if ( (swap->I.otherstatebits & 0x80) == 0 ) - basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40); + basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40,0); } + basilisk_swap_saveupdate(myinfo,swap); while ( retval == 0 && time(NULL) < swap->I.expiration ) // both sides have setup required data and paid txfee { + basilisk_swap_saveupdate(myinfo,swap); + if ( swap->connected == 0 ) + basilisk_psockinit(myinfo,swap,swap->I.iambob != 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); if ( swap->I.iambob != 0 ) @@ -1566,7 +1980,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap if ( (swap->I.statebits & 0x100) == 0 ) { printf("send bobdeposit\n"); - swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x200,data,maxlen,&swap->bobdeposit,0x100); + swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0); } // [BLOCKING: altfound] make sure altpayment is confirmed and send payment else if ( (swap->I.statebits & 0x1000) == 0 ) @@ -1575,12 +1989,12 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap if ( basilisk_swapget(myinfo,swap,0x1000,data,maxlen,basilisk_verify_alicepaid) == 0 ) { swap->I.statebits |= 0x1000; - printf("got alicepayment\n"); + printf("got alicepayment aliceconfirms.%d\n",swap->I.aliceconfirms); } } else if ( (swap->I.statebits & 0x2000) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->alicepayment) >= swap->I.aliceconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->alicepayment) >= swap->I.aliceconfirms ) { swap->I.statebits |= 0x2000; printf("alicepayment confirmed\n"); @@ -1590,28 +2004,28 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap { basilisk_bobscripts_set(myinfo,swap,0,1); printf("send bobpayment\n"); - swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000); + swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0); } // [BLOCKING: privM] Bob waits for privAm either from Alice or alice blockchain - else if ( (swap->I.statebits & 0x40000) == 0 ) + else if ( (swap->I.statebits & 0xc0000) != 0xc0000 ) { if ( basilisk_swapget(myinfo,swap,0x40000,data,maxlen,basilisk_verify_privi) == 0 || basilisk_privAm_extract(myinfo,swap) == 0 ) // divulges privAm { - printf("got privi spend alicepayment\n"); + //printf("got privi spend alicepayment, dont divulge privBn until bobspend propagated\n"); basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend); - if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobspend,0x40000) == 0 ) + if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobspend,0x40000,1) == 0 ) printf("Bob error spending alice payment\n"); else { tradebot_swap_balancingtrade(myinfo,swap,1); printf("Bob spends alicepayment\n"); swap->I.statebits |= 0x40000; - while ( basilisk_numconfirms(myinfo,&swap->bobspend) < swap->I.aliceconfirms ) + while ( basilisk_numconfirms(myinfo,swap,&swap->bobspend) < swap->I.aliceconfirms ) { printf("bobspend confirmed\n"); swap->I.statebits |= 0x80000; printf("Bob confirms spend of Alice's payment\n"); - sleep(10); + sleep(DEX_SLEEP); } retval = 1; } @@ -1622,14 +2036,14 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap // submit reclaim of payment printf("bob reclaims bobpayment\n"); swap->I.statebits |= (0x40000 | 0x80000); - if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobreclaim,0) == 0 ) + if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobreclaim,0,0) == 0 ) printf("Bob error reclaiming own payment after alice timed out\n"); else { printf("Bob reclaimed own payment\n"); while ( 0 && (swap->I.statebits & 0x100000) == 0 ) // why wait for own tx? { - if ( basilisk_numconfirms(myinfo,&swap->bobreclaim) >= 1 ) + if ( basilisk_numconfirms(myinfo,swap,&swap->bobreclaim) >= 1 ) { printf("bobreclaim confirmed\n"); swap->I.statebits |= 0x100000; @@ -1657,7 +2071,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x400) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->bobdeposit) >= swap->I.bobconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->bobdeposit) >= swap->I.bobconfirms ) { printf("bobdeposit confirmed\n"); swap->I.statebits |= 0x400; @@ -1666,7 +2080,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap else if ( (swap->I.statebits & 0x800) == 0 ) { printf("send alicepayment\n"); - swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x1000,data,maxlen,&swap->alicepayment,0x800); + swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x1000,data,maxlen,&swap->alicepayment,0x800,0); } // [BLOCKING: payfound] make sure payment is confrmed and send in spend or see bob's reclaim and claim else if ( (swap->I.statebits & 0x8000) == 0 ) @@ -1681,7 +2095,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x10000) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->bobpayment) >= swap->I.bobconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->bobpayment) >= swap->I.bobconfirms ) { printf("bobpayment confirmed\n"); swap->I.statebits |= 0x10000; @@ -1690,17 +2104,17 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap else if ( (swap->I.statebits & 0x20000) == 0 ) { printf("alicespend bobpayment\n"); - if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 && basilisk_numconfirms(myinfo,&swap->alicespend) > 0 ) + if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000,0) != 0 && basilisk_numconfirms(myinfo,swap,&swap->alicespend) > 0 ) { for (j=datalen=0; j<32; j++) data[datalen++] = swap->I.privAm.bytes[j]; - printf("send privAm\n"); swap->I.statebits |= basilisk_swapsend(myinfo,swap,0x40000,data,datalen,0x20000,swap->I.crcs_mypriv); + printf("send privAm %x\n",swap->I.statebits); } } else if ( (swap->I.statebits & 0x40000) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->alicespend) >= swap->I.bobconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->alicespend) >= swap->I.bobconfirms ) { swap->I.statebits |= 0x40000; printf("Alice confirms spend of Bob's payment\n"); @@ -1710,7 +2124,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap if ( swap->bobdeposit.I.locktime != 0 && time(NULL) > swap->bobdeposit.I.locktime ) { printf("Alice claims deposit\n"); - if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->aliceclaim,0) == 0 ) + if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->aliceclaim,0,0) == 0 ) printf("Alice couldnt claim deposit\n"); else { @@ -1722,7 +2136,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap { printf("Alice reclaims her payment\n"); swap->I.statebits |= 0x40000000; - if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicereclaim,0x40000000) == 0 ) + if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicereclaim,0x40000000,0) == 0 ) printf("Alice error sending alicereclaim\n"); else { @@ -1733,7 +2147,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } if ( (rand() % 30) == 0 ) printf("finished swapstate.%x other.%x\n",swap->I.statebits,swap->I.otherstatebits); - sleep(3 + (swap->I.iambob == 0)); + sleep(DEX_SLEEP + (swap->I.iambob == 0)); basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); } @@ -1753,10 +2167,90 @@ cJSON *swapjson(struct supernet_info *myinfo,struct basilisk_swap *swap) return(retjson); } +void basilisk_psockinit(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t amlp) +{ + char keystr[64],databuf[1024],*retstr,*retstr2,*datastr,*pushaddr=0,*subaddr=0; cJSON *retjson,*addrjson; uint8_t data[512]; int32_t datalen,timeout,pushsock = -1,subsock = -1; + if ( swap->connected == 1 ) + return; + if ( swap->pushsock < 0 && swap->subsock < 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 && (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) + { + timeout = 100; + nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + timeout = 1; + nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); + swap->pushsock = pushsock; + swap->subsock = subsock; + } + if ( swap->subsock < 0 || swap->pushsock < 0 ) + { + printf("error getting nn_sockets\n"); + return; + } + sprintf(keystr,"%08x-%08x",swap->I.req.requestid,swap->I.req.quoteid); + if ( (retstr= _dex_kvsearch(myinfo,"KV",keystr)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (datastr= jstr(retjson,"value")) != 0 ) + { + datalen = (int32_t)strlen(datastr) >> 1; + decode_hex((uint8_t *)databuf,datalen,datastr); + if ( (addrjson= cJSON_Parse(databuf)) != 0 ) + { + pushaddr = jstr(addrjson,"push"); + subaddr = jstr(addrjson,"sub"); + if ( pushaddr != 0 && subaddr != 0 ) + { + printf("KV decoded (%s and %s) %d %d\n",pushaddr,subaddr,swap->pushsock,swap->subsock); + if ( nn_connect(swap->pushsock,pushaddr) >= 0 && nn_connect(swap->subsock,subaddr) >= 0 ) + swap->connected = 1; + } + free_json(addrjson); + } + } + free_json(retjson); + } + printf("KVsearch.(%s) connected.%d socks.(%d %d)\n",retstr,swap->connected,swap->pushsock,swap->subsock); + free(retstr); + } + if ( swap->connected == 0 && amlp != 0 ) + { + if ( (retstr= _dex_psock(myinfo,"{}")) != 0 ) + { + // {"result":"success","pushaddr":"tcp://5.9.102.210:30002","subaddr":"tcp://5.9.102.210:30003","randipbits":3606291758,"coin":"KMD","tag":"6952562460568228137"} + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + pushaddr = jstr(retjson,"pushaddr"); + subaddr = jstr(retjson,"subaddr"); + if ( pushaddr != 0 && subaddr != 0 ) + { + if ( nn_connect(pushsock,pushaddr) >= 0 && nn_connect(subsock,subaddr) >= 0 ) + { + swap->connected = 1; + sprintf((char *)data,"{\"push\":\"%s\",\"sub\":\"%s\"}",pushaddr,subaddr); + datalen = (int32_t)strlen((char *)data) + 1; + printf("datalen.%d (%s)\n",datalen,(char *)data); + init_hexbytes_noT(databuf,data,datalen); + printf("%s -> %s\n",keystr,databuf); + if ( (retstr2= _dex_kvupdate(myinfo,"KV",keystr,databuf,1)) != 0 ) + { + printf("KVupdate.(%s)\n",retstr2); + free(retstr2); + } + } + } + free_json(retjson); + } + free(retstr); + } + } +} + void basilisk_swaploop(void *_swap) { - uint8_t *data; uint32_t expiration; uint32_t channel; int32_t retval=0,i,j,datalen,maxlen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; - myinfo = swap->myinfo; + uint8_t *data; uint32_t expiration; uint32_t channel; int32_t iters,retval=0,i,j,datalen,maxlen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; + myinfo = swap->myinfoptr; fprintf(stderr,"start swap\n"); maxlen = 1024*1024 + sizeof(*swap); data = malloc(maxlen); @@ -1765,22 +2259,31 @@ void basilisk_swaploop(void *_swap) channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); 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); - //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_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys - if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02 - basilisk_sendchoosei(myinfo,swap,data,maxlen); - basilisk_waitchoosei(myinfo,swap,data,maxlen); // wait for choosei 0x08 - if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) ) - break; - sleep(1); - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); + if ( swap->connected == 0 ) + basilisk_psockinit(myinfo,swap,swap->I.iambob != 0); + if ( swap->connected != 0 ) + { + printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); + basilisk_sendstate(myinfo,swap,data,maxlen); + basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys + if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02 + basilisk_sendchoosei(myinfo,swap,data,maxlen); + basilisk_waitchoosei(myinfo,swap,data,maxlen); // wait for choosei 0x08 + if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) ) + break; + } + sleep(DEX_SLEEP); + } + if ( swap->connected == 0 ) + { + printf("couldnt establish connection\n"); + retval = -1; } - while ( (swap->I.statebits & 0x20) == 0 && time(NULL) < expiration ) + while ( retval == 0 && (swap->I.statebits & 0x20) == 0 && time(NULL) < expiration ) { + if ( swap->connected == 0 ) + basilisk_psockinit(myinfo,swap,swap->I.iambob != 0); printf("B r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_sendchoosei(myinfo,swap,data,maxlen); @@ -1790,24 +2293,26 @@ void basilisk_swaploop(void *_swap) swap->I.statebits |= 0x20; break; } - sleep(3 + (swap->I.iambob == 0)*1); - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); + sleep(DEX_SLEEP + (swap->I.iambob == 0)*1); } + myinfo->DEXactive = swap->I.expiration; if ( time(NULL) >= expiration ) + { retval = -1; - myinfo->DEXactive = swap->I.expiration; + myinfo->DEXactive = 0; + } 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 + iters = 0; + while ( retval == 0 && (swap->I.statebits & 0x40) == 0 && iters++ < 10 ) // send fee { - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); - printf("sendstate.%x\n",swap->I.statebits); + if ( swap->connected == 0 ) + basilisk_psockinit(myinfo,swap,swap->I.iambob != 0); + //printf("sendstate.%x\n",swap->I.statebits); basilisk_sendstate(myinfo,swap,data,maxlen); - printf("swapget\n"); + //printf("swapget\n"); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); - printf("after swapget\n"); - if ( swap->myfee.txbytes == 0 ) + //printf("after swapget\n"); + if ( swap->myfee.I.datalen == 0 ) { /*for (i=0; i<20; i++) printf("%02x",swap->secretAm[i]); @@ -1845,7 +2350,7 @@ void basilisk_swaploop(void *_swap) printf("bobscripts set\n"); if ( basilisk_bobscripts_set(myinfo,swap,1,1) < 0 ) { - sleep(3); + sleep(DEX_SLEEP); printf("bobscripts set error\n"); continue; } @@ -1857,15 +2362,15 @@ void basilisk_swaploop(void *_swap) //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); - if ( swap->alicepayment.txbytes == 0 || swap->alicepayment.I.spendlen == 0 ) + if ( swap->alicepayment.I.datalen == 0 || swap->alicepayment.I.spendlen == 0 ) { printf("error alice generating payment.%d\n",swap->alicepayment.I.spendlen); - sleep(3); + sleep(DEX_SLEEP); } else { retval = 0; - for (i=0; ialicepayment.I.spendlen; i++) + for (i=0; ialicepayment.I.datalen; i++) printf("%02x",swap->alicepayment.txbytes[i]); printf(" ALICE PAYMENT created\n"); iguana_unspents_mark(myinfo,swap->alicecoin,swap->alicepayment.vins); @@ -1875,17 +2380,17 @@ 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->I.started,swap->persistent_pubkey33,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,0); iguana_unspents_mark(myinfo,swap->I.iambob!=0?swap->bobcoin:swap->alicecoin,swap->myfee.vins); basilisk_txlog(myinfo,swap,&swap->myfee,-1); for (i=0; imyfee.I.spendlen; i++) printf("%02x",swap->myfee.txbytes[i]); printf(" fee %p %x\n",swap->myfee.txbytes,swap->I.statebits); swap->I.statebits |= 0x40; - if ( swap->alicepayment.txbytes != 0 && swap->alicepayment.I.spendlen > 0 ) + if ( swap->alicepayment.I.datalen != 0 && swap->alicepayment.I.spendlen > 0 ) break; } else @@ -1895,22 +2400,40 @@ void basilisk_swaploop(void *_swap) } } } - while ( basilisk_swapiteration(myinfo,swap,data,maxlen) == 0 ) + if ( (swap->I.statebits & 0x40) == 0 ) + { + printf("couldnt send fee\n"); + retval = -8; + } + if ( retval == 0 ) + { + if ( swap->I.iambob == 0 && (swap->myfee.I.datalen == 0 || swap->alicepayment.I.datalen == 0 || swap->alicepayment.I.datalen == 0) ) + { + printf("ALICE's error %d %d %d\n",swap->myfee.I.datalen,swap->alicepayment.I.datalen,swap->alicepayment.I.datalen); + retval = -7; + } + else if ( swap->I.iambob != 0 && (swap->myfee.I.datalen == 0 || swap->bobpayment.I.datalen == 0 || swap->bobdeposit.I.datalen == 0) ) + { + printf("BOB's error %d %d %d\n",swap->myfee.I.datalen,swap->bobpayment.I.datalen,swap->bobdeposit.I.datalen); + retval = -7; + } + } + while ( retval == 0 && basilisk_swapiteration(myinfo,swap,data,maxlen) == 0 ) { - sleep(3); + sleep(DEX_SLEEP); basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); + basilisk_swap_saveupdate(myinfo,swap); if ( time(NULL) > swap->I.expiration ) break; - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); } - printf("end of atomic swap\n"); - if ( swap->I.iambob != 0 && swap->bobdeposit.txbytes != 0 ) + if ( swap->I.iambob != 0 && swap->bobdeposit.I.datalen != 0 ) { + printf("BOB waiting for confirm state.%x\n",swap->I.statebits); + sleep(60); // wait for confirm/propagation of msig printf("BOB reclaims refund\n"); basilisk_bobdeposit_refund(myinfo,swap,0); - if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobrefund,0x40000000) == 0 ) // use secretBn + if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobrefund,0x40000000,0) == 0 ) // use secretBn { printf("Bob submit error getting refund of deposit\n"); } @@ -1921,7 +2444,9 @@ void basilisk_swaploop(void *_swap) data[datalen++] = swap->I.privBn.bytes[j]; basilisk_swapsend(myinfo,swap,0x40000000,data,datalen,0x40000000,swap->I.crcs_mypriv); } + basilisk_swap_saveupdate(myinfo,swap); } + printf("end of atomic swap\n"); if ( swapcompleted(myinfo,swap) > 0 ) // only if swap completed { if ( swap->I.iambob != 0 ) @@ -1933,9 +2458,10 @@ void basilisk_swaploop(void *_swap) free(data); } -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,bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration,int32_t reinit) { - int32_t i,m,n; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; 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 basilisk_swap *swap = 0; + // statebits 1 -> client, 0 -> LP portable_mutex_lock(&myinfo->DEX_swapmutex); for (i=0; inumswaps; i++) if ( myinfo->swaps[i]->I.req.requestid == rp->requestid ) @@ -1945,56 +2471,116 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct } 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->subsock = swap->pushsock = -1; vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); swap->I.req = *rp; - swap->myinfo = myinfo; + swap->myinfoptr = myinfo; + printf("basilisk_thread_start request.%u statebits.%d (%s/%s) reinit.%d\n",rp->requestid,statebits,rp->src,rp->dest,reinit); + bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey); + pubkey25519 = curve25519(privkey,curve25519_basepoint9()); + swap->persistent_pubkey = pubkey25519; + swap->persistent_privkey = privkey; + memcpy(swap->persistent_pubkey33,pubkey33,33); m = n = 0; - if ( bitcoin_swapinit(myinfo,swap,optionduration) != 0 ) + if ( bitcoin_swapinit(myinfo,privkey,pubkey33,pubkey25519,swap,optionduration,statebits,reinit) != 0 ) { - starttime = (uint32_t)time(NULL); - printf("statebits.%x m.%d n.%d\n",statebits,m,n); - while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+BASILISK_MSGDURATION ) + basilisk_psockinit(myinfo,swap,statebits == 0); + if ( reinit != 0 ) + { + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 ) + { + + } + myinfo->swaps[myinfo->numswaps++] = swap; + } + else { - m = n = 0; - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); - sleep(3); - printf("waiting for offer to be accepted\n"); - channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); - if ( (retarray= basilisk_channelget(myinfo,rp->srchash,rp->desthash,channel,0x4000000,30)) != 0 ) + starttime = (uint32_t)time(NULL); + printf("statebits.%x m.%d n.%d\n",statebits,m,n); + while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+2*BASILISK_MSGDURATION ) + { + m = n = 0; + sleep(DEX_SLEEP); + printf("waiting for offer to be accepted\n"); + channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); + if ( (retarray= basilisk_channelget(myinfo,rp->srchash,rp->desthash,channel,0x4000000,30)) != 0 ) + { + if ( is_cJSON_Array(retarray) != 0 && (n= cJSON_GetArraySize(retarray)) > 0 ) + { + for (i=0; i 0 ) + { + item = jitem(msgobj,0); + if ( jobj(item,"data") != 0 && jobj(item,"key") != 0 ) + m++; + else printf("(%s)\n",jprint(item,0)); + } //else printf("msgobj.%p m.%d n.%d\n",msgobj,m,n); + } + } + } else printf("no retarray\n"); + } + printf("LAUNCH check.%d m.%d\n",statebits,m); + if ( statebits != 0 || m > 0 )//n/2 ) { - if ( is_cJSON_Array(retarray) != 0 && (n= cJSON_GetArraySize(retarray)) > 0 ) + //for (i=0; iI.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); + if ( (swap->fp= basilisk_swap_save(myinfo,swap,privkey,rp,statebits,optionduration,reinit)) != 0 ) { - for (i=0; i 0 ) + if ( myinfo->swapsfp == 0 ) { - item = jitem(msgobj,0); - if ( jobj(item,"data") != 0 && jobj(item,"key") != 0 ) - m++; - else printf("(%s)\n",jprint(item,0)); - } //else printf("msgobj.%p m.%d n.%d\n",msgobj,m,n); + char fname[512]; + sprintf(fname,"%s/SWAPS/list",GLOBAL_DBDIR), OS_compatible_path(fname); + if ( (myinfo->swapsfp= fopen(fname,"rb+")) == 0 ) + myinfo->swapsfp = fopen(fname,"wb+"); + else fseek(myinfo->swapsfp,0,SEEK_END); + } + if ( myinfo->swapsfp != 0 ) + { + fwrite(&rp->requestid,1,sizeof(rp->requestid),myinfo->swapsfp); + fwrite(&rp->quoteid,1,sizeof(rp->quoteid),myinfo->swapsfp); + fflush(myinfo->swapsfp); + } } } - } else printf("no retarray\n"); + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 ) + { + + } + 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); } - printf("LAUNCH check.%d m.%d\n",statebits,m); - if ( statebits != 0 || m > 0 )//n/2 ) - { - //for (i=0; iI.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); - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 ) - { - - } - 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); } } portable_mutex_unlock(&myinfo->DEX_swapmutex); return(swap); } + +char *basilisk_swaplist(struct supernet_info *myinfo) +{ + char fname[512]; FILE *fp; struct basilisk_request R; int32_t optionduration; uint32_t quoteid,requestid,statebits; cJSON *retjson,*array; bits256 privkey; + retjson = cJSON_CreateObject(); + array = cJSON_CreateArray(); + sprintf(fname,"%s/SWAPS/list",GLOBAL_DBDIR), OS_compatible_path(fname); + if ( (fp= fopen(fname,"rb")) != 0 ) + { + while ( fread(&requestid,1,sizeof(requestid),fp) == sizeof(requestid) && fread("eid,1,sizeof(quoteid),fp) == sizeof(quoteid) ) + { + if ( basilisk_swap_load(requestid,quoteid,&privkey,&R,&statebits,&optionduration) == 0 ) + { + jaddi(array,basilisk_requestjson(&R)); + } + } + fclose(fp); + } + jaddstr(retjson,"result","success"); + jadd(retjson,"swaps",array); + return(jprint(retjson,1)); +} + + diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index 7940a4e94..5d16548dc 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -69,12 +69,12 @@ int32_t basilisk_txitem(struct supernet_info *myinfo,struct basilisk_swap *swap, decode_hex((void *)&rawtx->I,sizeof(rawtx->I),hexstr); if ( (hexstr= jstr(obj,"txbytes")) != 0 && strlen(hexstr) == rawtx->I.datalen*2 ) { - if ( rawtx->txbytes == 0 ) + /*if ( rawtx->txbytes == 0 ) { printf("free (%s) txbytes\n",name); free(rawtx->txbytes); } - rawtx->txbytes = calloc(1,rawtx->I.datalen); + rawtx->txbytes = calloc(1,rawtx->I.datalen);*/ decode_hex((void *)rawtx->txbytes,rawtx->I.datalen,hexstr); } printf("PROCESS.(%s)\n",jprint(obj,0)); @@ -92,6 +92,7 @@ cJSON *basilisk_swapobj(struct supernet_info *myinfo,struct basilisk_swap *swap) jaddnum(obj,"quoteid",swap->I.req.quoteid); jadd(obj,"req",basilisk_requestjson(&swap->I.req)); jaddstr(obj,"info",hexstr); + //printf("strlen(hexstr) swap->I %d vs %d\n",(int32_t)strlen(hexstr),(int32_t)sizeof(swap->I)*2); return(obj); } @@ -104,7 +105,7 @@ int32_t basilisk_swapconv(struct supernet_info *myinfo,struct basilisk_swap *swa if ( juint(obj,"requestid") == swap->I.req.requestid && juint(obj,"quoteid") == swap->I.req.quoteid ) return(0); printf("swapconv mismatched req/quote %d %d, %d %d\n",juint(obj,"requestid"),swap->I.req.requestid,juint(obj,"quoteid"),swap->I.req.quoteid); - } else printf("no info field in swap obj\n"); + } //else printf("no info field in swap obj.(%s) len.%d vs %d\n",jprint(obj,0),(int32_t)strlen(hexstr),(int32_t)sizeof(swap->I)*2); return(-1); } @@ -278,7 +279,7 @@ int32_t basilisk_request_cmpref(struct basilisk_request *ref,struct basilisk_req double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk_request *issueR,struct basilisk_request *list,int32_t n) { - 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; bits256 privkey; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.; memset(issueR,0,sizeof(*issueR)); minamount = list[0].minamount; //printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid); @@ -288,7 +289,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk return(0.); pendingid = active->I.req.quoteid; } - if ( bits256_cmp(myinfo->myaddr.persistent,list[0].srchash) == 0 ) // my request + if ( smartaddress_pubkey(myinfo,&privkey,list[0].srchash) >= 0 ) myrequest = 1; for (i=0; imyaddr.persistent,list[i].desthash) == 0 ) // my quoteid + if ( smartaddress_pubkey(myinfo,&privkey,list[i].desthash) >= 0 ) myrequest |= 2; havequoteflag++; if ( pendingid == 0 ) @@ -331,7 +332,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk if ( fabs(aveprice) < SMALLVAL ) return(0); //retvals[0] = avebid, retvals[1] = bidvol, retvals[2] = aveask, retvals[3] = askvol; - destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount; + destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount * SATOSHIDEN; printf("aveprice %f dest %.8f avebid %f bidvol %f, aveask %f askvol %f\n",aveprice,dstr(destamount),retvals[0],retvals[1],retvals[2],retvals[3]); if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 ) { diff --git a/basilisk/jumblr.c b/basilisk/jumblr.c new file mode 100755 index 000000000..0710007c6 --- /dev/null +++ b/basilisk/jumblr.c @@ -0,0 +1,495 @@ +/****************************************************************************** + * Copyright © 2014-2017 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// included from basilisk.c +// connect DEX to jumblr-core + +/* + z_exportkey "zaddr" + z_exportwallet "filename" + z_getoperationstatus (["operationid", ... ]) + z_gettotalbalance ( minconf ) + z_importkey "zkey" ( rescan ) + z_importwallet "filename" + z_listaddresses + z_sendmany "fromaddress" [{"address":... ,"amount":..., "memo":""},...] ( minconf ) ( fee ) + */ + +#define JUMBLR_INCR 99.65 +#define JUMBLR_TXFEE 0.01 +#define JUMBLR_ADDR "RGhxXpXSSBTBm9EvNsXnTQczthMCxHX91t" +#define JUMBLR_BTCADDR "18RmTJe9qMech8siuhYfMtHo8RtcN1obC6" +#define JUMBLR_FEE 0.001 + +int32_t jumblr_addresstype(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + if ( addr[0] == 'z' && addr[1] == 'c' && strlen(addr) >= 40 ) + return('z'); + else if ( strlen(addr) < 40 ) + return('t'); + else return(-1); +} + +struct jumblr_item *jumblr_opidfind(struct supernet_info *myinfo,char *opid) +{ + struct jumblr_item *ptr; + HASH_FIND(hh,myinfo->jumblrs,opid,(int32_t)strlen(opid),ptr); + return(ptr); +} + +struct jumblr_item *jumblr_opidadd(struct supernet_info *myinfo,struct iguana_info *coin,char *opid) +{ + struct jumblr_item *ptr; + if ( (ptr= jumblr_opidfind(myinfo,opid)) == 0 ) + { + ptr = calloc(1,sizeof(*ptr)); + safecopy(ptr->opid,opid,sizeof(ptr->opid)); + HASH_ADD_KEYPTR(hh,myinfo->jumblrs,ptr->opid,(int32_t)strlen(ptr->opid),ptr); + if ( ptr != jumblr_opidfind(myinfo,opid) ) + printf("jumblr_opidadd.(%s) ERROR, couldnt find after add\n",opid); + } + return(ptr); +} + +char *jumblr_validateaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char params[1024]; + if ( coin->FULLNODE < 0 ) + { + sprintf(params,"[\"%s\"]",addr); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"validateaddress",params)); + } else return(_dex_validateaddress(myinfo,coin->symbol,addr)); +} + +int32_t jumblr_ismine(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char params[1024],*retstr; cJSON *retjson,*obj; int32_t retval = -1; + sprintf(params,"[\"%s\"]",addr); + if ( (retstr= jumblr_validateaddress(myinfo,coin,addr)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (obj= jobj(retjson,"ismine")) != 0 && is_cJSON_True(obj) != 0 ) + retval = 1; + else retval = 0; + free_json(retjson); + } + free(retstr); + } + return(retval); +} + +char *jumblr_zgetnewaddress(struct supernet_info *myinfo,struct iguana_info *coin) +{ + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getnewaddress","")); +} + +char *jumblr_zlistoperationids(struct supernet_info *myinfo,struct iguana_info *coin) +{ + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_listoperationids","")); +} + +char *jumblr_zgetoperationresult(struct supernet_info *myinfo,struct iguana_info *coin,char *opid) +{ + char params[1024]; + sprintf(params,"[[\"%s\"]]",opid); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getoperationresult",params)); +} + +char *jumblr_zgetoperationstatus(struct supernet_info *myinfo,struct iguana_info *coin,char *opid) +{ + char params[1024]; + sprintf(params,"[[\"%s\"]]",opid); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getoperationstatus",params)); +} + +char *jumblr_sendt_to_z(struct supernet_info *myinfo,struct iguana_info *coin,char *taddr,char *zaddr,double amount) +{ + char params[1024]; double fee = (amount-3*JUMBLR_TXFEE) * JUMBLR_FEE; + if ( jumblr_addresstype(myinfo,coin,zaddr) != 'z' || jumblr_addresstype(myinfo,coin,taddr) != 't' ) + return(clonestr("{\"error\":\"illegal address in t to z\"}")); + sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",taddr,zaddr,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_sendmany",params)); +} + +char *jumblr_sendz_to_z(struct supernet_info *myinfo,struct iguana_info *coin,char *zaddrS,char *zaddrD,double amount) +{ + char params[1024]; double fee = (amount-2*JUMBLR_TXFEE) * JUMBLR_FEE; + if ( jumblr_addresstype(myinfo,coin,zaddrS) != 'z' || jumblr_addresstype(myinfo,coin,zaddrD) != 'z' ) + return(clonestr("{\"error\":\"illegal address in z to z\"}")); + sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",zaddrS,zaddrD,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_sendmany",params)); +} + +char *jumblr_sendz_to_t(struct supernet_info *myinfo,struct iguana_info *coin,char *zaddr,char *taddr,double amount) +{ + char params[1024]; double fee = (amount-JUMBLR_TXFEE) * JUMBLR_FEE; + if ( jumblr_addresstype(myinfo,coin,zaddr) != 'z' || jumblr_addresstype(myinfo,coin,taddr) != 't' ) + return(clonestr("{\"error\":\"illegal address in z to t\"}")); + sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",zaddr,taddr,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_sendmany",params)); +} + +char *jumblr_zlistreceivedbyaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char params[1024]; + sprintf(params,"[\"%s\", 1]",addr); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_listreceivedbyaddress",params)); +} + +char *jumblr_getreceivedbyaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char params[1024]; + sprintf(params,"[\"%s\", 1]",addr); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getreceivedbyaddress",params)); +} + +char *jumblr_importprivkey(struct supernet_info *myinfo,struct iguana_info *coin,char *wifstr) +{ + char params[1024]; + sprintf(params,"[\"%s\", \"\", false]",wifstr); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"importprivkey",params)); +} + +char *jumblr_zgetbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char params[1024]; + sprintf(params,"[\"%s\", 1]",addr); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getbalance",params)); +} + +char *jumblr_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char params[1024]; + sprintf(params,"[1, 99999999, [\"%s\"]]",addr); + return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"listunspent",params)); +} + +int64_t jumblr_receivedby(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char *retstr; int64_t total = 0; + if ( (retstr= jumblr_getreceivedbyaddress(myinfo,coin,addr)) != 0 ) + { + total = atof(retstr) * SATOSHIDEN; + free(retstr); + } + return(total); +} + +int64_t jumblr_balance(struct supernet_info *myinfo,struct iguana_info *coin,char *addr) +{ + char *retstr; double val; cJSON *retjson; int32_t i,n; int64_t balance = 0; + if ( jumblr_addresstype(myinfo,coin,addr) == 't' ) + { + if ( coin->FULLNODE < 0 && jumblr_ismine(myinfo,coin,addr) > 0 ) + { + if ( (retstr= jumblr_listunspent(myinfo,coin,addr)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (n= cJSON_GetArraySize(retjson)) > 0 ) + for (i=0; isymbol,addr)) != 0 ) + { + //printf("retstr.(%s)\n",retstr); + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + balance = jdouble(retjson,"balance") * SATOSHIDEN; + free_json(retjson); + } + free(retstr); + } + } + else if ( (retstr= jumblr_zgetbalance(myinfo,coin,addr)) != 0 ) + { + if ( (val= atof(retstr)) > SMALLVAL ) + balance = val * SATOSHIDEN; + free(retstr); + } + return(balance); +} + +int32_t jumblr_itemset(struct jumblr_item *ptr,cJSON *item,char *status) +{ + cJSON *params,*amounts,*dest; char *from,*addr; int32_t i,n; int64_t amount; + /*"params" : { + "fromaddress" : "RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5", + "amounts" : [ + { + "address" : "zc9s3UdkDFTnnwHrMCr1vYy2WmkjhmTxXNiqC42s7BjeKBVUwk766TTSsrRPKfnX31Bbu8wbrTqnjDqskYGwx48FZMPHvft", + "amount" : 3.00000000 + } + ], + "minconf" : 1, + "fee" : 0.00010000 + }*/ + if ( (params= jobj(item,"params")) != 0 ) + { + //printf("params.(%s)\n",jprint(params,0)); + if ( (from= jstr(params,"fromaddress")) != 0 ) + { + safecopy(ptr->src,from,sizeof(ptr->src)); + } + if ( (amounts= jarray(&n,params,"amounts")) != 0 ) + { + for (i=0; i 0 ) + { + if ( strcmp(addr,JUMBLR_ADDR) == 0 ) + ptr->fee = amount; + else + { + ptr->amount = amount; + safecopy(ptr->dest,addr,sizeof(ptr->dest)); + } + } + } + } + ptr->txfee = jdouble(params,"fee") * SATOSHIDEN; + } + return(1); +} + +void jumblr_opidupdate(struct supernet_info *myinfo,struct iguana_info *coin,struct jumblr_item *ptr) +{ + char *retstr,*status,KMDjumblr[64],KMDdeposit[64],BTCaddr[64]; cJSON *retjson,*item; + if ( ptr->status == 0 ) + { + if ( (retstr= jumblr_zgetoperationstatus(myinfo,coin,ptr->opid)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( cJSON_GetArraySize(retjson) == 1 ) + { + item = jitem(retjson,0); + //printf("%s\n",jprint(item,0)); + if ( (status= jstr(item,"status")) != 0 ) + { + if ( strcmp(status,"success") == 0 ) + { + ptr->status = jumblr_itemset(ptr,item,status); + jumblr_privkey(myinfo,BTCaddr,KMDdeposit,JUMBLR_DEPOSITPREFIX); + jumblr_privkey(myinfo,BTCaddr,KMDjumblr,""); + if ( (jumblr_addresstype(myinfo,coin,ptr->src) == 't' && jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && strcmp(ptr->src,KMDdeposit) != 0) || (jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && jumblr_addresstype(myinfo,coin,ptr->src) == 't' && strcmp(ptr->dest,KMDjumblr) != 0) ) + { + printf("a non-jumblr t->z pruned\n"); + free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid)); + ptr->status = -1; + } + + } + else if ( strcmp(status,"failed") == 0 ) + { + printf("%s failed\n",ptr->opid); + free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid)); + ptr->status = -1; + } + } + } + free_json(retjson); + } + free(retstr); + } + } +} + +void jumblr_prune(struct supernet_info *myinfo,struct iguana_info *coin,struct jumblr_item *ptr) +{ + struct jumblr_item *tmp; char oldsrc[128]; int32_t flag = 1; + printf("PRUNE %s\n",ptr->opid); + strcpy(oldsrc,ptr->src); + free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid)); + while ( flag != 0 ) + { + flag = 0; + HASH_ITER(hh,myinfo->jumblrs,ptr,tmp) + { + if ( strcmp(oldsrc,ptr->dest) == 0 ) + { + printf("prune %s (%s -> %s) matched oldsrc\n",ptr->opid,ptr->src,ptr->dest); + free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid)); + strcpy(oldsrc,ptr->src); + flag = 1; + break; + } + } + } +} + +void jumblr_opidsupdate(struct supernet_info *myinfo,struct iguana_info *coin) +{ + char *retstr; cJSON *array; int32_t i,n; struct jumblr_item *ptr; + if ( (retstr= jumblr_zlistoperationids(myinfo,coin)) != 0 ) + { + if ( (array= cJSON_Parse(retstr)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; istatus == 0 ) + jumblr_opidupdate(myinfo,coin,ptr); + //printf("%d: %s -> %s %.8f\n",ptr->status,ptr->src,ptr->dest,dstr(ptr->amount)); + if ( jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && jumblr_addresstype(myinfo,coin,ptr->dest) == 't' ) + jumblr_prune(myinfo,coin,ptr); + } + } + } + free_json(array); + } + free(retstr); + } +} + +bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,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); + conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); + bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey); + bitcoin_address(BTCaddr,0,pubkey33,33); + bitcoin_address(KMDaddr,60,pubkey33,33); + return(privkey); +} + +void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coinkmd,char *BTCaddr,char *KMDaddr,bits256 privkey) +{ + 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+60 ) + { + kmdprice = get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,"komodo","KMD","BTC",&USD_average); + lasttime = (uint32_t)time(NULL); + printf("KMD %.8f\n",kmdprice); + } + 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+pending ) + { + printf("BTC deposits %.8f, min %.8f\n",btcavail,minbtc); + vals = cJSON_CreateObject(); + jaddstr(vals,"source","BTC"); + //hash = curve25519(privkey,curve25519_basepoint9()); + jaddstr(vals,"dest","KMD"); + jaddnum(vals,"amount",btcavail*.3); + jaddnum(vals,"minprice",kmdprice*.95); + jaddnum(vals,"usejumblr",1); + 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 pending %.8f\n",btcavail,pending); + } else printf("null kmdprice %.8f\n",kmdprice); +} + +void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int32_t selector,int32_t modval) +{ + //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; + fee = JUMBLR_INCR * JUMBLR_FEE; + OS_randombytes(&r,sizeof(r)); +//r = 0; + if ( strcmp(coin->symbol,"KMD") == 0 && coin->FULLNODE < 0 ) + { + //printf("JUMBLR selector.%d modval.%d r.%d\n",selector,modval,r&7); + switch ( selector ) + { + case 0: // public -> z, need to importprivkey + jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + if ( (total= jumblr_balance(myinfo,coin,KMDaddr)) >= (JUMBLR_INCR + 3*(fee+JUMBLR_TXFEE))*SATOSHIDEN ) + { + if ( (r & 1) == 0 ) + { + if ( (zaddr= jumblr_zgetnewaddress(myinfo,coin)) != 0 ) + { + if ( total >= SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*100 + 3*JUMBLR_TXFEE) ) + amount = SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*100 + 3*JUMBLR_TXFEE); + else if ( total >= SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*10 + 3*JUMBLR_TXFEE) ) + amount = SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*10 + 3*JUMBLR_TXFEE); + else amount = SATOSHIDEN * ((JUMBLR_INCR + 3*fee) + 3*JUMBLR_TXFEE); + if ( (retstr= jumblr_sendt_to_z(myinfo,coin,KMDaddr,zaddr,dstr(amount))) != 0 ) + { + printf("sendt_to_z.(%s)\n",retstr); + free(retstr); + } + free(zaddr); + } else printf("no zaddr from jumblr_zgetnewaddress\n"); + } + } else printf("%s total %.8f vs %.8f\n",KMDaddr,dstr(total),(JUMBLR_INCR + 3*(fee+JUMBLR_TXFEE))); + break; + case 1: // z -> z + jumblr_opidsupdate(myinfo,coin); + HASH_ITER(hh,myinfo->jumblrs,ptr,tmp) + { + if ( jumblr_addresstype(myinfo,coin,ptr->src) == 't' && jumblr_addresstype(myinfo,coin,ptr->dest) == 'z' ) + { + if ( (r & 1) == 0 && ptr->spent == 0 && (total= jumblr_balance(myinfo,coin,ptr->dest)) >= (fee + JUMBLR_FEE)*SATOSHIDEN ) + { + if ( (zaddr= jumblr_zgetnewaddress(myinfo,coin)) != 0 ) + { + if ( (retstr= jumblr_sendz_to_z(myinfo,coin,ptr->dest,zaddr,dstr(total))) != 0 ) + { + printf("sendz_to_z.(%s)\n",retstr); + free(retstr); + } + ptr->spent = (uint32_t)time(NULL); + free(zaddr); + break; + } + } + } + } + break; + case 2: // z -> public + jumblr_opidsupdate(myinfo,coin); + HASH_ITER(hh,myinfo->jumblrs,ptr,tmp) + { + if ( jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && jumblr_addresstype(myinfo,coin,ptr->dest) == 'z' ) + { + if ( (r & 1) == 0 && ptr->spent == 0 && (total= jumblr_balance(myinfo,coin,ptr->dest)) >= (fee + JUMBLR_FEE)*SATOSHIDEN ) + { + privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,""); + if ( (retstr= jumblr_sendz_to_t(myinfo,coin,ptr->dest,KMDaddr,dstr(total))) != 0 ) + { + printf("sendz_to_t.(%s)\n",retstr); + free(retstr); + } + ptr->spent = (uint32_t)time(NULL); + break; + } + } + } + break; + } + } +} + diff --git a/basilisk/smartaddress.c b/basilisk/smartaddress.c new file mode 100755 index 000000000..ff9707b0c --- /dev/null +++ b/basilisk/smartaddress.c @@ -0,0 +1,90 @@ +/****************************************************************************** + * Copyright © 2014-2017 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// included from basilisk.c + +int32_t smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *BTCaddr,char *KMDaddr) +{ + struct smartaddress *ap; + int32_t i; + if ( myinfo->numsmartaddrs < sizeof(myinfo->smartaddrs)/sizeof(*myinfo->smartaddrs) ) + { + for (i=0; inumsmartaddrs; i++) + if ( bits256_cmp(myinfo->smartaddrs[i].privkey,privkey) == 0 ) + return(-1); + ap = &myinfo->smartaddrs[myinfo->numsmartaddrs++]; + ap->privkey = privkey; + bitcoin_pubkey33(myinfo->ctx,ap->pubkey33,privkey); + calc_rmd160_sha256(ap->rmd160,ap->pubkey33,33); + ap->pubkey = curve25519(privkey,curve25519_basepoint9()); + char coinaddr[64]; uint8_t addrtype,rmd160[20]; + bitcoin_address(coinaddr,0,ap->pubkey33,33); + for (i=0; i<20; i++) + printf("%02x",ap->rmd160[i]); + bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + 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("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 i; uint8_t addrtype,rmd160[20]; + memset(privkeyp,0,sizeof(*privkeyp)); + bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + for (i=0; inumsmartaddrs; i++) + if ( memcmp(myinfo->smartaddrs[i].rmd160,rmd160,20) == 0 ) + { + *privkeyp = myinfo->smartaddrs[i].privkey; + printf("MATCHED %s\n",coinaddr); + return(i); + } + for (i=0; i<20; i++) + printf("%02x",rmd160[i]); + printf(" <- rmd160 smartaddress cant find (%s) of %d\n",coinaddr,myinfo->numsmartaddrs); + return(-1); +} + +int32_t smartaddress_pubkey(struct supernet_info *myinfo,bits256 *privkeyp,bits256 pubkey) +{ + int32_t i; + memset(privkeyp,0,sizeof(*privkeyp)); + for (i=0; inumsmartaddrs; i++) + if ( bits256_cmp(myinfo->smartaddrs[i].pubkey,pubkey) == 0 ) + { + *privkeyp = myinfo->smartaddrs[i].privkey; + return(i); + } + return(-1); +} + +int32_t smartaddress_pubkey33(struct supernet_info *myinfo,bits256 *privkeyp,uint8_t *pubkey33) +{ + int32_t i; + memset(privkeyp,0,sizeof(*privkeyp)); + for (i=0; inumsmartaddrs; i++) + if ( memcmp(myinfo->smartaddrs[i].pubkey33,pubkey33,33) == 0 ) + { + *privkeyp = myinfo->smartaddrs[i].privkey; + return(i); + } + return(0); +} + diff --git a/basilisk/tradebots_liquidity.c b/basilisk/tradebots_liquidity.c index cc38a2369..7e21127aa 100755 --- a/basilisk/tradebots_liquidity.c +++ b/basilisk/tradebots_liquidity.c @@ -110,7 +110,7 @@ int32_t tradebots_calcrawfeatures(struct tradebot_arbpair *pair) } if ( n > sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures) ) { - printf("n.%d too many for rawfeatures %ld\n",n,sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures)); + printf("n.%d too many for rawfeatures %d\n",n,(int32_t)(sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures))); exit(-1); } return(n); @@ -160,7 +160,7 @@ struct tradebot_arbpair *tradebots_arbpair_create(char *base,char *rel) pair->fp = OS_appendfile(fname); if ( (ftell(pair->fp) % sizeof(pair->rawfeatures)) != 0 ) { - printf("misalinged rawfeatures %ld %ld\n",ftell(pair->fp),(ftell(pair->fp) % sizeof(pair->rawfeatures))); + printf("misalinged rawfeatures %d %d\n",(uint32_t)ftell(pair->fp),(uint32_t)(ftell(pair->fp) % sizeof(pair->rawfeatures))); } fseek(pair->fp,(ftell(pair->fp) / sizeof(pair->rawfeatures)) * sizeof(pair->rawfeatures) - sizeof(pair->rawfeatures),SEEK_SET); if ( fread(pair->rawfeatures,1,sizeof(pair->rawfeatures),pair->fp) == sizeof(pair->rawfeatures) ) @@ -932,6 +932,8 @@ void _default_liquidity_command(struct supernet_info *myinfo,char *base,bits256 li.ask = jdouble(vals,"ask"); if ( (li.minvol= jdouble(vals,"minvol")) <= 0. ) li.minvol = (strcmp("BTC",base) == 0) ? 0.0001 : 0.001; + if ( strcmp(li.base,"KMD") == 0 && strcmp(li.rel,"BTC") == 0 && li.minvol > 100. ) + li.minvol = 100.; if ( (li.maxvol= jdouble(vals,"maxvol")) < li.minvol ) li.maxvol = li.minvol; if ( (li.totalvol= jdouble(vals,"total")) < li.maxvol ) @@ -1129,6 +1131,8 @@ 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) { + printf("balancing trade\n"); + return; if ( swap->balancingtrade == 0 ) _default_swap_balancingtrade(myinfo,swap,iambob); else (*swap->balancingtrade)(myinfo,swap,iambob); @@ -1203,35 +1207,3 @@ void tradebots_processprices(struct supernet_info *myinfo,struct exchange_info * } } } - -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -TWO_STRINGS(tradebot,gensvm,base,rel) -{ -#ifdef _WIN - return(clonestr("{\"error\":\"windows doesnt support SVM\"}")); -#else - int32_t numfeatures = 317*61; - struct tradebot_arbpair *pair; - if ( base[0] != 0 && rel[0] != 0 && (pair= tradebots_arbpair_find(base,rel)) != 0 && pair->fp != 0 ) - { - tradebots_calcanswers(pair); - ocas_gen(pair->refc,numfeatures,0,(int32_t)(ftell(pair->fp) / sizeof(pair->rawfeatures))); - return(clonestr("{\"result\":\"success\"}")); - } else return(clonestr("{\"error\":\"cant find arbpair\"}")); -#endif -} - -ZERO_ARGS(tradebot,openliquidity) -{ - int32_t i; cJSON *array = cJSON_CreateArray(); - for (i=0; ilinfos)/sizeof(*myinfo->linfos); i++) - { - if ( myinfo->linfos[i].base[0] != 0 ) - jaddi(array,linfo_json(&myinfo->linfos[i])); - } - return(jprint(array,1)); -} - -#include "../includes/iguana_apiundefs.h" diff --git a/basilisk/tradebots_marketmaker.c b/basilisk/tradebots_marketmaker.c index 7d5d5ec61..575861fa6 100755 --- a/basilisk/tradebots_marketmaker.c +++ b/basilisk/tradebots_marketmaker.c @@ -106,97 +106,3 @@ double tradebot_pending(struct supernet_info *myinfo,char *base) return(pending); } -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -ZERO_ARGS(tradebot,allbalances) -{ - int32_t i,n; double value,pending; char *base; cJSON *item,*balances = cJSON_CreateObject(); - if ( myinfo->liquidity_currencies == 0 ) - myinfo->liquidity_currencies = cJSON_Parse("[\"KMD\", \"BTC\"]"); - if ( myinfo->liquidity_currencies != 0 && (n= cJSON_GetArraySize(myinfo->liquidity_currencies)) > 0 ) - { - for (i=0; iliquidity_currencies,i); - value = tradebot_balance(myinfo,base); - pending = tradebot_pending(myinfo,base); - item = cJSON_CreateObject(); - jaddnum(item,"value",value); - jaddnum(item,"pending",pending); - jadd(balances,base,item); - } - } - return(jprint(balances,1)); -} - -ZERO_ARGS(tradebot,anchor) -{ - FILE *fp; char *anchorstr,fname[512]; cJSON *anchor; int32_t retval = -1; - if ( (anchorstr= tradebot_allbalances(myinfo,0,0,0)) != 0 ) - { - if ( (anchor= cJSON_Parse(anchorstr)) != 0 ) - { - if ( jobj(anchor,"error") == 0 ) - { - sprintf(fname,"%s/anchor",GLOBAL_DBDIR), OS_compatible_path(fname); - if ( (fp= fopen(fname,"wb")) != 0 ) - { - if ( fwrite(anchorstr,1,strlen(anchorstr)+1,fp) == strlen(anchorstr)+1 ) - retval = 0; - fclose(fp); - } - } - } - free(anchorstr); - } - if ( retval == 0 ) - return(clonestr("{\"result\":\"success\"}")); - else return(clonestr("{\"error\":\"couldnt make anchor file\"}")); -} - -ZERO_ARGS(tradebot,portfolio) -{ - char *currentstr,*anchorstr,fname[512]; long fsize; cJSON *current,*anchor=0,*portfolio=0; - if ( (currentstr= tradebot_allbalances(myinfo,0,0,0)) != 0 ) - { - if ( (current= cJSON_Parse(currentstr)) != 0 ) - { - sprintf(fname,"%s/anchor",GLOBAL_DBDIR), OS_compatible_path(fname); - if ( (anchorstr= OS_filestr(&fsize,fname)) != 0 ) - { - anchor = cJSON_Parse(anchorstr); - free(anchorstr); - } - if ( anchor == 0 ) - anchor = cJSON_Parse("{}"); - portfolio = tradebot_balancesdiff(myinfo,current,anchor); - free_json(current); - } - free(currentstr); - } - if ( portfolio == 0 ) - return(clonestr("{\"result\":\"success\"}")); - else return(jprint(portfolio,1)); -} - -ARRAY_OBJ_INT(tradebot,goals,currencies,vals,targettime) -{ - static bits256 zero; char *targetcoin; int32_t i,n; - if ( currencies != 0 && vals != 0 ) - { - // init things so automatically updates refli.bid and refli.ask - // volume range with margin - // currency percentage value in BTC? target distribution, max percentage, min percentage` - // min price to sell, max price to buy, max volume - n = cJSON_GetArraySize(currencies); - for (i=0; i -#include -#else #include #include -#endif // return data from the server #define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) diff --git a/crypto777/curve25519.c b/crypto777/curve25519.c index 5d2c24930..264d59952 100755 --- a/crypto777/curve25519.c +++ b/crypto777/curve25519.c @@ -1792,7 +1792,7 @@ void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig) int32_t acct777_sigcheck(struct acct777_sig *sig) { #define IGUANA_GENESIS 1453075200 -#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 2) +#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 4) #define TEN_YEARS (10 * 365 * 24 * 3600) if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE ) { diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index e9b8b8a51..80988fa5f 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -1164,7 +1164,7 @@ char *bittrex_orderbook(char *base,char *rel,int32_t maxdepth) double calc_theoretical(double weighted,double CMC_average,double changes[3]) { - double adjusted = 0.,theoretical = 0.; + double theoretical = 0.; //adjusted = 0., if ( weighted > SMALLVAL && CMC_average > SMALLVAL ) { theoretical = (weighted + CMC_average) * 0.5; @@ -1185,7 +1185,7 @@ double calc_theoretical(double weighted,double CMC_average,double changes[3]) if ( adjusted != 0. && theoretical != 0. ) theoretical = (theoretical + adjusted) * 0.5;*/ } - printf("adjusted %.8f theoretical %.8f (%.8f + wt %.8f)\n",adjusted,theoretical,CMC_average,weighted); + //printf("adjusted %.8f theoretical %.8f (%.8f + wt %.8f)\n",adjusted,theoretical,CMC_average,weighted); return(theoretical); } diff --git a/gecko/gecko.c b/gecko/gecko.c index 774139d3e..f8bdaeea3 100755 --- a/gecko/gecko.c +++ b/gecko/gecko.c @@ -273,9 +273,6 @@ char *basilisk_respond_geckoget(struct supernet_info *myinfo,char *CMD,void *add } else return(clonestr("{\"error\":\"invalid geckoget type, mustbe (HDR or BLK or GTX)\"}")); } -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx) { char *retstr = 0; struct iguana_info *virt,*btcd = iguana_coinfind("BTCD"); @@ -290,48 +287,5 @@ char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t return(retstr); } -HASH_ARRAY_STRING(basilisk,geckotx,hash,vals,hexstr) -{ - struct iguana_info *btcd; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid; - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 ) - { - if ( (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) - { - txid = bits256_doublesha256(0,data,datalen); - retstr = gecko_sendrawtransaction(myinfo,symbol,data,datalen,txid,vals,hexstr); - } else retstr = clonestr("{\"error\":\"no tx submitted\"}"); - if ( allocptr != 0 ) - free(allocptr); - if ( retstr == 0 ) - retstr = clonestr("{\"error\":\"couldnt create geckotx\"}"); - return(retstr); - } return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko tx\"}")); -} - -HASH_ARRAY_STRING(basilisk,geckoblock,hash,vals,hexstr) -{ - return(clonestr("{\"error\":\"geckoblock is an internal reporting function\"}")); -} - -HASH_ARRAY_STRING(basilisk,geckoheaders,hash,vals,hexstr) -{ - return(clonestr("{\"error\":\"geckoheaders is an internal reporting function\"}")); -} - -HASH_ARRAY_STRING(basilisk,geckoget,hash,vals,hexstr) -{ - struct iguana_info *btcd,*virt; char *symbol; - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 ) - { - if ( (virt= iguana_coinfind(symbol)) != 0 ) - { - basilisk_wait(myinfo,virt); - return(basilisk_respond_geckoget(myinfo,"GET",&coin->internaladdr,remoteaddr,0,vals,0,0,hash,0)); - } else return(clonestr("{\"error\":\"geckoget needs virtualchain\"}")); - } - return(clonestr("{\"error\":\"geckoget needs BTCD\"}")); -} - -#include "../includes/iguana_apiundefs.h" diff --git a/iguana.vcxproj b/iguana.vcxproj index e7a0d7a57..5a0050e59 100644 --- a/iguana.vcxproj +++ b/iguana.vcxproj @@ -73,12 +73,16 @@ true + $(ProjectDir)\includes;$(ProjectDir)\includes\curl;$(IncludePath) + $(ProjectDir)\OSlibs\win;$(LibraryPath) true false + $(ProjectDir)\includes;$(ProjectDir)\includes\curl;$(IncludePath) + $(ProjectDir)\OSlibs\win;$(LibraryPath) false @@ -97,7 +101,7 @@ Console true - Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;%(AdditionalDependencies) + Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;libcurl.lib;%(AdditionalDependencies) .\iguana;.\OSlibs\win;%(AdditionalLibraryDirectories) @@ -133,7 +137,7 @@ true true true - Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;%(AdditionalDependencies) + Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;libcurl.lib;%(AdditionalDependencies) .\OSlibs\win\release;%(AdditionalLibraryDirectories) diff --git a/iguana/SuperNET_keys.c b/iguana/SuperNET_keys.c index 904da0c83..31cbe6869 100755 --- a/iguana/SuperNET_keys.c +++ b/iguana/SuperNET_keys.c @@ -22,7 +22,6 @@ #include "../includes/curve25519.h" #include "../includes/cJSON.h" - /* if ( 0 ) { @@ -421,50 +420,4 @@ char *SuperNET_keysinit(struct supernet_info *myinfo,char *argjsonstr) return(coinargs); } -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -TWO_STRINGS(SuperNET,decryptjson,password,permanentfile) -{ - char pass[8192],fname2[1023],destfname[1024]; cJSON *retjson; bits256 wallethash,wallet2priv; - safecopy(pass,password,sizeof(pass)); - safecopy(fname2,permanentfile,sizeof(fname2)); - wallethash = wallet2priv = GENESIS_PRIVKEY; - if ( strlen(pass) == sizeof(wallethash)*2 && is_hexstr(pass,(int32_t)sizeof(bits256)*2) > 0 ) - wallethash = bits256_conv(pass); - if ( strlen(fname2) == sizeof(wallet2priv)*2 && is_hexstr(fname2,(int32_t)sizeof(bits256)*2) > 0 ) - wallet2priv = bits256_conv(fname2); - if ( (retjson= SuperNET_decryptedjson(destfname,pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 ) - { - //printf("decrypt pass.(%s) fname2.(%s) -> destfname.(%s)\n",pass,fname2,destfname); - //obj = jduplicate(jobj(retjson,"payload")); - //jdelete(retjson,"payload"); - //jadd(retjson,"result",obj); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"couldnt decrypt json file\"}")); -} - -THREE_STRINGS(SuperNET,encryptjson,password,permanentfile,payload) -{ - char destfname[4096],pass[8192],fname2[1023]; cJSON *argjson,*retjson = cJSON_CreateObject(); - safecopy(pass,password,sizeof(pass)); - safecopy(fname2,permanentfile,sizeof(fname2)); - argjson = jduplicate(json); - //printf("argjson.(%s)\n",jprint(argjson,0)); - jdelete(argjson,"agent"); - jdelete(argjson,"method"); - jdelete(argjson,"password"); - jdelete(argjson,"permanentfile"); - jdelete(argjson,"timestamp"); - jdelete(argjson,"tag"); - if ( _SuperNET_encryptjson(myinfo,destfname,pass,sizeof(pass),fname2,sizeof(fname2),argjson) == 0 ) - { - jaddstr(retjson,"result","success"); - jaddstr(retjson,"filename",destfname); - } else jaddstr(retjson,"error","couldnt encrypt json file"); - free_json(argjson); - return(jprint(retjson,1)); -} -#include "../includes/iguana_apiundefs.h" - diff --git a/iguana/dPoW.h b/iguana/dPoW.h index e6e8f9d80..b773104c8 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -23,7 +23,7 @@ //#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1) #define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries) #define DPOW_VERSION 0x0781 -#define DPOW_UTXOSIZE 10000 +#define DPOW_UTXOSIZE 50000 #define DPOW_MINOUTPUT 6000 #define DPOW_DURATION 600 #define DPOW_RATIFYDURATION (3600 * 24) @@ -167,6 +167,9 @@ char *dpow_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin); cJSON *dpow_kvupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *key,char *value,int32_t flags); cJSON *dpow_kvsearch(struct supernet_info *myinfo,struct iguana_info *coin,char *key); void init_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin); +cJSON *dpow_getmessage(struct supernet_info *myinfo,char *jsonstr); +cJSON *dpow_addmessage(struct supernet_info *myinfo,char *jsonstr); +cJSON *dpow_psock(struct supernet_info *myinfo,char *jsonstr); char *_dex_getinfo(struct supernet_info *myinfo,char *symbol); char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid); @@ -178,6 +181,7 @@ char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32 char *_dex_gettxin(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout); char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address); char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address); +char *_dex_getmessage(struct supernet_info *myinfo,char *jsonstr); char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address); char *_dex_listunspent2(struct supernet_info *myinfo,char *symbol,char *address); char *_dex_listspent(struct supernet_info *myinfo,char *symbol,char *address); @@ -189,6 +193,7 @@ int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol); char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol); char *_dex_kvupdate(struct supernet_info *myinfo,char *symbol,char *key,char *value,int32_t flags); char *_dex_kvsearch(struct supernet_info *myinfo,char *symbol,char *key); +char *_dex_psock(struct supernet_info *myinfo,char *jsonstr); 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); diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 4d563f9f1..18afb868b 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -126,8 +126,8 @@ int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct int32_t haveutxo,completed,minutxo,n; bits256 signedtxid; cJSON *addresses; char *rawtx,*sendtx; if ( strcmp("BTC",coin->symbol) == 0 ) { - minutxo = 499; - n = 50; + minutxo = 199; + n = 10; } else { diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 017d35973..cadc11faa 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -239,6 +239,105 @@ char *nanomsg_tcpname(struct supernet_info *myinfo,char *str,char *ipaddr,uint16 return(str); } +void dpow_psockloop(void *_ptr) +{ + int32_t i,nonz,size,sentbytes; uint32_t now; struct psock *ptr; void *buf; struct supernet_info *myinfo = _ptr; + while ( 1 ) + { + now = (uint32_t)time(NULL); + for (i=nonz=0; inumpsocks; i++) // change to nn_poll! + { + portable_mutex_lock(&myinfo->psockmutex); + if ( i < myinfo->numpsocks ) + { + ptr = &myinfo->PSOCKS[i]; + if ( (size= nn_recv(ptr->pullsock,&buf,NN_MSG,0)) > 0 ) + { + ptr->lasttime = now; + if ( (sentbytes= nn_send(ptr->pubsock,buf,size,0)) > 0 ) + { + //printf("PSOCKS[%d] of %d (%u %u) -> %d/%d bytes\n",i,myinfo->numpsocks,ptr->pushport,ptr->subport,size,sentbytes); + nonz++; + } + } + else if ( now > ptr->lasttime+PSOCK_IDLETIMEOUT ) + { + printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,myinfo->numpsocks,ptr->pushport,ptr->subport,now - ptr->lasttime); + nn_close(ptr->pullsock); + nn_close(ptr->pubsock); + if ( myinfo->numpsocks > 1 ) + { + myinfo->PSOCKS[i] = myinfo->PSOCKS[--myinfo->numpsocks]; + memset(&myinfo->PSOCKS[myinfo->numpsocks],0,sizeof(*ptr)); + } else myinfo->numpsocks = 0; + } + if ( buf != 0 ) + nn_freemsg(buf), buf = 0; + } + portable_mutex_unlock(&myinfo->psockmutex); + } + if ( nonz == 0 ) + usleep(100000); + } +} + +void dpow_psockadd(struct supernet_info *myinfo,int32_t pullsock,uint16_t pushport,int32_t pubsock,uint16_t subport) +{ + struct psock *ptr; + portable_mutex_lock(&myinfo->psockmutex); + myinfo->PSOCKS = realloc(myinfo->PSOCKS,sizeof(*myinfo->PSOCKS) * (myinfo->numpsocks + 1)); + ptr = &myinfo->PSOCKS[myinfo->numpsocks++]; + ptr->pullsock = pullsock; + ptr->pushport = pushport; + ptr->pubsock = pubsock; + ptr->subport = subport; + ptr->lasttime = (uint32_t)time(NULL); + portable_mutex_unlock(&myinfo->psockmutex); +} + +cJSON *dpow_psock(struct supernet_info *myinfo,char *jsonstr) +{ + char pushaddr[128],subaddr[128]; uint16_t i,pushport,subport; int32_t timeout,maxsize,pullsock=-1,pubsock=-1; cJSON *retjson=0; + retjson = cJSON_CreateObject(); + pushport = myinfo->psockport++; + subport = myinfo->psockport++; + for (i=0; i<100; i++) + { + pullsock = pubsock = -1; + nanomsg_tcpname(myinfo,pushaddr,myinfo->ipaddr,pushport), pushport += 2; + nanomsg_tcpname(myinfo,subaddr,myinfo->ipaddr,subport), subport += 2; + if ( (pullsock= nn_socket(AF_SP,NN_PULL)) >= 0 && (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) + { + if ( nn_bind(pullsock,pushaddr) >= 0 && nn_bind(pubsock,subaddr) >= 0 ) + { + timeout = 10; + nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + timeout = 1; + nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + timeout = 1; + maxsize = 1024 * 1024; + nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize)); + dpow_psockadd(myinfo,pullsock,pushport,pubsock,subport); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"pushaddr",pushaddr); + jaddstr(retjson,"subaddr",subaddr); + break; + } + if ( pullsock >= 0 ) + nn_close(pullsock); + if ( pubsock >= 0 ) + nn_close(pubsock); + } + if ( pushport < 1000 ) + pushport = 1001; + if ( subport < 1000 ) + subport = 1001; + } + if ( i == 100 ) + jaddstr(retjson,"error","cant find psock ports"); + return(retjson); +} + static int _increasing_ipbits(const void *a,const void *b) { #define uint32_a (*(uint32_t *)a) @@ -254,24 +353,24 @@ static int _increasing_ipbits(const void *a,const void *b) void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size) { - char *retstr; int32_t datalen; struct iguana_info *coin; struct dex_request dexreq; + char *retstr; int32_t datalen; struct dex_request dexreq; //struct iguana_info *coin; //for (i=0; ihandler,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 ) { + 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 ( (retstr= basilisk_respond_addmessage(myinfo,dexp->packet,BASILISK_KEYSIZE,&dexp->packet[BASILISK_KEYSIZE],dexp->datalen-BASILISK_KEYSIZE,0,BASILISK_DEXDURATION)) != 0 ) free(retstr); } else if ( strcmp(dexp->handler,"request") == 0 ) { datalen = dex_rwrequest(0,dexp->packet,&dexreq); - if ( myinfo->IAMNOTARY != 0 && dexreq.func == 'A' && (coin= iguana_coinfind(dexreq.name)) != 0 ) + /*if ( myinfo->IAMNOTARY != 0 && dexreq.func == 'A' && (coin= iguana_coinfind(dexreq.name)) != 0 ) { if ( (retstr= dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 ) free(retstr); printf("process broadcast importaddress.(%s) [%s]\n",(char *)&dexp->packet[datalen],dexreq.name); - } + }*/ } } @@ -287,17 +386,25 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32 { timeout = 1000; nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); - //timeout = 5000; + //timeout = 1500; //nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout)); - timeout = 1000; + timeout = 3000; nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + //prio = 1; + //nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDPRIO,&prio,sizeof(prio)); + //nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVPRIO,&prio,sizeof(prio)); for (i=0; idexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++) + { if ( nn_connect(reqsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddrs[i],REP_SOCK)) < 0 ) { nn_close(reqsock); reqsock = -1; break; } + } + //prio = 8; + //nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDPRIO,&prio,sizeof(prio)); + //nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVPRIO,&prio,sizeof(prio)); } if ( reqsock >= 0 ) { @@ -408,14 +515,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32 printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); } } -//#ifndef __APPLE__ +#ifndef __APPLE__ if ( (rand() % 100) < 40 ) { nanomsg_tcpname(0,str,ipaddr,REP_SOCK); nn_connect(myinfo->reqsock,str); printf("%d: req connect (%s)\n",myinfo->numdexipbits,str); } -//#endif +#endif } } if ( freeptr != 0 ) @@ -612,7 +719,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]); if ( retstr == 0 ) { - *broadcastflagp = 1; + //*broadcastflagp = 1; retstr = dpow_validateaddress(myinfo,coin,(char *)&dexp->packet[datalen]); } else @@ -636,6 +743,31 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d retstr = jprint(retjson,1); } } + else if ( dexreq.func == 'M' ) + { + if ( (retjson= dpow_getmessage(myinfo,(char *)&dexp->packet[datalen])) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + retstr = jprint(retjson,1); + } + } + else if ( dexreq.func == 'Z' ) + { + if ( (retjson= dpow_psock(myinfo,(char *)&dexp->packet[datalen])) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + retstr = jprint(retjson,1); + } + } + else if ( 0 && dexreq.func == 'a' ) + { + if ( (retjson= dpow_addmessage(myinfo,(char *)&dexp->packet[datalen])) != 0 ) + { + *broadcastflagp = 1; + dpow_randipbits(myinfo,coin,retjson); + retstr = jprint(retjson,1); + } + } else if ( dexreq.func == 'N' ) { uint8_t pubkeys[64][33]; char str[128]; int32_t numnotaries; cJSON *array,*item; @@ -985,6 +1117,35 @@ char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *addre return(_dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")); } +char *_dex_getmessage(struct supernet_info *myinfo,char *jsonstr) +{ + struct dex_request dexreq; + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,"KMD",sizeof(dexreq.name)); + dexreq.func = 'M'; + return(_dex_sendrequeststr(myinfo,&dexreq,jsonstr,0,1,"")); +} + +char *_dex_sendmessage(struct supernet_info *myinfo,char *jsonstr) +{ + struct dex_request dexreq; + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,"KMD",sizeof(dexreq.name)); + dexreq.func = 'a'; + return(_dex_sendrequeststr(myinfo,&dexreq,jsonstr,0,1,"")); +} + +char *_dex_psock(struct supernet_info *myinfo,char *jsonstr) +{ + struct dex_request dexreq; + if ( jsonstr == 0 ) + jsonstr = "{}"; + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,"KMD",sizeof(dexreq.name)); + dexreq.func = 'Z'; + return(_dex_sendrequeststr(myinfo,&dexreq,jsonstr,0,1,"")); +} + char *_dex_listunspentarg(struct supernet_info *myinfo,char *symbol,char *address,uint8_t arg) { struct dex_request dexreq; char *retstr; @@ -1077,7 +1238,7 @@ 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 firstz=-1; uint32_t crc32; + uint32_t crc32; //int32_t firstz=-1; if ( dexp->version0 == (DEX_VERSION & 0xff) && dexp->version1 == ((DEX_VERSION >> 8) & 0xff) ) { if ( dexp->datalen == (size - sizeof(*dexp)) ) @@ -1085,7 +1246,7 @@ int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp 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 ) return(0); - else printf("dexp %08x != %08x || firstz.%d < 0\n",dexp->crc32,crc32,firstz); + //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); @@ -1094,6 +1255,7 @@ int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp int32_t dex_subsock_poll(struct supernet_info *myinfo) { int32_t size= -1; struct dex_nanomsghdr *dexp; void *freeptr; + return(0); //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 ) { @@ -1962,7 +2124,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { //printf("FROM BUS.%08x -> pub\n",dexp->crc32); - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); + //signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); dex_packet(myinfo,dexp,size); } //printf("GOT DEX bus PACKET.%d\n",size); @@ -1984,8 +2146,9 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) free(retstr); if ( broadcastflag != 0 ) { - //printf("BROADCAST dexp request.[%d]\n",size); + printf("BROADCAST dexp request.[%d]\n",size); signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); + //signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); } } else @@ -1999,10 +2162,10 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); + //signed_nn_send(myinfo,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)); dex_packet(myinfo,dexp,size); - } else printf("failed dexpacketcheck\n"); + } //else printf("failed dexpacketcheck\n"); } //printf("GOT DEX rep PACKET.%d\n",size); //if ( freeptr != 0 ) diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 4f344119c..f8ffded08 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -36,6 +36,16 @@ cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin) { json = cJSON_Parse(retstr); free(retstr); + if ( strcmp(coin->symbol,"BTC") == 0 ) + { + sprintf(buf,"[%d]",2); + if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"estimatefee",buf)) != 0 ) + { + if ( atof(retstr) > SMALLVAL ) + jaddnum(json,"estimatefee",atof(retstr)); + free(retstr); + } + } } return(json); } diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 194285053..fac9033af 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -224,7 +224,7 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in } printf("numvouts.%d len.%d RATIFY vouts\n",numvouts,len); } - if ( (src_or_dest == 0 || strcmp(bp->destcoin->symbol,"BTC") != 0) && (n= dpow_paxpending(extras,&paxwdcrc)) > 0 ) + if ( 0 && (src_or_dest == 0 || strcmp(bp->destcoin->symbol,"BTC") != 0) && (n= dpow_paxpending(extras,&paxwdcrc)) > 0 ) { for (i=0; i= 4 ) { // validate with trailing hash, then remove hash + if ( len < 38 ) + len = 38; hash = bits256_doublesha256(0,buf,len - 4); *addrtypep = *buf; memcpy(privkeyp,buf+1,32); - if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] &&(buf[len - 1]&0xff) == hash.bytes[28] ) + if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] && (buf[len - 1]&0xff) == hash.bytes[28] ) { - //printf("coinaddr.(%s) valid checksum\n",coinaddr); + //int32_t i; for (i=0; i #include #include "OS_portable.h" +#define MAX(a,b) ((a) > (b) ? (a) : (b)) struct mmpending_order { @@ -501,15 +502,16 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double jaddnum(vals,"ask",ask); vol = bidvol > askvol ? askvol : bidvol; jaddnum(vals,"maxvol",vol); - jaddnum(vals,"minvol",vol * 0.1); + jaddnum(vals,"minvol",vol*0.1 > 100 ? 100 : vol * 0.1); sprintf(url,"%s/?",IGUANA_URL); sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}",base,jprint(vals,1)); + printf("(%s)\n",postdata); if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 ) { //printf("(%s) -> (%s)\n",postdata,retstr); free(retstr); } - spread_ratio = (ask - bid) / (bid + ask); + spread_ratio = .5 * ((ask - bid) / (bid + ask)); for (i=0; i SMALLVAL ) @@ -519,7 +521,7 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double jaddnum(vals,"bid",PAXPRICES[i] * (1. - spread_ratio)); jaddnum(vals,"ask",PAXPRICES[i] * (1. + spread_ratio)); jaddnum(vals,"maxvol",vol * PAXPRICES[i]); - jaddnum(vals,"minvol",vol * 0.1 * PAXPRICES[i]); + jaddnum(vals,"minvol",MAX(1,(int32_t)(vol * 0.01 * PAXPRICES[i]))); sprintf(url,"%s/?",IGUANA_URL); sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}","KMD",jprint(vals,1)); if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 ) @@ -528,6 +530,7 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double free(retstr); } } +break; } } else printf("unsupported ask only for DEX %s/%s\n",base,rel); } @@ -561,7 +564,7 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double start_BASE,double start_REL,double profitmargin,double maxexposure,double ratioincr,char *exchange,char *name,char *base,char *rel) { static uint32_t counter; - cJSON *fiatjson; double start_DEXbase,start_DEXrel,USD_average=0.,DEX_base = 0.,DEX_rel = 0.,balance_base=0.,balance_rel=0.,mmbid,mmask,usdprice=0.,CMC_average=0.,aveprice,incr,pendingbids,pendingasks,buyvol,sellvol,bidincr,askincr,filledprice,avebid=0.,aveask=0.,val,changes[3],highbid=0.,lowask=0.,theoretical = 0.; uint32_t lasttime = 0; + cJSON *fiatjson; double bid,ask,start_DEXbase,start_DEXrel,USD_average=0.,DEX_base = 0.,DEX_rel = 0.,balance_base=0.,balance_rel=0.,mmbid,mmask,usdprice=0.,CMC_average=0.,aveprice,incr,pendingbids,pendingasks,buyvol,sellvol,bidincr,askincr,filledprice,avebid=0.,aveask=0.,val,changes[3],highbid=0.,lowask=0.,theoretical = 0.; uint32_t lasttime = 0; incr = maxexposure * ratioincr; buyvol = sellvol = 0.; start_DEXbase = dex_balance(base,baseaddr); @@ -636,8 +639,11 @@ void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double mmask = 0.; } marketmaker_volumeset(&bidincr,&askincr,incr,buyvol,pendingbids,sellvol,pendingasks,maxexposure); - printf("AVE.(%.8f %.8f) hbla %.8f %.8f bid %.8f ask %.8f theory %.8f buys.(%.6f %.6f) sells.(%.6f %.6f) incr.(%.6f %.6f) balances.(%.8f + %.8f, %.8f + %.8f)\n",avebid,aveask,highbid,lowask,mmbid,mmask,theoretical,buyvol,pendingbids,sellvol,pendingasks,bidincr,askincr,balance_base,DEX_base,balance_rel,DEX_rel); - marketmaker_spread("DEX",base,rel,avebid - profitmargin*aveprice,incr,aveask + profitmargin*aveprice,incr,profitmargin*aveprice*0.5); + printf("AVE.(%.8f %.8f) hbla %.8f %.8f bid %.8f ask %.8f theory %.8f buys.(%.6f %.6f) sells.(%.6f %.6f) incr.(%.6f %.6f) balances.(%.8f + %.8f, %.8f + %.8f) test %f\n",avebid,aveask,highbid,lowask,mmbid,mmask,theoretical,buyvol,pendingbids,sellvol,pendingasks,bidincr,askincr,balance_base,DEX_base,balance_rel,DEX_rel,(aveask - avebid)/aveprice); + if ( (aveask - avebid)/aveprice > 4*profitmargin ) + bid = highbid * (1 - 4*profitmargin), ask = lowask * (1 + 4*profitmargin); + else bid = avebid - profitmargin*aveprice, ask = avebid + profitmargin*aveprice; + marketmaker_spread("DEX",base,rel,bid,incr,ask,incr,profitmargin*aveprice*0.5); if ( (pendingbids + buyvol) > (pendingasks + sellvol) ) { bidincr *= (double)(pendingasks + sellvol) / ((pendingbids + buyvol) + (pendingasks + sellvol)); @@ -655,8 +661,8 @@ void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double askincr = (int32_t)askincr + 0.777; } //printf("mmbid %.8f %.6f, mmask %.8f %.6f\n",mmbid,bidincr,mmask,askincr); - marketmaker_spread(exchange,base,rel,mmbid,bidincr,mmask,askincr,profitmargin*aveprice*0.5); - sleep(60); + //marketmaker_spread(exchange,base,rel,mmbid,bidincr,mmask,askincr,profitmargin*aveprice*0.5); + sleep(6000); } } } @@ -707,7 +713,7 @@ int main(int argc, const char * argv[]) marketmaker(minask,maxbid,baseaddr,reladdr,start_base,start_rel,profitmargin,maxexposure,incrratio,exchange,name,base,rel); } free_json(addrjson); - } + } else printf("ERROR parsing.(%s)\n",retstr); free(retstr); } free_json(retjson); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 29fa7195c..682d3da13 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -21,13 +21,17 @@ #define iguana777_net_h #if defined(_WIN32) || defined(_WIN64) +#ifndef WIN32 #define WIN32 #endif +#endif #if (defined(_WIN32) || defined(__WIN32__)) && \ !defined(WIN32) && !defined(__SYMBIAN32__) +#ifndef WIN32 #define WIN32 #endif +#endif #ifdef WIN32 #define __MINGW @@ -59,12 +63,14 @@ #include "../crypto777/nanosrc/nn.h" #include "../crypto777/nanosrc/bus.h" #include "../crypto777/nanosrc/pubsub.h" +#include "../crypto777/nanosrc/pipeline.h" #include "../crypto777/nanosrc/reqrep.h" #include "../crypto777/nanosrc/tcp.h" #else #include "/usr/local/include/nanomsg/nn.h" #include "/usr/local/include/nanomsg/bus.h" #include "/usr/local/include/nanomsg/pubsub.h" +#include "/usr/local/include/nanomsg/pipeline.h" #include "/usr/local/include/nanomsg/reqrep.h" #include "/usr/local/include/nanomsg/tcp.h" #endif @@ -88,8 +94,26 @@ struct supernet_address char NXTADDR[32],BTC[64],BTCD[64]; }; +struct smartaddress +{ + bits256 privkey,pubkey; + uint8_t pubkey33[33],rmd160[20]; +}; + struct pending_trade { UT_hash_handle hh; double basevolume,relvolume,dir; char base[32],rel[32]; }; +#define PSOCK_IDLETIMEOUT 600 +struct psock { uint32_t lasttime; int32_t pullsock,pubsock; uint16_t pushport,subport; }; + +#define JUMBLR_DEPOSITPREFIX "deposit " +struct jumblr_item +{ + UT_hash_handle hh; + int64_t amount,fee,txfee; + uint32_t spent,pad; + char opid[64],src[128],dest[128],status; +}; + struct liquidity_info { char base[16],rel[16],exchange[16]; @@ -102,9 +126,9 @@ struct message_info { int32_t msgcount; bits256 refhash,msghashes[64]; uint32_t struct supernet_info { struct supernet_address myaddr; - bits256 persistent_priv,privkey; + bits256 persistent_priv,privkey,jumblr_pubkey,jumblr_depositkey; uint8_t persistent_pubkey33[33]; - char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024]; + char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024],jumblr_passphrase[1024]; char *decryptstr; 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); @@ -112,6 +136,7 @@ struct supernet_info uint32_t expiration,dirty,DEXactive,DEXpoll,totalcoins,nanoinit,lastdexrequestid,dexcrcs[1024]; uint16_t argport,rpcport; struct basilisk_info basilisks; + struct jumblr_item *jumblrs; struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges; struct iguana_waccount *wallet; struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts; @@ -139,7 +164,33 @@ struct supernet_info uint8_t logs[256],exps[510]; struct message_info msgids[8192]; double *svmfeatures; + uint16_t psockport,numpsocks; struct psock *PSOCKS; portable_mutex_t psockmutex; uint8_t notaries[64][33]; int32_t numnotaries,DEXEXPLORER; + FILE *swapsfp; + struct smartaddress smartaddrs[64]; int32_t numsmartaddrs,cancelrefresh; +}; + +struct basilisk_swapmessage +{ + bits256 srchash,desthash; + uint32_t crc32,msgbits,quoteid,datalen; + uint8_t *data; +}; + +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; uint32_t lasttime; + FILE *fp; + bits256 persistent_privkey,persistent_pubkey; + struct basilisk_swapinfo I; + struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim; + bits256 privkeys[INSTANTDEX_DECKSIZE]; + struct basilisk_swapmessage *messages; int32_t nummessages; + uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; + uint8_t persistent_pubkey33[33],pad[15],verifybuf[65536]; + }; #include "../includes/iguana_funcs.h" diff --git a/iguana/iguana_bitmap.c b/iguana/iguana_bitmap.c index ec1ce5484..89effe210 100755 --- a/iguana/iguana_bitmap.c +++ b/iguana/iguana_bitmap.c @@ -1162,42 +1162,3 @@ void iguana_bitmap(char *space,int32_t max,char *name) } } -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -STRING_AND_TWOINTS(mouse,change,name,x,y) -{ - printf("mouse (%s) x.%d y.%d\n",name,x,y); - return(clonestr("{\"result\":\"changed\"}")); -} - -STRING_ARG(mouse,leave,name) -{ - printf("mouse (%s) leave\n",name); - return(clonestr("{\"result\":\"left\"}")); -} - -STRING_AND_TWOINTS(mouse,click,name,x,y) -{ - printf("mouse (%s) x.%d y.%d click\n",name,x,y); - return(clonestr("{\"result\":\"click\"}")); -} - -STRING_AND_INT(keyboard,key,name,c) -{ - printf(" KEY.(%s) c.%d (%c)\n",name,c,c); - return(clonestr("{\"result\":\"key\"}")); -} - -STRING_AND_TWOINTS(mouse,image,name,x,y) -{ - printf("mouse CREATE (%s) x.%d y.%d\n",name,x,y); - return(clonestr("{\"result\":\"opened\"}")); -} - -STRING_ARG(mouse,close,name) -{ - printf("mouse CLOSE (%s)\n",name); - return(clonestr("{\"result\":\"closed\"}")); -} -#include "../includes/iguana_apiundefs.h" diff --git a/iguana/iguana_chains.c b/iguana/iguana_chains.c index 87a8ce798..4fc5a0b76 100755 --- a/iguana/iguana_chains.c +++ b/iguana/iguana_chains.c @@ -232,7 +232,12 @@ void set_coinconfname(char *fname,char *coinstr,char *userhome,char *coindir,cha sprintf(confname,"%s.conf",buf); } printf("userhome.(%s) coindir.(%s) confname.(%s)\n",userhome,coindir,confname); - sprintf(fname,"%s/%s/%s",userhome,coindir,confname); +#ifdef WIN32 + if ( userhome == 0 || userhome[0] == 0 ) + sprintf(fname,"%s/%s",coindir,confname); + else +#endif + sprintf(fname,"%s/%s/%s",userhome,coindir,confname); } uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *userhome,char *coindir,char *confname) @@ -486,7 +491,7 @@ void iguana_chaininit(struct supernet_info *myinfo,struct iguana_chain *chain,in if ( strcmp(chain->symbol,"BTC") == 0 ) { chain->unitval = 0x1d; - chain->txfee = 10000; + chain->txfee = 50000; chain->havecltv = 1; } else chain->txfee = 10000; diff --git a/iguana/iguana_exchanges.c b/iguana/iguana_exchanges.c index 8be8d38c3..d7445f681 100755 --- a/iguana/iguana_exchanges.c +++ b/iguana/iguana_exchanges.c @@ -1176,6 +1176,7 @@ cJSON *iguana_pricesarray(struct supernet_info *myinfo,char *exchange,char *base #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" +#include "../includes/iguana_apideclares2.h" THREE_STRINGS_AND_THREE_INTS(InstantDEX,orderbook,exchange,base,rel,depth,allfields,ignore) { diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index e7febc655..7e38b1ad7 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -191,7 +191,10 @@ cJSON *SuperNET_helpjson() #include "../includes/iguana_apideclares.h" +#undef IGUANA_ARGS +#undef _IGUANA_APIDEC_H_ #include "../includes/iguana_apiundefs.h" + if ( array != 0 ) jadd(json,"API",array); jadd(json,"agents",agents); @@ -493,421 +496,13 @@ char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr) return(OS_filestr(&filesize,"index7778.html")); } -cJSON *iguana_peerjson(struct iguana_info *coin,struct iguana_peer *addr) -{ - cJSON *array,*json = cJSON_CreateObject(); - jaddstr(json,"ipaddr",addr->ipaddr); - if ( addr->supernet != 0 ) - jaddstr(json,"ipaddr",addr->ipaddr); - jaddstr(json,"supernet","yes"); - jaddnum(json,"protover",addr->protover); - jaddnum(json,"relay",addr->relayflag); - jaddnum(json,"height",addr->height); - jaddnum(json,"rank",addr->rank); - jaddnum(json,"usock",addr->usock); - if ( addr->dead != 0 ) - jaddnum(json,"dead",addr->dead); - jaddnum(json,"ready",addr->ready); - jaddnum(json,"recvblocks",addr->recvblocks); - jaddnum(json,"recvtotal",addr->recvtotal); - jaddnum(json,"lastcontact",addr->lastcontact); - if ( addr->numpings > 0 ) - jaddnum(json,"aveping",addr->pingsum/addr->numpings); - array = cJSON_CreateObject(); - jaddnum(array,"version",addr->msgcounts.version); - jaddnum(array,"verack",addr->msgcounts.verack); - jaddnum(array,"getaddr",addr->msgcounts.getaddr); - jaddnum(array,"addr",addr->msgcounts.addr); - jaddnum(array,"inv",addr->msgcounts.inv); - jaddnum(array,"getdata",addr->msgcounts.getdata); - jaddnum(array,"notfound",addr->msgcounts.notfound); - jaddnum(array,"getblocks",addr->msgcounts.getblocks); - jaddnum(array,"getheaders",addr->msgcounts.getheaders); - jaddnum(array,"headers",addr->msgcounts.headers); - jaddnum(array,"tx",addr->msgcounts.tx); - jaddnum(array,"block",addr->msgcounts.block); - jaddnum(array,"mempool",addr->msgcounts.mempool); - jaddnum(array,"ping",addr->msgcounts.ping); - jaddnum(array,"pong",addr->msgcounts.pong); - jaddnum(array,"reject",addr->msgcounts.reject); - jaddnum(array,"filterload",addr->msgcounts.filterload); - jaddnum(array,"filteradd",addr->msgcounts.filteradd); - jaddnum(array,"filterclear",addr->msgcounts.filterclear); - jaddnum(array,"merkleblock",addr->msgcounts.merkleblock); - jaddnum(array,"alert",addr->msgcounts.alert); - jadd(json,"msgcounts",array); - return(json); -} - -cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly) -{ - cJSON *retjson,*array; int32_t i; struct iguana_peer *addr; - if ( coin == 0 || coin->peers == 0 ) - return(0); - array = cJSON_CreateArray(); - for (i=0; iMAXPEERS; i++) - { - addr = &coin->peers->active[i]; - if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 ) - { - if ( addronly != 0 ) - jaddistr(array,addr->ipaddr); - else jaddi(array,iguana_peerjson(coin,addr)); - } - } - if ( addronly == 0 ) - { - retjson = cJSON_CreateObject(); - jadd(retjson,"peers",array); - jaddnum(retjson,"maxpeers",coin->MAXPEERS); - jaddstr(retjson,"coin",coin->symbol); - return(retjson); - } - else return(array); -} - -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -STRING_ARG(iguana,peers,activecoin) -{ - if ( coin != 0 ) - return(jprint(iguana_peersjson(coin,0),1)); - else return(clonestr("{\"error\":\"peers needs coin\"}")); -} - -STRING_ARG(iguana,getconnectioncount,activecoin) -{ - int32_t i,num = 0; char buf[512]; - if ( coin != 0 && coin->peers != 0 ) - { - for (i=0; ipeers->active)/sizeof(*coin->peers->active); i++) - if ( coin->peers->active[i].usock >= 0 ) - num++; - sprintf(buf,"{\"result\":\"%d\"}",num); - return(clonestr(buf)); - } else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}")); -} - -ZERO_ARGS(bitcoinrpc,getdifficulty) -{ - char buf[512]; - if ( coin != 0 ) - { - sprintf(buf,"{\"result\":\"success\",\"proof-of-work\":\"%.8f\",\"search-interval\": 0}",PoW_from_compact(coin->blocks.hwmchain.RO.bits,coin->chain->unitval)); - return(clonestr(buf)); - } else return(clonestr("{\"error\":\"getdifficulty needs coin\"}")); -} - -STRING_ARG(iguana,addcoin,newcoin) -{ - char *symbol,*seedip; int32_t retval; - if ( (symbol= newcoin) == 0 && coin != 0 ) - symbol = coin->symbol; - if ( symbol != 0 ) - { - if ( (seedip= jstr(json,"seedipaddr")) != 0 ) - safecopy(myinfo->seedipaddr,seedip,sizeof(myinfo->seedipaddr)); - printf(">> addcoin.%s seedipaddr.%s\n",symbol,myinfo->seedipaddr); -#ifdef __PNACL__ -// if ( strcmp(symbol,"BTC") == 0 ) -// return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}")); +#ifdef WIN32 +/** +* workaround for MSVS compiler bug - +* instead of going on if-else-if block split the if-else-if into two function +*/ +char *SuperNET_parser2(struct supernet_info *myinfo, char *agentstr, char *method, cJSON *json, char *remoteaddr); #endif - if ( (retval= iguana_launchcoin(myinfo,symbol,json,0)) > 0 ) - { - if ( myinfo->rpcsymbol[0] == 0 ) - safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol)); - return(clonestr("{\"result\":\"coin added\"}")); - } - else if ( retval == 0 ) - return(clonestr("{\"result\":\"coin already there\"}")); - else return(clonestr("{\"error\":\"error adding coin\"}")); - } else return(clonestr("{\"error\":\"addcoin needs newcoin\"}")); -} - -STRING_ARG(iguana,startcoin,activecoin) -{ - if ( coin != 0 ) - { - coin->active = 1; - return(clonestr("{\"result\":\"coin started\"}")); - } else return(clonestr("{\"error\":\"startcoin needs coin\"}")); -} - -STRING_ARG(iguana,stopcoin,activecoin) -{ - if ( activecoin[0] != 0 ) - coin = iguana_coinfind(activecoin); - if ( coin != 0 ) - { - coin->active = 0; - //iguana_coinpurge(coin); - return(clonestr("{\"result\":\"coin stopped\"}")); - } else return(clonestr("{\"error\":\"stopcoin needs coin\"}")); -} - -STRING_ARG(iguana,pausecoin,activecoin) -{ - if ( coin != 0 ) - { - coin->active = 0; - return(clonestr("{\"result\":\"coin paused\"}")); - } else return(clonestr("{\"error\":\"pausecoin needs coin\"}")); -} - -TWO_STRINGS(iguana,addnode,activecoin,ipaddr) -{ - struct iguana_peer *addr; int32_t i,n; - if ( coin == 0 ) - coin = iguana_coinfind(activecoin); - if ( coin != 0 && strcmp(coin->symbol,"RELAY") == 0 ) - basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddr),GENESIS_PUBKEY); - printf("coin.%p.[%s] addnode.%s -> %s\n",coin,coin!=0?coin->symbol:"",activecoin,ipaddr); - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 && is_ipaddr(ipaddr) != 0 ) - { - //iguana_possible_peer(coin,ipaddr); - if ( (addr= iguana_peerslot(coin,(uint32_t)calc_ipbits(ipaddr),1)) != 0 ) - { - addr->supernet = 1; - if ( addr->usock >= 0 ) - { - if ( (n= coin->peers->numranked) != 0 ) - { - for (i=0; ipeers->ranked[i] ) - break; - } - if ( i == n ) - { - if ( i == IGUANA_MAXPEERS ) - i--; - else coin->peers->numranked = n+1; - coin->peers->ranked[i] = addr; - addr->recvblocks = coin->peers->ranked[0]->recvblocks + 100; - addr->recvtotal = coin->peers->ranked[0]->recvtotal*1.1 + 100; - printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers->numranked); - } else printf("(%s) is already peer.%d\n",ipaddr,i); - } - return(clonestr("{\"result\":\"peer was already connected\"}")); - } - if ( addr->pending == 0 ) - { - addr->pending = (uint32_t)time(NULL); - iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); - return(clonestr("{\"result\":\"addnode submitted\"}")); - } else return(clonestr("{\"result\":\"addnode connection was already pending\"}")); - } else return(clonestr("{\"result\":\"addnode cant find peer slot\"}")); - } - else if ( coin == 0 ) - return(clonestr("{\"error\":\"addnode needs active coin, do an addcoin first\"}")); - else return(clonestr("{\"error\":\"addnode needs ipaddr\"}")); -} - -TWO_STRINGS(iguana,persistent,activecoin,ipaddr) -{ - int32_t i; - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) - { - for (i=0; ipeers->active[i].ipaddr,ipaddr) == 0 ) - { - coin->peers->active[i].persistent_peer = juint(json,"interval")+3; - return(clonestr("{\"result\":\"node marked as persistent\"}")); - } - } - return(clonestr("{\"result\":\"node wasnt active\"}")); - } else return(clonestr("{\"error\":\"persistent needs coin and ipaddr\"}")); -} - -TWO_STRINGS(iguana,removenode,activecoin,ipaddr) -{ - int32_t i; - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) - { - for (i=0; ipeers->active[i].ipaddr,ipaddr) == 0 ) - { - coin->peers->active[i].rank = 0; - coin->peers->active[i].dead = (uint32_t)time(NULL); - return(clonestr("{\"result\":\"node marked as dead\"}")); - } - } - return(clonestr("{\"result\":\"node wasnt active\"}")); - } else return(clonestr("{\"error\":\"removenode needs coin and ipaddr\"}")); -} - -TWO_STRINGS(iguana,oneshot,activecoin,ipaddr) -{ - if ( coin != 0 && ipaddr != 0 ) - { - iguana_possible_peer(coin,ipaddr); - return(clonestr("{\"result\":\"addnode submitted\"}")); - } else return(clonestr("{\"error\":\"addnode needs coin and ipaddr\"}")); -} - -TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr) -{ - int32_t i; struct iguana_peer *addr; - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) - { - for (i=0; iMAXPEERS; i++) - { - addr = &coin->peers->active[i]; - if ( strcmp(addr->ipaddr,ipaddr) == 0 ) - return(jprint(iguana_peerjson(coin,addr),1)); - } - return(clonestr("{\"result\":\"nodestatus couldnt find ipaddr\"}")); - } else return(clonestr("{\"error\":\"nodestatus needs ipaddr\"}")); -} - -STRING_AND_INT(iguana,maxpeers,activecoin,max) -{ - cJSON *retjson; int32_t i; struct iguana_peer *addr; - if ( coin != 0 && coin->peers != 0 ) - { - retjson = cJSON_CreateObject(); - if ( max > IGUANA_MAXPEERS ) - max = IGUANA_MAXPEERS; - if ( max > coin->MAXPEERS ) - { - for (i=max; iMAXPEERS; i++) - if ( (addr= coin->peers->ranked[i]) != 0 ) - addr->dead = 1; - } - coin->MAXPEERS = max; - jaddnum(retjson,"maxpeers",coin->MAXPEERS); - jaddstr(retjson,"coin",coin->symbol); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"maxpeers needs coin\"}")); -} - -char *hmac_dispatch(char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message),char *name,char *message,char *password) -{ - char hexstr[1025]; cJSON *json; - if ( message != 0 && password != 0 && message[0] != 0 && password[0] != 0 ) - { - memset(hexstr,0,sizeof(hexstr)); - (*hmacfunc)(hexstr,password,password==0?0:(int32_t)strlen(password),message); - json = cJSON_CreateObject(); - jaddstr(json,"result","hmac calculated"); - jaddstr(json,"message",message); - jaddstr(json,name,hexstr); - return(jprint(json,1)); - } else return(clonestr("{\"error\":\"hmac needs message and passphrase\"}")); -} - -char *hash_dispatch(void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len),char *name,char *message) -{ - char hexstr[65537]; uint8_t databuf[32768]; cJSON *json; - if ( message != 0 && message[0] != 0 ) - { - memset(hexstr,0,sizeof(hexstr)); - (*hashfunc)(hexstr,databuf,(uint8_t *)message,(int32_t)strlen(message)); - json = cJSON_CreateObject(); - jaddstr(json,"result","hash calculated"); - jaddstr(json,"message",message); - jaddstr(json,name,hexstr); - return(jprint(json,1)); - } else return(clonestr("{\"error\":\"hash needs message\"}")); -} - -TWO_HASHES(hash,curve25519_pair,element,scalar) -{ - cJSON *retjson = cJSON_CreateObject(); - jaddbits256(retjson,"result",curve25519(element,scalar)); - return(jprint(retjson,1)); -} - -STRING_ARG(hash,NXT,passphrase) { return(hash_dispatch(calc_NXTaddr,"NXT",passphrase)); } -STRING_ARG(hash,curve25519,pubkey) { return(hash_dispatch(calc_curve25519_str,"curve25519",pubkey)); } -STRING_ARG(hash,crc32,message) { return(hash_dispatch(calc_crc32str,"crc32",message)); } -STRING_ARG(hash,base64_encode,message) { return(hash_dispatch(calc_base64_encodestr,"base64_encode",message)); } -STRING_ARG(hash,base64_decode,message) { return(hash_dispatch(calc_base64_decodestr,"base64_decode",message)); } -STRING_ARG(hash,rmd160_sha256,message) { return(hash_dispatch(rmd160ofsha256,"rmd160_sha256",message)); } -STRING_ARG(hash,sha256_sha256,message) { return(hash_dispatch(sha256_sha256,"sha256_sha256",message)); } -STRING_ARG(hash,hex,message) { return(hash_dispatch(calc_hexstr,"hex",message)); } -STRING_ARG(hash,unhex,message) { return(hash_dispatch(calc_unhexstr,"unhex",message)); } - -STRING_ARG(hash,sha224,message) { return(hash_dispatch(calc_sha224,"sha224",message)); } -STRING_ARG(hash,sha256,message) { return(hash_dispatch(vcalc_sha256,"sha256",message)); } -STRING_ARG(hash,sha384,message) { return(hash_dispatch(calc_sha384,"sha384",message)); } -STRING_ARG(hash,sha512,message) { return(hash_dispatch(calc_sha512,"sha512",message)); } -STRING_ARG(hash,rmd128,message) { return(hash_dispatch(calc_rmd128,"rmd128",message)); } -STRING_ARG(hash,rmd160,message) { return(hash_dispatch(calc_rmd160,"rmd160",message)); } -STRING_ARG(hash,rmd256,message) { return(hash_dispatch(calc_rmd256,"rmd256",message)); } -STRING_ARG(hash,rmd320,message) { return(hash_dispatch(calc_rmd320,"rmd320",message)); } -STRING_ARG(hash,sha1,message) { return(hash_dispatch(calc_sha1,"sha1",message)); } -STRING_ARG(hash,md2,message) { return(hash_dispatch(calc_md2str,"md2",message)); } -STRING_ARG(hash,md4,message) { return(hash_dispatch(calc_md4str,"md4",message)); } -STRING_ARG(hash,md5,message) { return(hash_dispatch(calc_md5str,"md5",message)); } -STRING_ARG(hash,tiger192_3,message) { return(hash_dispatch(calc_tiger,"tiger",message)); } -STRING_ARG(hash,whirlpool,message) { return(hash_dispatch(calc_whirlpool,"whirlpool",message)); } -TWO_STRINGS(hmac,sha224,message,passphrase) { return(hmac_dispatch(hmac_sha224_str,"sha224",message,passphrase)); } -TWO_STRINGS(hmac,sha256,message,passphrase) { return(hmac_dispatch(hmac_sha256_str,"sha256",message,passphrase)); } -TWO_STRINGS(hmac,sha384,message,passphrase) { return(hmac_dispatch(hmac_sha384_str,"sha384",message,passphrase)); } -TWO_STRINGS(hmac,sha512,message,passphrase) { return(hmac_dispatch(hmac_sha512_str,"sha512",message,passphrase)); } -TWO_STRINGS(hmac,rmd128,message,passphrase) { return(hmac_dispatch(hmac_rmd128_str,"rmd128",message,passphrase)); } -TWO_STRINGS(hmac,rmd160,message,passphrase) { return(hmac_dispatch(hmac_rmd160_str,"rmd160",message,passphrase)); } -TWO_STRINGS(hmac,rmd256,message,passphrase) { return(hmac_dispatch(hmac_rmd256_str,"rmd256",message,passphrase)); } -TWO_STRINGS(hmac,rmd320,message,passphrase) { return(hmac_dispatch(hmac_rmd320_str,"rmd320",message,passphrase)); } -TWO_STRINGS(hmac,sha1,message,passphrase) { return(hmac_dispatch(hmac_sha1_str,"sha1",message,passphrase)); } -TWO_STRINGS(hmac,md2,message,passphrase) { return(hmac_dispatch(hmac_md2_str,"md2",message,passphrase)); } -TWO_STRINGS(hmac,md4,message,passphrase) { return(hmac_dispatch(hmac_md4_str,"md4",message,passphrase)); } -TWO_STRINGS(hmac,md5,message,passphrase) { return(hmac_dispatch(hmac_md5_str,"md5",message,passphrase)); } -TWO_STRINGS(hmac,tiger192_3,message,passphrase) { return(hmac_dispatch(hmac_tiger_str,"tiger",message,passphrase)); } -TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirlpool_str,"whirlpool",message,passphrase)); } - -STRING_ARG(SuperNET,bitcoinrpc,setcoin) -{ - char buf[1024]; - if ( setcoin != 0 && setcoin[0] != 0 ) - { - strcpy(myinfo->rpcsymbol,setcoin); - touppercase(myinfo->rpcsymbol); - printf("bitcoinrpc.%s\n",myinfo->rpcsymbol); - if ( iguana_launchcoin(myinfo,myinfo->rpcsymbol,json,0) < 0 ) - return(clonestr("{\"error\":\"error creating coin\"}")); - else - { - sprintf(buf,"{\"result\":\"success\",\"setcoin\":\"%s\"}",setcoin); - return(clonestr(buf)); - } - } else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}")); -} - -ZERO_ARGS(SuperNET,help) -{ - cJSON *helpjson,*retjson; - if ( (helpjson= SuperNET_helpjson()) != 0 ) - { - retjson = cJSON_CreateObject(); - jadd(retjson,"result",helpjson); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"cant get helpjson\"}")); -} - -TWO_STRINGS(SuperNET,html,agentform,htmlfile) -{ - char *htmlstr; cJSON *retjson; int32_t max = 4*1024*1024; - if ( htmlfile == 0 || htmlfile[0] == 0 ) - htmlfile = "forms.html"; - //if ( (fp= fopen(htmlfile,"w")) == 0 ) - // printf("error opening htmlfile.(%s)\n",htmlfile); - htmlstr = malloc(max); - htmlstr = SuperNET_htmlstr(htmlfile,htmlstr,max,agentform); - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result",htmlstr); - free(htmlstr); - //if ( fp != 0 ) - // fclose(fp); - return(jprint(retjson,1)); -} - -#undef IGUANA_ARGS -#include "../includes/iguana_apiundefs.h" char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,cJSON *json,char *remoteaddr) { @@ -1025,12 +620,31 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c #define STRING_ARRAY_OBJ_STRING IGUANA_DISPATCH_SAOS #include "../includes/iguana_apideclares.h" -//#undef IGUANA_ARGS - +#ifdef WIN32 +return SuperNET_parser2(myinfo, agentstr, method, json, remoteaddr); +#else +#undef IGUANA_ARGS +#undef _IGUANA_APIDEC_H_ #include "../includes/iguana_apiundefs.h" char errstr[512]; sprintf(errstr,"{\"error\":\"unsupported call\",\"agent\":\"%s\",\"method\":\"%s\"}",agentstr,method); return(clonestr(errstr)); +#endif } +#ifdef WIN32 +char *SuperNET_parser2(struct supernet_info *myinfo, char *agentstr, char *method, cJSON *json, char *remoteaddr) { + char *coinstr; struct iguana_info *coin = 0; + if (remoteaddr != 0 && (remoteaddr[0] == 0 || strcmp(remoteaddr, "127.0.0.1") == 0)) + remoteaddr = 0; +#include "../includes/iguana_apideclares2.h" +#undef IGUANA_ARGS +#undef _IGUANA_APIDEC_H_ +#include "../includes/iguana_apiundefs.h" + char errstr[512]; + sprintf(errstr, "{\"error\":\"unsupported call\",\"agent\":\"%s\",\"method\":\"%s\"}", agentstr, method); + return(clonestr(errstr)); +} + +#endif diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index c9532e3c0..dc4d436d8 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -224,6 +224,7 @@ void dpow_addresses() #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" +#include "../includes/iguana_apideclares2.h" TWO_STRINGS(iguana,dpow,symbol,pubkey) { @@ -373,7 +374,6 @@ THREE_STRINGS(iguana,passthru,asset,function,hex) else return(clonestr("{\"error\":\"assetchain not active, start in bitcoind mode\"}")); } - TWO_STRINGS(dex,send,hex,handler) { uint8_t data[8192]; int32_t datalen; char *retstr; @@ -615,7 +615,7 @@ HASH_AND_STRING_AND_INT(dex,gettxout,txid,symbol,vout) TWO_STRINGS(dex,listunspent,symbol,address) { - if ( symbol != 0 && strcmp(symbol,"BTC") == 0 && (coin= iguana_coinfind("BTC")) != 0 && coin->FULLNODE == 0 && myinfo->IAMLP != 0 ) + if ( symbol != 0 && strcmp(symbol,"BTC") == 0 && (coin= iguana_coinfind("BTC")) != 0 && coin->FULLNODE == 0 && myinfo->blocktrail_apikey[0] != 0 ) { char url[1024],*retstr,*coinaddr,*script; int32_t i,n,vout; cJSON *retjson,*data,*item,*item3,*data3; bits256 txid; uint64_t val; sprintf(url,"https://api.blocktrail.com/v1/btc/address/%s/unspent-outputs?api_key=%s",address,myinfo->blocktrail_apikey); @@ -670,7 +670,7 @@ TWO_STRINGS(dex,listunspent,symbol,address) TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip) { - if ( symbol != 0 && strcmp(symbol,"BTC") == 0 && (coin= iguana_coinfind("BTC")) != 0 && coin->FULLNODE == 0 && myinfo->IAMLP != 0 ) + if ( symbol != 0 && strcmp(symbol,"BTC") == 0 && (coin= iguana_coinfind("BTC")) != 0 && coin->FULLNODE == 0 && myinfo->blocktrail_apikey[0] != 0 ) { char url[1024],*retstr,*retstr2; cJSON *retjson,*retjson2,*retjson3,*data,*data2; int32_t i,n; sprintf(url,"https://api.blocktrail.com/v1/btc/address/%s/transactions?api_key=%s",address,myinfo->blocktrail_apikey); @@ -747,6 +747,16 @@ TWO_STRINGS(dex,validateaddress,symbol,address) return(_dex_validateaddress(myinfo,symbol,address)); } +STRING_ARG(dex,getmessage,argstr) +{ + return(_dex_getmessage(myinfo,argstr)); +} + +STRING_ARG(dex,psock,argstr) +{ + return(_dex_psock(myinfo,argstr)); +} + STRING_ARG(dex,getnotaries,symbol) { return(_dex_getnotaries(myinfo,symbol)); @@ -860,7 +870,7 @@ TWO_STRINGS(dex,getbalance,symbol,address) } if ( symbol != 0 && address != 0 ) { - if ( strcmp(symbol,"BTC") == 0 && myinfo->IAMLP != 0 ) + if ( strcmp(symbol,"BTC") == 0 && myinfo->blocktrail_apikey[0] != 0 ) { sprintf(url,"https://api.blocktrail.com/v1/btc/address/%s?api_key=%s",address,myinfo->blocktrail_apikey); if ( (retstr= issue_curl(url)) != 0 ) diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 82386e4b9..842dd261c 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -175,7 +175,7 @@ int32_t iguana_RTbestunspent(struct supernet_info *myinfo,struct iguana_info *co } 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; } if ( maxmode == 0 ) @@ -274,7 +274,7 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int memset(&msgtx,0,sizeof(msgtx)); if ( V == 0 ) V = calloc(numinputs,sizeof(*V)), flagV = 1; - //printf("SIGN.(%s) priv.(%s) %llx %llx\n",jprint(vins,0),jprint(privkeys,0),(long long)V->signers[0].privkey.txid,(long long)V->signers[1].privkey.txid); + //printf("SIGN.(%s) priv.(%s) %llx %llx (%s)\n",jprint(vins,0),jprint(privkeys,0),(long long)V->signers[0].privkey.txid,(long long)V->signers[1].privkey.txid,vins!=0?jprint(vins,0):"no vins"); if ( V != 0 ) { if ( iguana_signrawtransaction(myinfo,coin,height,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 ) @@ -346,18 +346,26 @@ uint64_t _iguana_interest(uint32_t now,int32_t chainheight,uint32_t txlocktime,u int32_t minutes; uint64_t numerator=0,denominator=0,interest = 0; if ( (minutes= ((uint32_t)time(NULL) - 60 - txlocktime) / 60) >= 60 ) { + if ( minutes > 365 * 24 * 60 ) + minutes = 365 * 24 * 60; + if ( chainheight >= 250000 ) + minutes -= 59; denominator = (((uint64_t)365 * 24 * 60) / minutes); if ( denominator == 0 ) denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually! if ( value > 25000LL*SATOSHIDEN && chainheight > 155949 ) { numerator = (value / 20); // assumes 5%! - interest = (numerator / denominator); + if ( chainheight < 250000 ) + interest = (numerator / denominator); + else interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); } else if ( value >= 10*SATOSHIDEN ) { numerator = (value * KOMODO_INTEREST); - interest = (numerator / denominator) / SATOSHIDEN; + if ( chainheight < 250000 || numerator * minutes < 365 * 24 * 60 ) + interest = (numerator / denominator) / SATOSHIDEN; + else interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)) / SATOSHIDEN; } //fprintf(stderr,"komodo_interest.%d %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",chainheight,(long long)value,(double)value/SATOSHIDEN,txlocktime,now,minutes,(long long)interest,(double)interest/SATOSHIDEN,(long long)numerator,(long long)denominator); } @@ -394,7 +402,6 @@ uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,b interest = _iguana_interest((uint32_t)time(NULL),coin->longestchain,tx->locktime,value); } } - char str[65]; printf("interest for %s.v%d %.8f %.8f (%s)\n",bits256_str(str,txid),vout,dstr(value),dstr(interest),retjson!=0?jprint(retjson,0):""); return(interest); } @@ -442,7 +449,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS } unspents = realloc(unspents,(1 + max) * sizeof(*unspents)); value = jdouble(item,"amount") * SATOSHIDEN; - if ( jdouble(item,"interest") != 0 ) + if ( (0) && jdouble(item,"interest") != 0 ) printf("utxo has interest of %.8f\n",jdouble(item,"interest")); iguana_outptset(myinfo,coin,&unspents[max++],jbits256(item,"txid"),jint(item,"vout"),value,spendscriptstr); avail += value; @@ -460,7 +467,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS free(unspents); 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 num.%d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen,num); if ( txobj != 0 && avail >= satoshis+txfee ) { if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num,maxmode)) != 0 ) @@ -535,7 +542,11 @@ char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin for (i=0; i 16 ) + { + + } + else if ( (sobj= jobj(item,"scriptPubKey")) == 0 || (spendscriptstr= jstr(sobj,"hex")) == 0 ) { printf("no spendscript (%s)\n",jprint(item,0)); continue; @@ -554,6 +565,14 @@ char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin { if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num,maxmode)) != 0 ) { + if ( strcmp(coin->symbol,"KMD") == 0 ) + { + if ( (interests= iguana_interests(myinfo,coin,vins)) != 0 ) + { + total += interests; + printf("boost total by interest %.8f\n",dstr(interests)); + } + } if ( total < (satoshis + txfee) ) { free_json(vins); @@ -561,7 +580,6 @@ char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin printf("insufficient total %.8f vs (%.8f + %.8f)\n",dstr(total),dstr(satoshis),dstr(txfee)); return(0); } - total += interests; if ( (change= (total - (satoshis + txfee))) > 10000 && (changeaddr == 0 || changeaddr[0] == 0) ) { printf("no changeaddr for %.8f\n",dstr(change)); @@ -690,6 +708,7 @@ char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char * #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" +#include "../includes/iguana_apideclares2.h" STRING_AND_INT(bitcoinrpc,sendrawtransaction,rawtx,allowhighfees) { @@ -1675,4 +1694,99 @@ THREE_INTS(iguana,splitfunds,satoshis,duplicates,sendflag) return(jprint(retjson,1)); } +P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC) +{ + struct vin_info V; uint8_t p2sh_rmd160[20],serialized[2096],spendscript[32],pubkeys[3][65],*pubkeyptrs[3]; int32_t spendlen,height = 0; + char msigaddr[64],*retstr; cJSON *retjson,*txobj; struct iguana_info *active; + bits256 signedtxid; char *signedtx; + struct iguana_msgtx msgtx; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( myinfo->expiration == 0 ) + return(clonestr("{\"error\":\"need to unlock wallet\"}")); + if ( (active= iguana_coinfind(activecoin)) == 0 ) + return(clonestr("{\"error\":\"activecoin isnt active\"}")); + if ( M > N || N > 3 ) + return(clonestr("{\"error\":\"illegal M or N\"}")); + memset(&V,0,sizeof(V)); + txobj = bitcoin_txcreate(active->symbol,active->chain->isPoS,0,coin->chain->normal_txversion,0); + if ( destaddress[0] != 0 && destamount > 0. ) + bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN); + if ( destaddress2[0] != 0 && destamount2 > 0. ) + bitcoin_txaddspend(active,txobj,destaddress2,destamount2 * SATOSHIDEN); + if ( pubA[0] != 0 && (retstr= _setVsigner(active,&V,0,pubA,wifA)) != 0 ) + return(retstr); + if ( N >= 2 && pubB[0] != 0 && (retstr= _setVsigner(active,&V,1,pubB,wifB)) != 0 ) + return(retstr); + if ( N == 3 && pubC[0] != 0 && (retstr= _setVsigner(active,&V,2,pubC,wifC)) != 0 ) + return(retstr); + V.M = M, V.N = N, V.type = IGUANA_SCRIPT_P2SH; + V.p2shlen = bitcoin_MofNspendscript(p2sh_rmd160,V.p2shscript,0,&V); + spendlen = bitcoin_p2shspend(spendscript,0,p2sh_rmd160); + if ( pubA[0] != 0 ) + { + decode_hex(pubkeys[0],(int32_t)strlen(pubA)>>1,pubA); + pubkeyptrs[0] = pubkeys[0]; + } + if ( pubB[0] != 0 ) + { + decode_hex(pubkeys[1],(int32_t)strlen(pubB)>>1,pubB); + pubkeyptrs[1] = pubkeys[1]; + } + if ( pubC[0] != 0 ) + { + decode_hex(pubkeys[2],(int32_t)strlen(pubC)>>1,pubC); + pubkeyptrs[2] = pubkeys[2]; + } + bitcoin_txinput(active,txobj,vintxid,vinvout,0xffffffff,spendscript,spendlen,V.p2shscript,V.p2shlen,pubkeyptrs,N,0,0); + bitcoin_address(msigaddr,active->chain->p2shtype,V.p2shscript,V.p2shlen); + retjson = cJSON_CreateObject(); + if ( bitcoin_verifyvins(active,height,&signedtxid,&signedtx,&msgtx,serialized,sizeof(serialized),&V,SIGHASH_ALL,1,V.suppress_pubkeys) == 0 ) + { + jaddstr(retjson,"result","msigtx"); + if ( signedtx != 0 ) + jaddstr(retjson,"signedtx",signedtx), free(signedtx); + jaddbits256(retjson,"txid",signedtxid); + } else jaddstr(retjson,"error","couldnt sign tx"); + jaddstr(retjson,"msigaddr",msigaddr); + return(jprint(retjson,1)); +} + +STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighash) +{ + char *signedtx = 0; struct vin_info *V; bits256 signedtxid; int32_t complete,numinputs = 1; struct iguana_msgtx msgtx; cJSON *retjson; int uselessbitcoin_error = 0; + retjson = cJSON_CreateObject(); + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( myinfo->expiration == 0 ) + return(clonestr("{\"error\":\"need to unlock wallet\"}")); + //printf("rawtx.(%s) vins.(%s) privkeys.(%s) sighash.(%s)\n",rawtx,jprint(vins,0),jprint(privkeys,0),sighash); + if ( sighash == 0 || sighash[0] == 0 ) + sighash = "ALL"; + if ( strcmp(sighash,"ALL") != 0 ) + jaddstr(retjson,"error","only sighash all (ALL) supported for now"); + if ( (numinputs= cJSON_GetArraySize(vins)) > 0 ) + { + V = calloc(numinputs,sizeof(*V)); + memset(&msgtx,0,sizeof(msgtx)); + if ( (complete= iguana_signrawtransaction(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,&signedtx,&signedtxid,V,numinputs,rawtx,vins,privkeys)) >= 0 ) + { + if ( signedtx != 0 ) + { + jaddstr(retjson,"result",signedtx); + jadd(retjson,"complete",complete!=0?jtrue():jfalse()); + free(signedtx); + } else jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "no transaction from verifyvins"); + } + else if ( complete == -2 ) + jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "hex2json -> json2hex error"); + else if ( complete == -1 ) + jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "couldnt load serialized tx or mismatched numinputs"); + free(V); + //for (i=0; isymbol); + if ( coin != 0 ) + jaddstr(json,"coin",coin->symbol); if ( userpass != 0 ) jaddstr(json,"userpass",userpass); if ( coin != 0 && coin->FULLNODE >= 0 && coin->chain->userpass[0] != 0 ) diff --git a/iguana/iguana_scripts.c b/iguana/iguana_scripts.c index 2b8d9f21e..57e8181d1 100755 --- a/iguana/iguana_scripts.c +++ b/iguana/iguana_scripts.c @@ -487,7 +487,7 @@ char *iguana_scriptaddress(struct iguana_info *coin,char *coinaddr,uint8_t *scri int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t *sigsizep,uint32_t *pubkeysizep,uint8_t **userdatap,uint32_t *userdatalenp,struct vin_info *vp,uint8_t *scriptsig,int32_t len,int32_t spendtype) { - char asmstr[IGUANA_MAXSCRIPTSIZE*3]; int32_t j,n,siglen,plen; uint8_t *p2shscript; + int32_t j,n,siglen,plen; uint8_t *p2shscript; j = n = 0; *userdatap = 0; *userdatalenp = *pubkeysizep = *sigsizep = 0; @@ -559,7 +559,7 @@ int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t * decode_hex(vp->rmd160,20,"010966776006953d5567439e5e39f86a0d273bee");//3564a74f9ddb4372301c49154605573d7d1a88fe"); vp->type = IGUANA_SCRIPT_76A988AC; }*/ - vp->spendlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,vp->spendscript,asmstr,vp->rmd160,vp->type,(const struct vin_info *)vp,vp->vin.prev_vout); + vp->spendlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,vp->spendscript,0,vp->rmd160,vp->type,(const struct vin_info *)vp,vp->vin.prev_vout); //printf("type.%d asmstr.(%s) spendlen.%d\n",vp->type,asmstr,vp->spendlen); return(vp->spendlen); } diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index 3ef8338c6..20ce30e9d 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -568,6 +568,22 @@ void iguana_vinobjset(struct iguana_msgvin *vin,cJSON *item,uint8_t *spendscript } } +int32_t iguana_vinarray_check(cJSON *vinarray,bits256 txid) +{ + bits256 array_txid; cJSON *item; int32_t i,n = cJSON_GetArraySize(vinarray); + for (i=0; ivouts[i],i,*txidp)); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); - //printf("lock_time.%08x len.%d\n",msg->lock_time,len); +//printf("lock_time.%08x len.%d\n",msg->lock_time,len); if ( strcmp(coin->symbol,"VPN") == 0 ) { uint16_t ddosflag = 0; @@ -688,13 +704,16 @@ 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)); - jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid)); + if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 ) + jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid)); if ( msg->vins[i].spendscript == spendscript ) msg->vins[i].spendscript = 0; - } else jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid)); + } else if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 ) + jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid)); } free(sigser); jadd(json,"vin",vinarray); + msg->tx_in = cJSON_GetArraySize(vinarray); jaddnum(json,"numvins",msg->tx_in); } if ( voutarray != 0 ) @@ -833,6 +852,7 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,int32_t height,bits256 *txidp, jaddstr(txobj,"error","couldnt decode transaction"); jaddstr(txobj,"coin",coin->symbol); } + //printf("msgtx.(%s)\n",jprint(txobj,0)); if ( n != len ) { int32_t i; @@ -1013,13 +1033,13 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign { flag++; numsigs++; - int32_t z; + /*int32_t z; for (z=0; zsigners[j].pubkey[z]); - printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M); + printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);*/ } } if ( numsigs >= vp->M ) @@ -1344,71 +1364,9 @@ int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLoc return(0); } -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - - -P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC) -{ - struct vin_info V; uint8_t p2sh_rmd160[20],serialized[2096],spendscript[32],pubkeys[3][65],*pubkeyptrs[3]; int32_t spendlen,height = 0; - char msigaddr[64],*retstr; cJSON *retjson,*txobj; struct iguana_info *active; - bits256 signedtxid; char *signedtx; - struct iguana_msgtx msgtx; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - if ( myinfo->expiration == 0 ) - return(clonestr("{\"error\":\"need to unlock wallet\"}")); - if ( (active= iguana_coinfind(activecoin)) == 0 ) - return(clonestr("{\"error\":\"activecoin isnt active\"}")); - if ( M > N || N > 3 ) - return(clonestr("{\"error\":\"illegal M or N\"}")); - memset(&V,0,sizeof(V)); - txobj = bitcoin_txcreate(active->symbol,active->chain->isPoS,0,coin->chain->normal_txversion,0); - if ( destaddress[0] != 0 && destamount > 0. ) - bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN); - if ( destaddress2[0] != 0 && destamount2 > 0. ) - bitcoin_txaddspend(active,txobj,destaddress2,destamount2 * SATOSHIDEN); - if ( pubA[0] != 0 && (retstr= _setVsigner(active,&V,0,pubA,wifA)) != 0 ) - return(retstr); - if ( N >= 2 && pubB[0] != 0 && (retstr= _setVsigner(active,&V,1,pubB,wifB)) != 0 ) - return(retstr); - if ( N == 3 && pubC[0] != 0 && (retstr= _setVsigner(active,&V,2,pubC,wifC)) != 0 ) - return(retstr); - V.M = M, V.N = N, V.type = IGUANA_SCRIPT_P2SH; - V.p2shlen = bitcoin_MofNspendscript(p2sh_rmd160,V.p2shscript,0,&V); - spendlen = bitcoin_p2shspend(spendscript,0,p2sh_rmd160); - if ( pubA[0] != 0 ) - { - decode_hex(pubkeys[0],(int32_t)strlen(pubA)>>1,pubA); - pubkeyptrs[0] = pubkeys[0]; - } - if ( pubB[0] != 0 ) - { - decode_hex(pubkeys[1],(int32_t)strlen(pubB)>>1,pubB); - pubkeyptrs[1] = pubkeys[1]; - } - if ( pubC[0] != 0 ) - { - decode_hex(pubkeys[2],(int32_t)strlen(pubC)>>1,pubC); - pubkeyptrs[2] = pubkeys[2]; - } - bitcoin_txinput(active,txobj,vintxid,vinvout,0xffffffff,spendscript,spendlen,V.p2shscript,V.p2shlen,pubkeyptrs,N,0,0); - bitcoin_address(msigaddr,active->chain->p2shtype,V.p2shscript,V.p2shlen); - retjson = cJSON_CreateObject(); - if ( bitcoin_verifyvins(active,height,&signedtxid,&signedtx,&msgtx,serialized,sizeof(serialized),&V,SIGHASH_ALL,1,V.suppress_pubkeys) == 0 ) - { - jaddstr(retjson,"result","msigtx"); - if ( signedtx != 0 ) - jaddstr(retjson,"signedtx",signedtx), free(signedtx); - jaddbits256(retjson,"txid",signedtxid); - } else jaddstr(retjson,"error","couldnt sign tx"); - jaddstr(retjson,"msigaddr",msigaddr); - return(jprint(retjson,1)); -} - int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson) { - uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 65536; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0; + uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 65536; char *privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0; maxsize = 1000000; memset(privkey.bytes,0,sizeof(privkey)); if ( rawtx != 0 && rawtx[0] != 0 && (len= (int32_t)strlen(rawtx)>>1) < maxsize ) @@ -1420,30 +1378,14 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf extraspace = malloc(extralen); memset(msgtx,0,sizeof(*msgtx)); decode_hex(serialized,len,rawtx); + // printf("call hex2json.(%s) vins.(%s)\n",rawtx,jprint(vins,0)); if ( (txobj= bitcoin_hex2json(coin,height,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 ) { - if ( (0) && vins != 0 ) - printf("txobj.(%s)\n",jprint(txobj,0)); - if ( jobj(txobj,"error") != 0 ) - { - printf("txobj.(%s)\n",jprint(txobj,0)); - } - if ( (0) && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 ) // no guarantee of identical regen - { - if ( strcmp(rawtx,checkstr) != 0 ) - { - printf("RAW.(%s) ->\nNEW.(%s)\n",rawtx,checkstr); - //free_json(txobj); - //free(checkstr); - //free(serialized), free(serialized2), free(serialized3), free(serialized4); - //free(extraspace); - //return(-2); - } - free(checkstr); - } + //printf("back from bitcoin_hex2json (%s)\n",jprint(vins,0)); } else fprintf(stderr,"no txobj from bitcoin_hex2json\n"); if ( (numinputs= cJSON_GetArraySize(vins)) > 0 ) { + //printf("numinputs.%d msgtx.%d\n",numinputs,msgtx->tx_in); memset(msgtx,0,sizeof(*msgtx)); if ( iguana_rwmsgtx(coin,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) { @@ -1463,6 +1405,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf iguana_ensure_privkey(myinfo,coin,privkey); } } + //printf("after privkeys tx_in.%d\n",msgtx->tx_in); for (i=0; itx_in; i++) { if ( msgtx->vins[i].p2shlen != 0 ) @@ -1473,18 +1416,13 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf sigsize = 0; flag = (msgtx->vins[i].vinscript[0] == 0); type = bitcoin_scriptget(coin,&hashtype,&sigsize,&pubkeysize,&userdata,&userdatalen,&mainvin,msgtx->vins[i].vinscript+flag,msgtx->vins[i].scriptlen-flag,0); - if ( flag != 0 && pubkeysize == 33 ) // jl777: need to generalize this - { - for (k=0; kvins[i].scriptlen); if ( msgtx->vins[i].redeemscript != 0 ) { //for (j=0; jvins[i].p2shlen; j++) // printf("%02x",msgtx->vins[i].redeemscript[j]); bitcoin_address(coinaddr,coin->chain->p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen); - type = iguana_calcrmd160(coin,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,01); + type = iguana_calcrmd160(coin,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,0); for (j=0; jsuppress_pubkeys == 0 ) @@ -1512,12 +1450,12 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf for (z=0; z<33; z++) V[i].signers[j].pubkey[z] = pubkeys[k][z]; } - printf("%s -> V[%d].signer.[%d] <- privkey.%d\n",mvin.signers[j].coinaddr,i,j,k); + //printf("%s -> V[%d].signer.[%d] <- privkey.%d\n",mvin.signers[j].coinaddr,i,j,k); break; } } } - printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N); + //printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N); } } if ( i < V->N ) @@ -1535,16 +1473,17 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf } } finalized = iguana_vininfo_create(myinfo,coin,serialized2,maxsize,msgtx,vins,numinputs,V); + //printf("finalized.%d\n",finalized); if ( (complete= bitcoin_verifyvins(coin,height,signedtxidp,&signedtx,msgtx,serialized3,maxsize,V,SIGHASH_ALL,1,V->suppress_pubkeys)) > 0 && signedtx != 0 ) { int32_t tmp; char str[65]; if ( (tmp= iguana_interpreter(coin,0,iguana_lockval(finalized,jint(txobj,"locktime")),V,numinputs)) < 0 ) { - //printf("iguana_interpreter %d error.(%s)\n",tmp,signedtx); + printf("iguana_interpreter %d error.(%s)\n",tmp,signedtx); complete = 0; } else printf("%s signed\n",bits256_str(str,*signedtxidp)); - } - } + } else printf("complete.%d\n",complete); + } else printf("rwmsgtx error\n"); } else fprintf(stderr,"no inputs in vins.(%s)\n",vins!=0?jprint(vins,0):"null"); free(extraspace); free(serialized), free(serialized2), free(serialized3), free(serialized4); @@ -1555,43 +1494,4 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf return(complete); } -STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighash) -{ - char *signedtx = 0; struct vin_info *V; bits256 signedtxid; int32_t complete,numinputs = 1; struct iguana_msgtx msgtx; cJSON *retjson; int uselessbitcoin_error = 0; - retjson = cJSON_CreateObject(); - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - if ( myinfo->expiration == 0 ) - return(clonestr("{\"error\":\"need to unlock wallet\"}")); - //printf("rawtx.(%s) vins.(%s) privkeys.(%s) sighash.(%s)\n",rawtx,jprint(vins,0),jprint(privkeys,0),sighash); - if ( sighash == 0 || sighash[0] == 0 ) - sighash = "ALL"; - if ( strcmp(sighash,"ALL") != 0 ) - jaddstr(retjson,"error","only sighash all (ALL) supported for now"); - if ( (numinputs= cJSON_GetArraySize(vins)) > 0 ) - { - V = calloc(numinputs,sizeof(*V)); - memset(&msgtx,0,sizeof(msgtx)); - if ( (complete= iguana_signrawtransaction(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,&signedtx,&signedtxid,V,numinputs,rawtx,vins,privkeys)) >= 0 ) - { - if ( signedtx != 0 ) - { - jaddstr(retjson,"result",signedtx); - jadd(retjson,"complete",complete!=0?jtrue():jfalse()); - free(signedtx); - } else jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "no transaction from verifyvins"); - } - else if ( complete == -2 ) - jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "hex2json -> json2hex error"); - else if ( complete == -1 ) - jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "couldnt load serialized tx or mismatched numinputs"); - free(V); - //for (i=0; imarkedunspents[firstslot] = txid; coin->markedunspents[firstslot].ushorts[15] = vout; - if ( coin->utxofp == 0 ) + if ( (0) && coin->utxofp == 0 ) { sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname); if ( (coin->utxofp= fopen(fname,"rb+")) == 0 ) @@ -939,6 +939,7 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin, void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *coin) { char *filestr,fname[1024]; FILE *fp; long filesize; bits256 filetxid; cJSON *array,*item; int32_t i,filevout,n,firstslot; +return; sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname); if ( (fp= fopen(fname,"rb")) != 0 ) { @@ -948,7 +949,7 @@ void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *c { if ( firstslot >= 0 ) { - char str[65]; printf("%s slot.[%d] <- %s/v%d\n",fname,firstslot,bits256_str(str,filetxid),filevout); + //char str[65]; printf("%s slot.[%d] <- %s/v%d\n",fname,firstslot,bits256_str(str,filetxid),filevout); coin->markedunspents[firstslot] = filetxid; coin->markedunspents[firstslot].ushorts[15] = filevout; } @@ -974,7 +975,7 @@ void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *c { if ( firstslot >= 0 ) { - char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout); + //char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout); coin->markedunspents[firstslot] = filetxid; coin->markedunspents[firstslot].ushorts[15] = filevout; } @@ -1798,6 +1799,7 @@ void iguana_utxoaddrs_purge(struct iguana_info *coin) #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" +#include "../includes/iguana_apideclares2.h" STRING_AND_INT(iguana,snapshot,symbol,height) { diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 11d631d2b..c73259f29 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -995,6 +995,7 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" +#include "../includes/iguana_apideclares2.h" int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,cJSON *txids,cJSON *vouts,cJSON *unspents,cJSON *spends,char *coinaddr,int32_t minconf,int32_t firstheight) { @@ -1360,7 +1361,16 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout) if ( coin != 0 ) { bitcoin_address(coin->changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33); + if ( coin->FULLNODE < 0 ) + { + char wifstr[64]; + bitcoin_priv2wif(wifstr,myinfo->persistent_priv,coin->chain->wiftype); + jumblr_importprivkey(myinfo,coin,wifstr); + } } + if ( bits256_nonz(myinfo->persistent_priv) != 0 ) + smartaddress_add(myinfo,myinfo->persistent_priv,"",""); + //basilisk_unspents_update(myinfo,coin); return(retstr); } diff --git a/iguana/kmd_lookup.h b/iguana/kmd_lookup.h index 5ed99a79b..f44779156 100755 --- a/iguana/kmd_lookup.h +++ b/iguana/kmd_lookup.h @@ -117,7 +117,7 @@ int32_t kmd_transactionvin(struct iguana_info *coin,bits256 spendtxid,int32_t vi } return(0); } - char str[65]; printf("vin error %s vout.%d of %d vs ptr %p [%d] spent.%p\n",bits256_str(str,txid),vout,ptr!=0?ptr->numvouts:-1,ptr,ptr!=0?ptr->numvouts:-1,spendptr); + char str[65]; printf("%s.vin error %s vout.%d of %d vs ptr %p [%d] spent.%p\n",coin->symbol,bits256_str(str,txid),vout,ptr!=0?ptr->numvouts:-1,ptr,ptr!=0?ptr->numvouts:-1,spendptr); return(-1); } @@ -203,11 +203,11 @@ FILE *kmd_txidinit(struct iguana_info *coin) { if ( (tx= kmd_transactionalloc(T.txid,T.height,T.timestamp,T.numvouts,T.numvins)) != 0 ) { - //printf("INIT %s.[%d] vins.[%d] ht.%d %u\n",bits256_str(str,T.txid),T.numvouts,T.numvins,T.height,T.timestamp); + //char str[65]; printf("INIT %s.[%d] vins.[%d] ht.%d %u\n",bits256_str(str,T.txid),T.numvouts,T.numvins,T.height,T.timestamp); if ( (ptr= kmd_transactionadd(coin,tx,T.numvouts,T.numvins)) != 0 ) { if ( ptr != kmd_transaction(coin,tx->txid) ) - printf("ERROR: %p != %p for ht.%d\n",ptr,kmd_transaction(coin,tx->txid),tx->height); + printf("%s ERROR: %p != %p for ht.%d\n",coin->symbol,ptr,kmd_transaction(coin,tx->txid),tx->height); ptr->fpos = lastpos; ptr->numvins = T.numvins; ptr->numvouts = T.numvouts; @@ -219,7 +219,7 @@ FILE *kmd_txidinit(struct iguana_info *coin) } else { - printf("error loading vout.%d ht.%d\n",i,T.height); + printf("%s error loading vout.%d ht.%d\n",coin->symbol,i,T.height); break; } } @@ -255,7 +255,7 @@ FILE *kmd_spendinit(struct iguana_info *coin) { if ( kmd_transactionvin(coin,txid,i,spenttxid,spentvout) < 0 ) { - printf("error adding spend %s %d of %d\n",bits256_str(str,txid),i,numvins); + printf("%s error adding spend %s %d of %d\n",coin->symbol,bits256_str(str,txid),i,numvins); //break; } } else break; @@ -277,7 +277,7 @@ FILE *kmd_spendinit(struct iguana_info *coin) { if ( ptr->ptrs[(i<<1) + 1] != kmd_transaction(coin,vptr->spendtxid) ) { - printf("mismatch %s spend.%d %p %p\n",bits256_str(str,vptr->spendtxid),i,ptr->ptrs[(i<<1) + 1],kmd_transaction(coin,vptr->spendtxid)); + printf("%s mismatch %s spend.%d %p %p\n",coin->symbol,bits256_str(str,vptr->spendtxid),i,ptr->ptrs[(i<<1) + 1],kmd_transaction(coin,vptr->spendtxid)); } } } @@ -392,9 +392,24 @@ cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout) cJSON *kmd_listaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t mode,cJSON *array) { - struct kmd_addresshh *addr; struct kmd_transactionhh *ptr=0,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i; + struct kmd_addresshh *addr; struct kmd_transactionhh *ptr=0,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i; char *retstr; cJSON *retjson; if ( array == 0 ) array = cJSON_CreateArray(); + //printf("%s listaddress.(%s)\n",coin->symbol,coinaddr); + if ( (retstr= bitcoinrpc_validateaddress(myinfo,coin,0,0,coinaddr)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(retjson,"error") != 0 && is_cJSON_False(jobj(retjson,"error")) == 0 ) + { + printf("%s\n",retstr); + free(retstr); + return(retjson); + } + free_json(retjson); + } + free(retstr); + } /*if ( time(NULL) > coin->kmd_lasttime+30 ) { coin->kmd_lasttime = (uint32_t)time(NULL); @@ -463,7 +478,7 @@ cJSON *kmd_listaddress(struct supernet_info *myinfo,struct iguana_info *coin,cha } ptr = prev; } - } else printf("no valid entry for (%s) %p %p\n",coinaddr,addr,ptr); + } //else printf("no valid entry for (%s) %p %p\n",coinaddr,addr,ptr); return(array); } @@ -627,7 +642,7 @@ int32_t _kmd_bitcoinscan(struct iguana_info *coin) { flag = 0; if ( (loadheight % 10000) == 0 ) - printf("loading ht.%d\n",loadheight);//,jprint(kmd_getbalance(coin,"*"),1)); + printf("loading %s ht.%d vs height.%d - lag.%d kmdheight.%d\n",coin->symbol,loadheight,height,lag,coin->kmd_height);//,jprint(kmd_getbalance(coin,"*"),1)); if ( (blockjson= kmd_blockjson(&h,coin->symbol,coin->chain->serverport,coin->chain->userpass,0,loadheight)) != 0 ) { if ( (txids= jarray(&numtxids,blockjson,"tx")) != 0 ) @@ -679,9 +694,11 @@ int32_t _kmd_bitcoinscan(struct iguana_info *coin) { bitcoin_addr2rmd160(&type_rmd160[0],&type_rmd160[1],jstri(addresses,0)); kmd_transactionvout(coin,ptr,j,jdouble(vout,"value")*SATOSHIDEN,type_rmd160,zero,-1); + //fprintf(stderr,"%.8f ",jdouble(vout,"value")); } // else printf("missing sobj.%p or addresses.%p (%s)\n",sobj,addresses,jprint(vout,0)); //likely OP_RETURN sobj = addresses = 0; } + //fprintf(stderr,"numvouts.%d ht.%d %s\n",numvouts,height,coin->symbol); if ( coin->kmd_txidfp != 0 ) { ptr->fpos = ftell(coin->kmd_txidfp); @@ -748,6 +765,7 @@ void kmd_bitcoinscan() { //if ( strcmp("KMD",coin->symbol) == 0 ) _kmd_bitcoinscan(coin); + usleep(250000); } } } diff --git a/iguana/main.c b/iguana/main.c index c0d231e3b..984f2c27a 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -24,6 +24,7 @@ #include "../pnacl_main.h" #include "iguana777.h" + struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char *retjsonstr; char remoteaddr[64]; uint16_t port; char jsonstr[]; }; uint16_t SuperNET_API2num(char *agent,char *method) @@ -461,6 +462,19 @@ rm BTC.xz; mksquashfs DB/BTC BTC.xz -comp xz -b 1048576 -comp xz -Xdict-size 102 https://github.com/vasi/squashfuse */ +void DEX_explorerloop(void *ptr) +{ + struct supernet_info *myinfo = ptr; + while ( 1 ) + { + if ( myinfo->DEXEXPLORER != 0 ) + { + kmd_bitcoinscan(); + } + usleep(100000); + } +} + void mainloop(struct supernet_info *myinfo) { struct iguana_info *coin; int32_t counter=0,depth; double lastmilli = 0; @@ -484,8 +498,6 @@ void mainloop(struct supernet_info *myinfo) } usleep(30000); } - if ( myinfo->DEXEXPLORER != 0 ) - kmd_bitcoinscan(); //pangea_queues(SuperNET_MYINFO(0)); //if ( flag == 0 ) // usleep(100000 + isRT*100000 + (numpeers == 0)*1000000); @@ -672,6 +684,7 @@ void iguana_ensuredirs() sprintf(dirname,"%s",GLOBAL_GENESISDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s",GLOBAL_CONFSDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname); + sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/TRANSACTIONS",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/purgeable",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s",GLOBAL_TMPDIR), OS_ensure_directory(dirname); @@ -734,6 +747,29 @@ void iguana_urlinit(struct supernet_info *myinfo,int32_t ismainnet,int32_t usess else strcat(myinfo->NXTAPIURL,"6876/nxt"); } +void jumblr_loop(void *ptr) +{ + struct iguana_info *coin; char BTCaddr[64],KMDaddr[64]; bits256 privkey; uint32_t t; struct supernet_info *myinfo = ptr; int32_t mult = 10; + printf("JUMBLR loop\n"); + while ( 1 ) + { + if ( (coin= iguana_coinfind("KMD")) != 0 && coin->FULLNODE < 0 ) + { + privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + // 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); + t = (uint32_t)time(NULL); + if ( myinfo->jumblr_passphrase[0] != 0 && (t % (120 * mult)) < 60 ) + { + jumblr_iteration(myinfo,coin,(t % (360 * mult)) / (120 * mult),t % (120 * mult)); + } + //printf("t.%u %p.%d %s\n",t,coin,coin!=0?coin->FULLNODE:0,myinfo->jumblr_passphrase); + } + sleep(55); + } +} + void iguana_launchdaemons(struct supernet_info *myinfo) { int32_t i; char *helperargs,helperstr[512]; @@ -749,6 +785,9 @@ void iguana_launchdaemons(struct supernet_info *myinfo) if ( COMMANDLINE_ARGFILE == 0 ) iguana_launch(0,"rpcloop",iguana_rpcloop,myinfo,IGUANA_PERMTHREAD); // limit to oneprocess printf("launch mainloop\n"); + OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)DEX_explorerloop,(void *)myinfo); + OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)jumblr_loop,(void *)myinfo); + OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)dpow_psockloop,(void *)myinfo); mainloop(myinfo); } @@ -987,6 +1026,435 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" +#include "../includes/iguana_apideclares2.h" + +STRING_ARG(iguana,initfastfind,activecoin) +{ + if ( (coin= iguana_coinfind(activecoin)) != 0 ) + { + iguana_fastfindcreate(coin); + return(clonestr("{\"result\":\"fast find initialized\"}")); + } else return(clonestr("{\"error\":\"no coin to initialize\"}")); +} + +TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,lastheightd,minconfd) +{ + int32_t lastheight,minconf,maxconf=1<<30; cJSON *array,*retjson = cJSON_CreateObject(); + if ( activecoin != 0 && activecoin[0] != 0 ) + coin = iguana_coinfind(activecoin); + if ( coin != 0 ) + { + if ( (minconf= minconfd) <= 0 ) + minconf = 1; + lastheight = lastheightd; + jaddstr(retjson,"address",address); + if ( bitcoin_validaddress(coin,address) < 0 ) + { + jaddstr(retjson,"error","illegal address"); + return(jprint(retjson,1)); + } + jadd64bits(retjson,"RTbalance",iguana_RTbalance(coin,address)); + array = cJSON_CreateArray(); + jaddistr(array,address); + jadd(retjson,"unspents",iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,1)); + free_json(array); + if ( lastheight > 0 ) + jaddnum(retjson,"RTheight",coin->RTheight); + } + return(jprint(retjson,1)); +} + +STRING_ARG(iguana,validate,activecoin) +{ + int32_t i,total,validated; struct iguana_bundle *bp; cJSON *retjson; + if ( (coin= iguana_coinfind(activecoin)) != 0 ) + { + for (i=total=validated=0; ibundlescount; i++) + if ( (bp= coin->bundles[i]) != 0 ) + { + validated += iguana_bundlevalidate(myinfo,coin,bp,1); + total += bp->n; + } + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","validation run"); + jaddstr(retjson,"coin",coin->symbol); + jaddnum(retjson,"validated",validated); + jaddnum(retjson,"total",total); + jaddnum(retjson,"bundles",coin->bundlescount); + jaddnum(retjson,"accuracy",(double)validated/total); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"no active coin\"}")); +} + +STRING_ARG(iguana,removecoin,activecoin) +{ + struct iguana_bundle *bp; int32_t i,height; char fname[1024]; + if ( (coin= iguana_coinfind(activecoin)) != 0 ) + { + coin->active = 0; + coin->started = 0; + if ( (0) ) + { + for (i=0; isymbol,i), OS_removefile(fname,0); + sprintf(fname,"%s/%s/%04d.vins",coin->VALIDATEDIR,coin->symbol,i), OS_removefile(fname,0); + } + sprintf(fname,"%s/%s/vouts/*",GLOBAL_DBDIR,coin->symbol), OS_removefile(fname,0); + sprintf(fname,"%s/%s/*",coin->VALIDATEDIR,coin->symbol), OS_removefile(fname,0); + for (i=0; ibundlescount; i++) + { + sprintf(fname,"%s/%s/balancecrc.%d",GLOBAL_DBDIR,coin->symbol,i), OS_removefile(fname,0); + if ( (bp= coin->bundles[i]) != 0 ) + { + iguana_bundlepurgefiles(coin,bp); + iguana_bundleremove(coin,bp->hdrsi,1); + } + } + for (height=0; heightlongestchain; height+=IGUANA_SUBDIRDIVISOR) + { + sprintf(fname,"%s/%s/%d",GLOBAL_DBDIR,coin->symbol,height/IGUANA_SUBDIRDIVISOR); + OS_remove_directory(fname); + } + sprintf(fname,"%s/%s/*",GLOBAL_DBDIR,coin->symbol), OS_remove_directory(fname); + } + return(clonestr("{\"result\":\"success\"}")); + } + return(clonestr("{\"error\":\"no active coin\"}")); +} + +INT_ARG(bitcoinrpc,getblockhash,height) +{ + cJSON *retjson; + if ( coin->notarychain >= 0 && coin->FULLNODE == 0 ) + return(_dex_getblockhash(myinfo,coin->symbol,height)); + retjson = cJSON_CreateObject(); + jaddbits256(retjson,"result",iguana_blockhash(coin,height)); + return(jprint(retjson,1)); +} + +HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly) +{ + char *blockstr,*datastr; struct iguana_msgblock msg; struct iguana_block *block; cJSON *retjson; bits256 txid; int32_t len; + if ( coin->notarychain >= 0 && coin->FULLNODE == 0 ) + return(_dex_getblock(myinfo,coin->symbol,blockhash)); + retjson = cJSON_CreateObject(); + memset(&msg,0,sizeof(msg)); + if ( remoteonly == 0 && (block= iguana_blockfind("getblockRPC",coin,blockhash)) != 0 ) + { + if ( verbose != 0 ) + return(jprint(iguana_blockjson(myinfo,coin,block,1),1)); + else + { + if ( (len= iguana_peerblockrequest(myinfo,coin,coin->blockspace,coin->blockspacesize,0,blockhash,0)) > 0 ) + { + datastr = malloc(len*2 + 1); + init_hexbytes_noT(datastr,coin->blockspace,len); + jaddstr(retjson,"result",datastr); + free(datastr); + return(jprint(retjson,1)); + } + jaddstr(retjson,"error","error getting rawblock"); + } + } + else if ( coin->APIblockstr != 0 ) + jaddstr(retjson,"error","already have pending request"); + else + { + memset(txid.bytes,0,sizeof(txid)); + if ( (blockstr= iguana_APIrequest(coin,blockhash,txid,5)) != 0 ) + { + jaddstr(retjson,"result",blockstr); + free(blockstr); + } else jaddstr(retjson,"error","cant find blockhash"); + } + return(jprint(retjson,1)); +} + +ZERO_ARGS(bitcoinrpc,getbestblockhash) +{ + cJSON *retjson; + if ( coin->notarychain >= 0 && coin->FULLNODE == 0 ) + return(_dex_getbestblockhash(myinfo,coin->symbol)); + retjson = cJSON_CreateObject(); + char str[65]; jaddstr(retjson,"result",bits256_str(str,coin->blocks.hwmchain.RO.hash2)); + return(jprint(retjson,1)); +} + +ZERO_ARGS(bitcoinrpc,getblockcount) +{ + cJSON *retjson = cJSON_CreateObject(); + //printf("result %d\n",coin->blocks.hwmchain.height); + jaddnum(retjson,"result",coin->blocks.hwmchain.height); + return(jprint(retjson,1)); +} + +STRING_AND_INT(iguana,bundleaddresses,activecoin,height) +{ + struct iguana_info *ptr; + if ( (ptr= iguana_coinfind(activecoin)) != 0 ) + return(iguana_bundleaddrs(ptr,height / coin->chain->bundlesize)); + else return(clonestr("{\"error\":\"activecoin is not active\"}")); +} + +STRING_AND_INT(iguana,PoSweights,activecoin,height) +{ + struct iguana_info *ptr; int32_t num,nonz,errs,bundleheight; struct iguana_pkhash *refP; uint64_t *weights,supply; cJSON *retjson; + if ( (ptr= iguana_coinfind(activecoin)) != 0 ) + { + //for (bundleheight=coin->chain->bundlesize; bundleheightchain->bundlesize) + { + bundleheight = (height / ptr->chain->bundlesize) * ptr->chain->bundlesize; + if ( (weights= iguana_PoS_weights(myinfo,ptr,&refP,&supply,&num,&nonz,&errs,bundleheight)) != 0 ) + { + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",errs == 0 ? "success" : "error"); + jaddnum(retjson,"bundleheight",bundleheight); + jaddnum(retjson,"numaddresses",num); + jaddnum(retjson,"nonzero",nonz); + jaddnum(retjson,"errors",errs); + jaddnum(retjson,"supply",dstr(supply)); + free(weights); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"iguana_PoS_weights returned null\"}")); + } + } + return(clonestr("{\"error\":\"activecoin is not active\"}")); +} + +STRING_ARG(iguana,stakers,activecoin) +{ + struct iguana_info *ptr; int32_t i,datalen,pkind,hdrsi; bits256 hash2; struct iguana_bundle *bp; cJSON *retjson,*array; struct iguana_pkhash *refP; struct iguana_ramchaindata *rdata; char coinaddr[64]; uint8_t refrmd160[20]; bits256 *sortbuf; + if ( (ptr= iguana_coinfind(activecoin)) != 0 && ptr->RTheight > ptr->chain->bundlesize ) + { + hdrsi = (ptr->RTheight / ptr->chain->bundlesize) - 1; + if ( (bp= ptr->bundles[hdrsi]) != 0 && bp->weights != 0 && (rdata= bp->ramchain.H.data) != 0 && bp->weights != 0 ) + { + sortbuf = calloc(bp->numweights,2 * sizeof(*sortbuf)); + for (i=datalen=0; inumweights; i++) + datalen += iguana_rwnum(1,&((uint8_t *)sortbuf)[datalen],sizeof(bp->weights[i]),(void *)&bp->weights[i]); + hash2 = bits256_doublesha256(0,(uint8_t *)sortbuf,datalen); + refP = RAMCHAIN_PTR(rdata,Poffset); + retjson = cJSON_CreateObject(); + array = cJSON_CreateArray(); + memset(refrmd160,0,sizeof(refrmd160)); + for (i=0; ichain->bundlesize; i++) + { + if ( (pkind= iguana_staker_sort(ptr,&hash2,refrmd160,refP,bp->weights,bp->numweights,sortbuf)) > 0 ) + { + bitcoin_address(coinaddr,ptr->chain->pubtype,refP[pkind].rmd160,sizeof(refP[pkind].rmd160)); + jaddistr(array,coinaddr); + } else jaddistr(array,"error"); + } + jaddstr(retjson,"result","success"); + jadd(retjson,"stakers",array); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"iguana_stakers needs PoSweights and weights\"}")); + } + return(clonestr("{\"error\":\"activecoin is not active\"}")); +} + +STRING_AND_INT(iguana,bundlehashes,activecoin,height) +{ + struct iguana_info *ptr; struct iguana_bundle *bp; int32_t i,hdrsi; cJSON *retjson,*array; struct iguana_ramchaindata *rdata; + if ( (ptr= iguana_coinfind(activecoin)) != 0 ) + { + hdrsi = height / coin->chain->bundlesize; + if ( hdrsi < coin->bundlescount && hdrsi >= 0 && (bp= coin->bundles[hdrsi]) != 0 ) + { + if ( (rdata= bp->ramchain.H.data) != 0 ) + { + array = cJSON_CreateArray(); + for (i=0; ilhashes[i].txid); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jaddbits256(retjson,"sha256",rdata->sha256); + jadd(retjson,"bundlehashes",array); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"ramchain not there\"}")); + } else return(clonestr("{\"error\":\"height is too big\"}")); + } else return(clonestr("{\"error\":\"activecoin is not active\"}")); +} + +// low priority RPC + +HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag) +{ + /*"transactions" : [ + { + "account" : "doc test", + "address" : "mmXgiR6KAhZCyQ8ndr2BCfEq1wNG2UnyG6", + "category" : "receive", + "amount" : 0.10000000, + "vout" : 0, + "confirmations" : 76478, + "blockhash" : "000000000017c84015f254498c62a7c884a51ccd75d4dd6dbdcb6434aa3bd44d", + "blockindex" : 1, + "blocktime" : 1399294967, + "txid" : "85a98fdf1529f7d5156483ad020a51b7f3340e47448cf932f470b72ff01a6821", + "walletconflicts" : [ + ], + "time" : 1399294967, + "timereceived" : 1418924714 + },*/ + cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"error","low priority RPC not implemented"); + return(jprint(retjson,1)); +} + +ZERO_ARGS(bitcoinrpc,gettxoutsetinfo) +{ + cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"error","low priority RPC not implemented"); + return(jprint(retjson,1)); +} + +ZERO_ARGS(bitcoinrpc,listaddressgroupings) +{ + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + return(clonestr("{\"error\":\"low priority RPC not implemented\"}")); +} + +SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment) +{ + cJSON *retjson; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( myinfo->expiration == 0 ) + return(clonestr("{\"error\":\"need to unlock wallet\"}")); + retjson = cJSON_CreateObject(); + return(jprint(retjson,1)); +} + +ZERO_ARGS(pax,start) +{ + void PAX_init(); + PAX_init(); + return(clonestr("{\"result\":\"PAX_init called\"}")); +} + +STRING_AND_TWOINTS(mouse,change,name,x,y) +{ + printf("mouse (%s) x.%d y.%d\n",name,x,y); + return(clonestr("{\"result\":\"changed\"}")); +} + +STRING_ARG(mouse,leave,name) +{ + printf("mouse (%s) leave\n",name); + return(clonestr("{\"result\":\"left\"}")); +} + +STRING_AND_TWOINTS(mouse,click,name,x,y) +{ + printf("mouse (%s) x.%d y.%d click\n",name,x,y); + return(clonestr("{\"result\":\"click\"}")); +} + +STRING_AND_INT(keyboard,key,name,c) +{ + printf(" KEY.(%s) c.%d (%c)\n",name,c,c); + return(clonestr("{\"result\":\"key\"}")); +} + +STRING_AND_TWOINTS(mouse,image,name,x,y) +{ + printf("mouse CREATE (%s) x.%d y.%d\n",name,x,y); + return(clonestr("{\"result\":\"opened\"}")); +} + +STRING_ARG(mouse,close,name) +{ + printf("mouse CLOSE (%s)\n",name); + return(clonestr("{\"result\":\"closed\"}")); +} + +HASH_ARRAY_STRING(basilisk,geckotx,hash,vals,hexstr) +{ + struct iguana_info *btcd; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid; + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 ) + { + if ( (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) + { + txid = bits256_doublesha256(0,data,datalen); + retstr = gecko_sendrawtransaction(myinfo,symbol,data,datalen,txid,vals,hexstr); + } else retstr = clonestr("{\"error\":\"no tx submitted\"}"); + if ( allocptr != 0 ) + free(allocptr); + if ( retstr == 0 ) + retstr = clonestr("{\"error\":\"couldnt create geckotx\"}"); + return(retstr); + } return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko tx\"}")); +} + +HASH_ARRAY_STRING(basilisk,geckoblock,hash,vals,hexstr) +{ + return(clonestr("{\"error\":\"geckoblock is an internal reporting function\"}")); +} + +HASH_ARRAY_STRING(basilisk,geckoheaders,hash,vals,hexstr) +{ + return(clonestr("{\"error\":\"geckoheaders is an internal reporting function\"}")); +} + +HASH_ARRAY_STRING(basilisk,geckoget,hash,vals,hexstr) +{ + struct iguana_info *btcd,*virt; char *symbol; + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 ) + { + if ( (virt= iguana_coinfind(symbol)) != 0 ) + { + basilisk_wait(myinfo,virt); + return(basilisk_respond_geckoget(myinfo,"GET",&coin->internaladdr,remoteaddr,0,vals,0,0,hash,0)); + } else return(clonestr("{\"error\":\"geckoget needs virtualchain\"}")); + } + return(clonestr("{\"error\":\"geckoget needs BTCD\"}")); +} + +TWO_STRINGS(SuperNET,decryptjson,password,permanentfile) +{ + char pass[8192],fname2[1023],destfname[1024]; cJSON *retjson; bits256 wallethash,wallet2priv; + safecopy(pass,password,sizeof(pass)); + safecopy(fname2,permanentfile,sizeof(fname2)); + wallethash = wallet2priv = GENESIS_PRIVKEY; + if ( strlen(pass) == sizeof(wallethash)*2 && is_hexstr(pass,(int32_t)sizeof(bits256)*2) > 0 ) + wallethash = bits256_conv(pass); + if ( strlen(fname2) == sizeof(wallet2priv)*2 && is_hexstr(fname2,(int32_t)sizeof(bits256)*2) > 0 ) + wallet2priv = bits256_conv(fname2); + if ( (retjson= SuperNET_decryptedjson(destfname,pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 ) + { + //printf("decrypt pass.(%s) fname2.(%s) -> destfname.(%s)\n",pass,fname2,destfname); + //obj = jduplicate(jobj(retjson,"payload")); + //jdelete(retjson,"payload"); + //jadd(retjson,"result",obj); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"couldnt decrypt json file\"}")); +} + +THREE_STRINGS(SuperNET,encryptjson,password,permanentfile,payload) +{ + char destfname[4096],pass[8192],fname2[1023]; cJSON *argjson,*retjson = cJSON_CreateObject(); + safecopy(pass,password,sizeof(pass)); + safecopy(fname2,permanentfile,sizeof(fname2)); + argjson = jduplicate(json); + //printf("argjson.(%s)\n",jprint(argjson,0)); + jdelete(argjson,"agent"); + jdelete(argjson,"method"); + jdelete(argjson,"password"); + jdelete(argjson,"permanentfile"); + jdelete(argjson,"timestamp"); + jdelete(argjson,"tag"); + if ( _SuperNET_encryptjson(myinfo,destfname,pass,sizeof(pass),fname2,sizeof(fname2),argjson) == 0 ) + { + jaddstr(retjson,"result","success"); + jaddstr(retjson,"filename",destfname); + } else jaddstr(retjson,"error","couldnt encrypt json file"); + free_json(argjson); + return(jprint(retjson,1)); +} + STRING_ARG(SuperNET,addr2rmd160,address) { @@ -1423,7 +1891,7 @@ ZERO_ARGS(SuperNET,logout) ZERO_ARGS(SuperNET,activehandle) { - cJSON *retjson; + cJSON *retjson; char BTCaddr[64],KMDaddr[64]; if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); retjson = SuperNET_rosettajson(myinfo,myinfo->persistent_priv,0); @@ -1439,6 +1907,15 @@ ZERO_ARGS(SuperNET,activehandle) jaddstr(retjson,"status","unlocked"); jaddnum(retjson,"duration",myinfo->expiration - time(NULL)); } else jaddstr(retjson,"status","locked"); + if ( myinfo->jumblr_passphrase[0] != 0 ) + { + jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + jaddstr(retjson,"BTCdeposit","notyet"); + jaddstr(retjson,"KMDdeposit",KMDaddr); + jumblr_privkey(myinfo,BTCaddr,KMDaddr,""); + jaddstr(retjson,"BTCjumblr","notyet"); + jaddstr(retjson,"KMDjumblr",KMDaddr); + } SuperNET_MYINFOadd(myinfo); return(jprint(retjson,1)); } @@ -1566,7 +2043,7 @@ FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase) free(str); myinfo->expiration = (uint32_t)(time(NULL) + 3600); return(SuperNET_activehandle(IGUANA_CALLARGS)); - } else return(clonestr("{\"error\":\"need passphrase\"}")); + } else return(clonestr("{\"error\":\"need passphrase or wallet doesnt exist\"}")); return(SuperNET_activehandle(IGUANA_CALLARGS)); } @@ -1578,7 +2055,7 @@ void komodo_ICO_batch(cJSON *array,int32_t batchid) if ( (n= cJSON_GetArraySize(array)) > 0 ) { totalKMD = totalREVS = 0; - for (iter=3; iter<4; iter++) + for (iter=0; iter<1; iter++) for (i=0; irpcport = IGUANA_RPCPORT; myinfo->dpowsock = myinfo->dexsock = myinfo->pubsock = myinfo->subsock = myinfo->reqsock = myinfo->repsock = -1; dex_init(myinfo); + myinfo->psockport = 30000; if ( arg != 0 ) { if ( strcmp((char *)arg,"OStests") == 0 ) @@ -1730,6 +2208,7 @@ void iguana_main(void *arg) portable_mutex_init(&myinfo->pending_mutex); portable_mutex_init(&myinfo->dpowmutex); portable_mutex_init(&myinfo->notarymutex); + portable_mutex_init(&myinfo->psockmutex); #if LIQUIDITY_PROVIDER myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("nxtae"),0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bitcoin"),0); diff --git a/iguana/mini-gmp.c b/iguana/mini-gmp.c index ef9e235df..c2c975f12 100644 --- a/iguana/mini-gmp.c +++ b/iguana/mini-gmp.c @@ -4394,7 +4394,7 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr) //memset(data,0,be_sz); //for (i=0; ipeers != 0 ) { - iguana_fastfindcreate(coin); - return(clonestr("{\"result\":\"fast find initialized\"}")); - } else return(clonestr("{\"error\":\"no coin to initialize\"}")); + for (i=0; ipeers->active)/sizeof(*coin->peers->active); i++) + if ( coin->peers->active[i].usock >= 0 ) + num++; + sprintf(buf,"{\"result\":\"%d\"}",num); + return(clonestr(buf)); + } else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}")); } -TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,lastheightd,minconfd) +ZERO_ARGS(bitcoinrpc,getdifficulty) { - int32_t lastheight,minconf,maxconf=1<<30; cJSON *array,*retjson = cJSON_CreateObject(); - if ( activecoin != 0 && activecoin[0] != 0 ) - coin = iguana_coinfind(activecoin); + char buf[512]; if ( coin != 0 ) { - if ( (minconf= minconfd) <= 0 ) - minconf = 1; - lastheight = lastheightd; - jaddstr(retjson,"address",address); - if ( bitcoin_validaddress(coin,address) < 0 ) + sprintf(buf,"{\"result\":\"success\",\"proof-of-work\":\"%.8f\",\"search-interval\": 0}",PoW_from_compact(coin->blocks.hwmchain.RO.bits,coin->chain->unitval)); + return(clonestr(buf)); + } else return(clonestr("{\"error\":\"getdifficulty needs coin\"}")); +} + +STRING_ARG(iguana,addcoin,newcoin) +{ + char *symbol,*seedip; int32_t retval; + if ( (symbol= newcoin) == 0 && coin != 0 ) + symbol = coin->symbol; + if ( symbol != 0 ) + { + if ( (seedip= jstr(json,"seedipaddr")) != 0 ) + safecopy(myinfo->seedipaddr,seedip,sizeof(myinfo->seedipaddr)); + printf(">> addcoin.%s seedipaddr.%s\n",symbol,myinfo->seedipaddr); +#ifdef __PNACL__ + // if ( strcmp(symbol,"BTC") == 0 ) + // return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}")); +#endif + if ( (retval= iguana_launchcoin(myinfo,symbol,json,0)) > 0 ) { - jaddstr(retjson,"error","illegal address"); - return(jprint(retjson,1)); + if ( myinfo->rpcsymbol[0] == 0 ) + safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol)); + return(clonestr("{\"result\":\"coin added\"}")); } - jadd64bits(retjson,"RTbalance",iguana_RTbalance(coin,address)); - array = cJSON_CreateArray(); - jaddistr(array,address); - jadd(retjson,"unspents",iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,1)); - free_json(array); - if ( lastheight > 0 ) - jaddnum(retjson,"RTheight",coin->RTheight); - } - return(jprint(retjson,1)); + else if ( retval == 0 ) + return(clonestr("{\"result\":\"coin already there\"}")); + else return(clonestr("{\"error\":\"error adding coin\"}")); + } else return(clonestr("{\"error\":\"addcoin needs newcoin\"}")); } -STRING_ARG(iguana,validate,activecoin) +STRING_ARG(iguana,startcoin,activecoin) { - int32_t i,total,validated; struct iguana_bundle *bp; cJSON *retjson; - if ( (coin= iguana_coinfind(activecoin)) != 0 ) + if ( coin != 0 ) { - for (i=total=validated=0; ibundlescount; i++) - if ( (bp= coin->bundles[i]) != 0 ) - { - validated += iguana_bundlevalidate(myinfo,coin,bp,1); - total += bp->n; - } - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result","validation run"); - jaddstr(retjson,"coin",coin->symbol); - jaddnum(retjson,"validated",validated); - jaddnum(retjson,"total",total); - jaddnum(retjson,"bundles",coin->bundlescount); - jaddnum(retjson,"accuracy",(double)validated/total); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"no active coin\"}")); + coin->active = 1; + return(clonestr("{\"result\":\"coin started\"}")); + } else return(clonestr("{\"error\":\"startcoin needs coin\"}")); +} + +STRING_ARG(iguana,stopcoin,activecoin) +{ + if ( activecoin[0] != 0 ) + coin = iguana_coinfind(activecoin); + if ( coin != 0 ) + { + coin->active = 0; + //iguana_coinpurge(coin); + return(clonestr("{\"result\":\"coin stopped\"}")); + } else return(clonestr("{\"error\":\"stopcoin needs coin\"}")); } -STRING_ARG(iguana,removecoin,activecoin) +STRING_ARG(iguana,pausecoin,activecoin) { - struct iguana_bundle *bp; int32_t i,height; char fname[1024]; - if ( (coin= iguana_coinfind(activecoin)) != 0 ) + if ( coin != 0 ) { coin->active = 0; - coin->started = 0; - if ( (0) ) + return(clonestr("{\"result\":\"coin paused\"}")); + } else return(clonestr("{\"error\":\"pausecoin needs coin\"}")); +} + +TWO_STRINGS(iguana,addnode,activecoin,ipaddr) +{ + struct iguana_peer *addr; int32_t i,n; + if ( coin == 0 ) + coin = iguana_coinfind(activecoin); + if ( coin != 0 && strcmp(coin->symbol,"RELAY") == 0 ) + basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddr),GENESIS_PUBKEY); + printf("coin.%p.[%s] addnode.%s -> %s\n",coin,coin!=0?coin->symbol:"",activecoin,ipaddr); + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 && is_ipaddr(ipaddr) != 0 ) + { + //iguana_possible_peer(coin,ipaddr); + if ( (addr= iguana_peerslot(coin,(uint32_t)calc_ipbits(ipaddr),1)) != 0 ) { - for (i=0; isupernet = 1; + if ( addr->usock >= 0 ) { - sprintf(fname,"%s/%s/vouts/%04d.vouts",GLOBAL_DBDIR,coin->symbol,i), OS_removefile(fname,0); - sprintf(fname,"%s/%s/%04d.vins",coin->VALIDATEDIR,coin->symbol,i), OS_removefile(fname,0); - } - sprintf(fname,"%s/%s/vouts/*",GLOBAL_DBDIR,coin->symbol), OS_removefile(fname,0); - sprintf(fname,"%s/%s/*",coin->VALIDATEDIR,coin->symbol), OS_removefile(fname,0); - for (i=0; ibundlescount; i++) - { - sprintf(fname,"%s/%s/balancecrc.%d",GLOBAL_DBDIR,coin->symbol,i), OS_removefile(fname,0); - if ( (bp= coin->bundles[i]) != 0 ) + if ( (n= coin->peers->numranked) != 0 ) { - iguana_bundlepurgefiles(coin,bp); - iguana_bundleremove(coin,bp->hdrsi,1); + for (i=0; ipeers->ranked[i] ) + break; + } + if ( i == n ) + { + if ( i == IGUANA_MAXPEERS ) + i--; + else coin->peers->numranked = n+1; + coin->peers->ranked[i] = addr; + addr->recvblocks = coin->peers->ranked[0]->recvblocks + 100; + addr->recvtotal = coin->peers->ranked[0]->recvtotal*1.1 + 100; + printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers->numranked); + } else printf("(%s) is already peer.%d\n",ipaddr,i); } + return(clonestr("{\"result\":\"peer was already connected\"}")); } - for (height=0; heightlongestchain; height+=IGUANA_SUBDIRDIVISOR) + if ( addr->pending == 0 ) { - sprintf(fname,"%s/%s/%d",GLOBAL_DBDIR,coin->symbol,height/IGUANA_SUBDIRDIVISOR); - OS_remove_directory(fname); - } - sprintf(fname,"%s/%s/*",GLOBAL_DBDIR,coin->symbol), OS_remove_directory(fname); - } - return(clonestr("{\"result\":\"success\"}")); + addr->pending = (uint32_t)time(NULL); + iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); + return(clonestr("{\"result\":\"addnode submitted\"}")); + } else return(clonestr("{\"result\":\"addnode connection was already pending\"}")); + } else return(clonestr("{\"result\":\"addnode cant find peer slot\"}")); } - return(clonestr("{\"error\":\"no active coin\"}")); + else if ( coin == 0 ) + return(clonestr("{\"error\":\"addnode needs active coin, do an addcoin first\"}")); + else return(clonestr("{\"error\":\"addnode needs ipaddr\"}")); } -INT_ARG(bitcoinrpc,getblockhash,height) +TWO_STRINGS(iguana,persistent,activecoin,ipaddr) { - cJSON *retjson; - if ( coin->notarychain >= 0 && coin->FULLNODE == 0 ) - return(_dex_getblockhash(myinfo,coin->symbol,height)); - retjson = cJSON_CreateObject(); - jaddbits256(retjson,"result",iguana_blockhash(coin,height)); - return(jprint(retjson,1)); + int32_t i; + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) + { + for (i=0; ipeers->active[i].ipaddr,ipaddr) == 0 ) + { + coin->peers->active[i].persistent_peer = juint(json,"interval")+3; + return(clonestr("{\"result\":\"node marked as persistent\"}")); + } + } + return(clonestr("{\"result\":\"node wasnt active\"}")); + } else return(clonestr("{\"error\":\"persistent needs coin and ipaddr\"}")); } -HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly) +TWO_STRINGS(iguana,removenode,activecoin,ipaddr) { - char *blockstr,*datastr; struct iguana_msgblock msg; struct iguana_block *block; cJSON *retjson; bits256 txid; int32_t len; - if ( coin->notarychain >= 0 && coin->FULLNODE == 0 ) - return(_dex_getblock(myinfo,coin->symbol,blockhash)); - retjson = cJSON_CreateObject(); - memset(&msg,0,sizeof(msg)); - if ( remoteonly == 0 && (block= iguana_blockfind("getblockRPC",coin,blockhash)) != 0 ) + int32_t i; + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) { - if ( verbose != 0 ) - return(jprint(iguana_blockjson(myinfo,coin,block,1),1)); - else + for (i=0; iblockspace,coin->blockspacesize,0,blockhash,0)) > 0 ) + if ( strcmp(coin->peers->active[i].ipaddr,ipaddr) == 0 ) { - datastr = malloc(len*2 + 1); - init_hexbytes_noT(datastr,coin->blockspace,len); - jaddstr(retjson,"result",datastr); - free(datastr); - return(jprint(retjson,1)); + coin->peers->active[i].rank = 0; + coin->peers->active[i].dead = (uint32_t)time(NULL); + return(clonestr("{\"result\":\"node marked as dead\"}")); } - jaddstr(retjson,"error","error getting rawblock"); } - } - else if ( coin->APIblockstr != 0 ) - jaddstr(retjson,"error","already have pending request"); - else - { - memset(txid.bytes,0,sizeof(txid)); - if ( (blockstr= iguana_APIrequest(coin,blockhash,txid,5)) != 0 ) - { - jaddstr(retjson,"result",blockstr); - free(blockstr); - } else jaddstr(retjson,"error","cant find blockhash"); - } - return(jprint(retjson,1)); + return(clonestr("{\"result\":\"node wasnt active\"}")); + } else return(clonestr("{\"error\":\"removenode needs coin and ipaddr\"}")); } -ZERO_ARGS(bitcoinrpc,getbestblockhash) +TWO_STRINGS(iguana,oneshot,activecoin,ipaddr) { - cJSON *retjson; - if ( coin->notarychain >= 0 && coin->FULLNODE == 0 ) - return(_dex_getbestblockhash(myinfo,coin->symbol)); - retjson = cJSON_CreateObject(); - char str[65]; jaddstr(retjson,"result",bits256_str(str,coin->blocks.hwmchain.RO.hash2)); - return(jprint(retjson,1)); + if ( coin != 0 && ipaddr != 0 ) + { + iguana_possible_peer(coin,ipaddr); + return(clonestr("{\"result\":\"addnode submitted\"}")); + } else return(clonestr("{\"error\":\"addnode needs coin and ipaddr\"}")); } -ZERO_ARGS(bitcoinrpc,getblockcount) +cJSON *iguana_peerjson(struct iguana_info *coin,struct iguana_peer *addr) { - cJSON *retjson = cJSON_CreateObject(); - //printf("result %d\n",coin->blocks.hwmchain.height); - jaddnum(retjson,"result",coin->blocks.hwmchain.height); - return(jprint(retjson,1)); + cJSON *array,*json = cJSON_CreateObject(); + jaddstr(json,"ipaddr",addr->ipaddr); + if ( addr->supernet != 0 ) + jaddstr(json,"ipaddr",addr->ipaddr); + jaddstr(json,"supernet","yes"); + jaddnum(json,"protover",addr->protover); + jaddnum(json,"relay",addr->relayflag); + jaddnum(json,"height",addr->height); + jaddnum(json,"rank",addr->rank); + jaddnum(json,"usock",addr->usock); + if ( addr->dead != 0 ) + jaddnum(json,"dead",addr->dead); + jaddnum(json,"ready",addr->ready); + jaddnum(json,"recvblocks",addr->recvblocks); + jaddnum(json,"recvtotal",addr->recvtotal); + jaddnum(json,"lastcontact",addr->lastcontact); + if ( addr->numpings > 0 ) + jaddnum(json,"aveping",addr->pingsum/addr->numpings); + array = cJSON_CreateObject(); + jaddnum(array,"version",addr->msgcounts.version); + jaddnum(array,"verack",addr->msgcounts.verack); + jaddnum(array,"getaddr",addr->msgcounts.getaddr); + jaddnum(array,"addr",addr->msgcounts.addr); + jaddnum(array,"inv",addr->msgcounts.inv); + jaddnum(array,"getdata",addr->msgcounts.getdata); + jaddnum(array,"notfound",addr->msgcounts.notfound); + jaddnum(array,"getblocks",addr->msgcounts.getblocks); + jaddnum(array,"getheaders",addr->msgcounts.getheaders); + jaddnum(array,"headers",addr->msgcounts.headers); + jaddnum(array,"tx",addr->msgcounts.tx); + jaddnum(array,"block",addr->msgcounts.block); + jaddnum(array,"mempool",addr->msgcounts.mempool); + jaddnum(array,"ping",addr->msgcounts.ping); + jaddnum(array,"pong",addr->msgcounts.pong); + jaddnum(array,"reject",addr->msgcounts.reject); + jaddnum(array,"filterload",addr->msgcounts.filterload); + jaddnum(array,"filteradd",addr->msgcounts.filteradd); + jaddnum(array,"filterclear",addr->msgcounts.filterclear); + jaddnum(array,"merkleblock",addr->msgcounts.merkleblock); + jaddnum(array,"alert",addr->msgcounts.alert); + jadd(json,"msgcounts",array); + return(json); } -STRING_AND_INT(iguana,bundleaddresses,activecoin,height) +cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly) { - struct iguana_info *ptr; - if ( (ptr= iguana_coinfind(activecoin)) != 0 ) - return(iguana_bundleaddrs(ptr,height / coin->chain->bundlesize)); - else return(clonestr("{\"error\":\"activecoin is not active\"}")); + cJSON *retjson,*array; int32_t i; struct iguana_peer *addr; + if ( coin == 0 || coin->peers == 0 ) + return(0); + array = cJSON_CreateArray(); + for (i=0; iMAXPEERS; i++) + { + addr = &coin->peers->active[i]; + if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 ) + { + if ( addronly != 0 ) + jaddistr(array,addr->ipaddr); + else jaddi(array,iguana_peerjson(coin,addr)); + } + } + if ( addronly == 0 ) + { + retjson = cJSON_CreateObject(); + jadd(retjson,"peers",array); + jaddnum(retjson,"maxpeers",coin->MAXPEERS); + jaddstr(retjson,"coin",coin->symbol); + return(retjson); + } + else return(array); } -STRING_AND_INT(iguana,PoSweights,activecoin,height) +TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr) { - struct iguana_info *ptr; int32_t num,nonz,errs,bundleheight; struct iguana_pkhash *refP; uint64_t *weights,supply; cJSON *retjson; - if ( (ptr= iguana_coinfind(activecoin)) != 0 ) + int32_t i; struct iguana_peer *addr; + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) { - //for (bundleheight=coin->chain->bundlesize; bundleheightchain->bundlesize) + for (i=0; iMAXPEERS; i++) { - bundleheight = (height / ptr->chain->bundlesize) * ptr->chain->bundlesize; - if ( (weights= iguana_PoS_weights(myinfo,ptr,&refP,&supply,&num,&nonz,&errs,bundleheight)) != 0 ) - { - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result",errs == 0 ? "success" : "error"); - jaddnum(retjson,"bundleheight",bundleheight); - jaddnum(retjson,"numaddresses",num); - jaddnum(retjson,"nonzero",nonz); - jaddnum(retjson,"errors",errs); - jaddnum(retjson,"supply",dstr(supply)); - free(weights); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"iguana_PoS_weights returned null\"}")); + addr = &coin->peers->active[i]; + if ( strcmp(addr->ipaddr,ipaddr) == 0 ) + return(jprint(iguana_peerjson(coin,addr),1)); } - } - return(clonestr("{\"error\":\"activecoin is not active\"}")); + return(clonestr("{\"result\":\"nodestatus couldnt find ipaddr\"}")); + } else return(clonestr("{\"error\":\"nodestatus needs ipaddr\"}")); } -STRING_ARG(iguana,stakers,activecoin) +STRING_AND_INT(iguana,maxpeers,activecoin,max) { - struct iguana_info *ptr; int32_t i,datalen,pkind,hdrsi; bits256 hash2; struct iguana_bundle *bp; cJSON *retjson,*array; struct iguana_pkhash *refP; struct iguana_ramchaindata *rdata; char coinaddr[64]; uint8_t refrmd160[20]; bits256 *sortbuf; - if ( (ptr= iguana_coinfind(activecoin)) != 0 && ptr->RTheight > ptr->chain->bundlesize ) + cJSON *retjson; int32_t i; struct iguana_peer *addr; + if ( coin != 0 && coin->peers != 0 ) { - hdrsi = (ptr->RTheight / ptr->chain->bundlesize) - 1; - if ( (bp= ptr->bundles[hdrsi]) != 0 && bp->weights != 0 && (rdata= bp->ramchain.H.data) != 0 && bp->weights != 0 ) + retjson = cJSON_CreateObject(); + if ( max > IGUANA_MAXPEERS ) + max = IGUANA_MAXPEERS; + if ( max > coin->MAXPEERS ) { - sortbuf = calloc(bp->numweights,2 * sizeof(*sortbuf)); - for (i=datalen=0; inumweights; i++) - datalen += iguana_rwnum(1,&((uint8_t *)sortbuf)[datalen],sizeof(bp->weights[i]),(void *)&bp->weights[i]); - hash2 = bits256_doublesha256(0,(uint8_t *)sortbuf,datalen); - refP = RAMCHAIN_PTR(rdata,Poffset); - retjson = cJSON_CreateObject(); - array = cJSON_CreateArray(); - memset(refrmd160,0,sizeof(refrmd160)); - for (i=0; ichain->bundlesize; i++) - { - if ( (pkind= iguana_staker_sort(ptr,&hash2,refrmd160,refP,bp->weights,bp->numweights,sortbuf)) > 0 ) - { - bitcoin_address(coinaddr,ptr->chain->pubtype,refP[pkind].rmd160,sizeof(refP[pkind].rmd160)); - jaddistr(array,coinaddr); - } else jaddistr(array,"error"); - } - jaddstr(retjson,"result","success"); - jadd(retjson,"stakers",array); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"iguana_stakers needs PoSweights and weights\"}")); - } - return(clonestr("{\"error\":\"activecoin is not active\"}")); + for (i=max; iMAXPEERS; i++) + if ( (addr= coin->peers->ranked[i]) != 0 ) + addr->dead = 1; + } + coin->MAXPEERS = max; + jaddnum(retjson,"maxpeers",coin->MAXPEERS); + jaddstr(retjson,"coin",coin->symbol); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"maxpeers needs coin\"}")); } -STRING_AND_INT(iguana,bundlehashes,activecoin,height) +char *hmac_dispatch(char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message),char *name,char *message,char *password) { - struct iguana_info *ptr; struct iguana_bundle *bp; int32_t i,hdrsi; cJSON *retjson,*array; struct iguana_ramchaindata *rdata; - if ( (ptr= iguana_coinfind(activecoin)) != 0 ) + char hexstr[1025]; cJSON *json; + if ( message != 0 && password != 0 && message[0] != 0 && password[0] != 0 ) { - hdrsi = height / coin->chain->bundlesize; - if ( hdrsi < coin->bundlescount && hdrsi >= 0 && (bp= coin->bundles[hdrsi]) != 0 ) - { - if ( (rdata= bp->ramchain.H.data) != 0 ) - { - array = cJSON_CreateArray(); - for (i=0; ilhashes[i].txid); - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result","success"); - jaddbits256(retjson,"sha256",rdata->sha256); - jadd(retjson,"bundlehashes",array); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"ramchain not there\"}")); - } else return(clonestr("{\"error\":\"height is too big\"}")); - } else return(clonestr("{\"error\":\"activecoin is not active\"}")); + memset(hexstr,0,sizeof(hexstr)); + (*hmacfunc)(hexstr,password,password==0?0:(int32_t)strlen(password),message); + json = cJSON_CreateObject(); + jaddstr(json,"result","hmac calculated"); + jaddstr(json,"message",message); + jaddstr(json,name,hexstr); + return(jprint(json,1)); + } else return(clonestr("{\"error\":\"hmac needs message and passphrase\"}")); } -// low priority RPC +char *hash_dispatch(void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len),char *name,char *message) +{ + char hexstr[65537]; uint8_t databuf[32768]; cJSON *json; + if ( message != 0 && message[0] != 0 ) + { + memset(hexstr,0,sizeof(hexstr)); + (*hashfunc)(hexstr,databuf,(uint8_t *)message,(int32_t)strlen(message)); + json = cJSON_CreateObject(); + jaddstr(json,"result","hash calculated"); + jaddstr(json,"message",message); + jaddstr(json,name,hexstr); + return(jprint(json,1)); + } else return(clonestr("{\"error\":\"hash needs message\"}")); +} -HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag) +TWO_HASHES(hash,curve25519_pair,element,scalar) { - /*"transactions" : [ - { - "account" : "doc test", - "address" : "mmXgiR6KAhZCyQ8ndr2BCfEq1wNG2UnyG6", - "category" : "receive", - "amount" : 0.10000000, - "vout" : 0, - "confirmations" : 76478, - "blockhash" : "000000000017c84015f254498c62a7c884a51ccd75d4dd6dbdcb6434aa3bd44d", - "blockindex" : 1, - "blocktime" : 1399294967, - "txid" : "85a98fdf1529f7d5156483ad020a51b7f3340e47448cf932f470b72ff01a6821", - "walletconflicts" : [ - ], - "time" : 1399294967, - "timereceived" : 1418924714 - },*/ cJSON *retjson = cJSON_CreateObject(); - jaddstr(retjson,"error","low priority RPC not implemented"); + jaddbits256(retjson,"result",curve25519(element,scalar)); return(jprint(retjson,1)); } -ZERO_ARGS(bitcoinrpc,gettxoutsetinfo) +STRING_ARG(hash,NXT,passphrase) { return(hash_dispatch(calc_NXTaddr,"NXT",passphrase)); } +STRING_ARG(hash,curve25519,pubkey) { return(hash_dispatch(calc_curve25519_str,"curve25519",pubkey)); } +STRING_ARG(hash,crc32,message) { return(hash_dispatch(calc_crc32str,"crc32",message)); } +STRING_ARG(hash,base64_encode,message) { return(hash_dispatch(calc_base64_encodestr,"base64_encode",message)); } +STRING_ARG(hash,base64_decode,message) { return(hash_dispatch(calc_base64_decodestr,"base64_decode",message)); } +STRING_ARG(hash,rmd160_sha256,message) { return(hash_dispatch(rmd160ofsha256,"rmd160_sha256",message)); } +STRING_ARG(hash,sha256_sha256,message) { return(hash_dispatch(sha256_sha256,"sha256_sha256",message)); } +STRING_ARG(hash,hex,message) { return(hash_dispatch(calc_hexstr,"hex",message)); } +STRING_ARG(hash,unhex,message) { return(hash_dispatch(calc_unhexstr,"unhex",message)); } + +STRING_ARG(hash,sha224,message) { return(hash_dispatch(calc_sha224,"sha224",message)); } +STRING_ARG(hash,sha256,message) { return(hash_dispatch(vcalc_sha256,"sha256",message)); } +STRING_ARG(hash,sha384,message) { return(hash_dispatch(calc_sha384,"sha384",message)); } +STRING_ARG(hash,sha512,message) { return(hash_dispatch(calc_sha512,"sha512",message)); } +STRING_ARG(hash,rmd128,message) { return(hash_dispatch(calc_rmd128,"rmd128",message)); } +STRING_ARG(hash,rmd160,message) { return(hash_dispatch(calc_rmd160,"rmd160",message)); } +STRING_ARG(hash,rmd256,message) { return(hash_dispatch(calc_rmd256,"rmd256",message)); } +STRING_ARG(hash,rmd320,message) { return(hash_dispatch(calc_rmd320,"rmd320",message)); } +STRING_ARG(hash,sha1,message) { return(hash_dispatch(calc_sha1,"sha1",message)); } +STRING_ARG(hash,md2,message) { return(hash_dispatch(calc_md2str,"md2",message)); } +STRING_ARG(hash,md4,message) { return(hash_dispatch(calc_md4str,"md4",message)); } +STRING_ARG(hash,md5,message) { return(hash_dispatch(calc_md5str,"md5",message)); } +STRING_ARG(hash,tiger192_3,message) { return(hash_dispatch(calc_tiger,"tiger",message)); } +STRING_ARG(hash,whirlpool,message) { return(hash_dispatch(calc_whirlpool,"whirlpool",message)); } +TWO_STRINGS(hmac,sha224,message,passphrase) { return(hmac_dispatch(hmac_sha224_str,"sha224",message,passphrase)); } +TWO_STRINGS(hmac,sha256,message,passphrase) { return(hmac_dispatch(hmac_sha256_str,"sha256",message,passphrase)); } +TWO_STRINGS(hmac,sha384,message,passphrase) { return(hmac_dispatch(hmac_sha384_str,"sha384",message,passphrase)); } +TWO_STRINGS(hmac,sha512,message,passphrase) { return(hmac_dispatch(hmac_sha512_str,"sha512",message,passphrase)); } +TWO_STRINGS(hmac,rmd128,message,passphrase) { return(hmac_dispatch(hmac_rmd128_str,"rmd128",message,passphrase)); } +TWO_STRINGS(hmac,rmd160,message,passphrase) { return(hmac_dispatch(hmac_rmd160_str,"rmd160",message,passphrase)); } +TWO_STRINGS(hmac,rmd256,message,passphrase) { return(hmac_dispatch(hmac_rmd256_str,"rmd256",message,passphrase)); } +TWO_STRINGS(hmac,rmd320,message,passphrase) { return(hmac_dispatch(hmac_rmd320_str,"rmd320",message,passphrase)); } +TWO_STRINGS(hmac,sha1,message,passphrase) { return(hmac_dispatch(hmac_sha1_str,"sha1",message,passphrase)); } +TWO_STRINGS(hmac,md2,message,passphrase) { return(hmac_dispatch(hmac_md2_str,"md2",message,passphrase)); } +TWO_STRINGS(hmac,md4,message,passphrase) { return(hmac_dispatch(hmac_md4_str,"md4",message,passphrase)); } +TWO_STRINGS(hmac,md5,message,passphrase) { return(hmac_dispatch(hmac_md5_str,"md5",message,passphrase)); } +TWO_STRINGS(hmac,tiger192_3,message,passphrase) { return(hmac_dispatch(hmac_tiger_str,"tiger",message,passphrase)); } +TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirlpool_str,"whirlpool",message,passphrase)); } + +STRING_ARG(SuperNET,bitcoinrpc,setcoin) { - cJSON *retjson = cJSON_CreateObject(); - jaddstr(retjson,"error","low priority RPC not implemented"); - return(jprint(retjson,1)); + char buf[1024]; + if ( setcoin != 0 && setcoin[0] != 0 ) + { + strcpy(myinfo->rpcsymbol,setcoin); + touppercase(myinfo->rpcsymbol); + printf("bitcoinrpc.%s\n",myinfo->rpcsymbol); + if ( iguana_launchcoin(myinfo,myinfo->rpcsymbol,json,0) < 0 ) + return(clonestr("{\"error\":\"error creating coin\"}")); + else + { + sprintf(buf,"{\"result\":\"success\",\"setcoin\":\"%s\"}",setcoin); + return(clonestr(buf)); + } + } else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}")); } -ZERO_ARGS(bitcoinrpc,listaddressgroupings) +ZERO_ARGS(SuperNET,help) { - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - return(clonestr("{\"error\":\"low priority RPC not implemented\"}")); + cJSON *helpjson,*retjson; + if ( (helpjson= SuperNET_helpjson()) != 0 ) + { + retjson = cJSON_CreateObject(); + jadd(retjson,"result",helpjson); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"cant get helpjson\"}")); } -SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment) +TWO_STRINGS(SuperNET,html,agentform,htmlfile) { - cJSON *retjson; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - if ( myinfo->expiration == 0 ) - return(clonestr("{\"error\":\"need to unlock wallet\"}")); + char *htmlstr; cJSON *retjson; int32_t max = 4*1024*1024; + if ( htmlfile == 0 || htmlfile[0] == 0 ) + htmlfile = "forms.html"; + //if ( (fp= fopen(htmlfile,"w")) == 0 ) + // printf("error opening htmlfile.(%s)\n",htmlfile); + htmlstr = malloc(max); + htmlstr = SuperNET_htmlstr(htmlfile,htmlstr,max,agentform); retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",htmlstr); + free(htmlstr); + //if ( fp != 0 ) + // fclose(fp); return(jprint(retjson,1)); } -ZERO_ARGS(pax,start) -{ - void PAX_init(); - PAX_init(); - return(clonestr("{\"result\":\"PAX_init called\"}")); -} #undef IGUANA_ARGS +#undef _IGUANA_APIDEC_H_ #include "../includes/iguana_apiundefs.h" diff --git a/iguana/tests/DEXinit b/iguana/tests/DEXinit new file mode 100755 index 000000000..63e43fe15 --- /dev/null +++ b/iguana/tests/DEXinit @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"init\"}" diff --git a/iguana/tests/KMD.batch12 b/iguana/tests/KMD.batch12 new file mode 100755 index 000000000..f4b24ca4a --- /dev/null +++ b/iguana/tests/KMD.batch12 @@ -0,0 +1,141 @@ +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762, REVS 31.12033224 +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762 +./komodo-cli sendtoaddress RDTjem9CP97XPXvet1sQBb428xrmSZJSsd 1568.45531762 +sleep 3 +echo "1568.45531762 <- expected amount RDTjem9CP97XPXvet1sQBb428xrmSZJSsd" + +# RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz KMD 73430.96919475 +./komodo-cli sendtoaddress RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz 73430.96919475 +sleep 3 +echo "73430.96919475 <- expected amount RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz" + +# RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE KMD 5689.04575312 +./komodo-cli sendtoaddress RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE 5689.04575312 +sleep 3 +echo "5689.04575312 <- expected amount RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE" + +# RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT KMD 17817.00058850 +./komodo-cli sendtoaddress RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT 17817.00058850 +sleep 3 +echo "17817.00058850 <- expected amount RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT" + +# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 202518.10752377 +./komodo-cli sendtoaddress RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB 202518.10752377 +sleep 3 +echo "202518.10752377 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB" + +# RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf KMD 6963.60677351 +./komodo-cli sendtoaddress RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf 6963.60677351 +sleep 3 +echo "6963.60677351 <- expected amount RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf" + +# RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv KMD 32042.52085087 +./komodo-cli sendtoaddress RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv 32042.52085087 +sleep 3 +echo "32042.52085087 <- expected amount RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv" + +# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 2135.12309659 +./komodo-cli sendtoaddress RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A 2135.12309659 +sleep 3 +echo "2135.12309659 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A" + +# RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic KMD 5533.00461690 +./komodo-cli sendtoaddress RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic 5533.00461690 +sleep 3 +echo "5533.00461690 <- expected amount RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic" + +# RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i KMD 50.26846585 +./komodo-cli sendtoaddress RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i 50.26846585 +sleep 3 +echo "50.26846585 <- expected amount RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i" + +# RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7 KMD 1733.05190072 +./komodo-cli sendtoaddress RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7 1733.05190072 +sleep 3 +echo "1733.05190072 <- expected amount RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7" + +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290, REVS 139.09398517 +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290 +./komodo-cli sendtoaddress RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y 11852.83167290 +sleep 3 +echo "11852.83167290 <- expected amount RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y" + +# RH9CANWQNvqSktmX39ruDfiNFimcToD2ur KMD 43125.33019700 +./komodo-cli sendtoaddress RH9CANWQNvqSktmX39ruDfiNFimcToD2ur 43125.33019700 +sleep 3 +echo "43125.33019700 <- expected amount RH9CANWQNvqSktmX39ruDfiNFimcToD2ur" + +# RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b KMD 36837.09249870 +./komodo-cli sendtoaddress RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b 36837.09249870 +sleep 3 +echo "36837.09249870 <- expected amount RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b" + +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526, REVS 59.85500000 +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526 +./komodo-cli sendtoaddress RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 3016.26045526 +sleep 3 +echo "3016.26045526 <- expected amount RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8" + +# RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb KMD 91240.39653929 +./komodo-cli sendtoaddress RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb 91240.39653929 +sleep 3 +echo "91240.39653929 <- expected amount RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb" + +# RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury KMD 2440.00507548 +./komodo-cli sendtoaddress RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury 2440.00507548 +sleep 3 +echo "2440.00507548 <- expected amount RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury" + +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934, REVS 75.88015839 +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934 +./komodo-cli sendtoaddress RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX 3823.81289934 +sleep 3 +echo "3823.81289934 <- expected amount RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX" + +# RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz KMD 2772.48246697 +./komodo-cli sendtoaddress RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz 2772.48246697 +sleep 3 +echo "2772.48246697 <- expected amount RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz" + +# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289 +./komodo-cli sendtoaddress RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv 693.08132289 +sleep 3 +echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv" + +# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 10316.17621736 +./komodo-cli sendtoaddress RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut 10316.17621736 +sleep 3 +echo "10316.17621736 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut" + +# RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW KMD 29566.93551966 +./komodo-cli sendtoaddress RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW 29566.93551966 +sleep 3 +echo "29566.93551966 <- expected amount RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW" + +# RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX KMD 19365.33667225 +./komodo-cli sendtoaddress RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX 19365.33667225 +sleep 3 +echo "19365.33667225 <- expected amount RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX" + +# R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X KMD 55229.13842423 +./komodo-cli sendtoaddress R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X 55229.13842423 +sleep 3 +echo "55229.13842423 <- expected amount R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X" + +# RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB KMD 29049.45748125 +./komodo-cli sendtoaddress RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB 29049.45748125 +sleep 3 +echo "29049.45748125 <- expected amount RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB" + +# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 10066.89321267 +./komodo-cli sendtoaddress RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 10066.89321267 +sleep 3 +echo "10066.89321267 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47" + +# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 2834.17657315 +./komodo-cli sendtoaddress RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ 2834.17657315 +sleep 3 +echo "2834.17657315 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ" + + +# total KMD 701710.56131060 REVS 0.00000000 diff --git a/iguana/tests/KMD.batch12.importaddress b/iguana/tests/KMD.batch12.importaddress new file mode 100755 index 000000000..c140a3396 --- /dev/null +++ b/iguana/tests/KMD.batch12.importaddress @@ -0,0 +1,139 @@ +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762, REVS 31.12033224 +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RDTjem9CP97XPXvet1sQBb428xrmSZJSsd\",\"symbol\":\"KMD\"}" # 1568.45531762 +sleep 3 +echo "1568.45531762 <- expected amount RDTjem9CP97XPXvet1sQBb428xrmSZJSsd" + +# RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz KMD 73430.96919475 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz\",\"symbol\":\"KMD\"}" # 73430.96919475 +sleep 3 +echo "73430.96919475 <- expected amount RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz" + +# RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE KMD 5689.04575312 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE\",\"symbol\":\"KMD\"}" # 5689.04575312 +sleep 3 +echo "5689.04575312 <- expected amount RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE" + +# RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT KMD 17817.00058850 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT\",\"symbol\":\"KMD\"}" # 17817.00058850 +sleep 3 +echo "17817.00058850 <- expected amount RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT" + +# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 202518.10752377 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB\",\"symbol\":\"KMD\"}" # 202518.10752377 +sleep 3 +echo "202518.10752377 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB" + +# RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf KMD 6963.60677351 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf\",\"symbol\":\"KMD\"}" # 6963.60677351 +sleep 3 +echo "6963.60677351 <- expected amount RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf" + +# RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv KMD 32042.52085087 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv\",\"symbol\":\"KMD\"}" # 32042.52085087 +sleep 3 +echo "32042.52085087 <- expected amount RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv" + +# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 2135.12309659 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A\",\"symbol\":\"KMD\"}" # 2135.12309659 +sleep 3 +echo "2135.12309659 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A" + +# RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic KMD 5533.00461690 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic\",\"symbol\":\"KMD\"}" # 5533.00461690 +sleep 3 +echo "5533.00461690 <- expected amount RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic" + +# RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i KMD 50.26846585 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i\",\"symbol\":\"KMD\"}" # 50.26846585 +sleep 3 +echo "50.26846585 <- expected amount RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i" + +# RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7 KMD 1733.05190072 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7\",\"symbol\":\"KMD\"}" # 1733.05190072 +sleep 3 +echo "1733.05190072 <- expected amount RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7" + +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290, REVS 139.09398517 +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y\",\"symbol\":\"KMD\"}" # 11852.83167290 +sleep 3 +echo "11852.83167290 <- expected amount RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y" + +# RH9CANWQNvqSktmX39ruDfiNFimcToD2ur KMD 43125.33019700 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RH9CANWQNvqSktmX39ruDfiNFimcToD2ur\",\"symbol\":\"KMD\"}" # 43125.33019700 +sleep 3 +echo "43125.33019700 <- expected amount RH9CANWQNvqSktmX39ruDfiNFimcToD2ur" + +# RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b KMD 36837.09249870 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b\",\"symbol\":\"KMD\"}" # 36837.09249870 +sleep 3 +echo "36837.09249870 <- expected amount RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b" + +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526, REVS 59.85500000 +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8\",\"symbol\":\"KMD\"}" # 3016.26045526 +sleep 3 +echo "3016.26045526 <- expected amount RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8" + +# RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb KMD 91240.39653929 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb\",\"symbol\":\"KMD\"}" # 91240.39653929 +sleep 3 +echo "91240.39653929 <- expected amount RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb" + +# RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury KMD 2440.00507548 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury\",\"symbol\":\"KMD\"}" # 2440.00507548 +sleep 3 +echo "2440.00507548 <- expected amount RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury" + +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934, REVS 75.88015839 +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX\",\"symbol\":\"KMD\"}" # 3823.81289934 +sleep 3 +echo "3823.81289934 <- expected amount RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX" + +# RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz KMD 2772.48246697 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz\",\"symbol\":\"KMD\"}" # 2772.48246697 +sleep 3 +echo "2772.48246697 <- expected amount RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz" + +# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv\",\"symbol\":\"KMD\"}" # 693.08132289 +sleep 3 +echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv" + +# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 10316.17621736 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut\",\"symbol\":\"KMD\"}" # 10316.17621736 +sleep 3 +echo "10316.17621736 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut" + +# RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW KMD 29566.93551966 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW\",\"symbol\":\"KMD\"}" # 29566.93551966 +sleep 3 +echo "29566.93551966 <- expected amount RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW" + +# RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX KMD 19365.33667225 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX\",\"symbol\":\"KMD\"}" # 19365.33667225 +sleep 3 +echo "19365.33667225 <- expected amount RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX" + +# R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X KMD 55229.13842423 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X\",\"symbol\":\"KMD\"}" # 55229.13842423 +sleep 3 +echo "55229.13842423 <- expected amount R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X" + +# RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB KMD 29049.45748125 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB\",\"symbol\":\"KMD\"}" # 29049.45748125 +sleep 3 +echo "29049.45748125 <- expected amount RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB" + +# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 10066.89321267 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47\",\"symbol\":\"KMD\"}" # 10066.89321267 +sleep 3 +echo "10066.89321267 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47" + +# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 2834.17657315 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ\",\"symbol\":\"KMD\"}" # 2834.17657315 +sleep 3 +echo "2834.17657315 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ" + diff --git a/iguana/tests/KMD.batch12.listunspent b/iguana/tests/KMD.batch12.listunspent new file mode 100755 index 000000000..11e9bfdd0 --- /dev/null +++ b/iguana/tests/KMD.batch12.listunspent @@ -0,0 +1,112 @@ +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762, REVS 31.12033224 +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RDTjem9CP97XPXvet1sQBb428xrmSZJSsd\",\"symbol\":\"KMD\"}" +echo "1568.45531762 <- expected amount RDTjem9CP97XPXvet1sQBb428xrmSZJSsd" + +# RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz KMD 73430.96919475 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz\",\"symbol\":\"KMD\"}" +echo "73430.96919475 <- expected amount RAvtq1kazCRZUvWvPsN7ioY2Vt1EYtgpuz" + +# RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE KMD 5689.04575312 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE\",\"symbol\":\"KMD\"}" +echo "5689.04575312 <- expected amount RWxT4Jfwp1Bv6RYdUMdrQ6oXt6dMsQZ8jE" + +# RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT KMD 17817.00058850 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT\",\"symbol\":\"KMD\"}" +echo "17817.00058850 <- expected amount RXQxetCQScefabaJaFyqCJ1FvfNwsKtvMT" + +# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 202518.10752377 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB\",\"symbol\":\"KMD\"}" +echo "202518.10752377 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB" + +# RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf KMD 6963.60677351 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf\",\"symbol\":\"KMD\"}" +echo "6963.60677351 <- expected amount RH4SXj2zZqfG4TfejyHcVpaoPoDv1Uonnf" + +# RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv KMD 32042.52085087 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv\",\"symbol\":\"KMD\"}" +echo "32042.52085087 <- expected amount RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv" + +# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 2135.12309659 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A\",\"symbol\":\"KMD\"}" +echo "2135.12309659 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A" + +# RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic KMD 5533.00461690 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic\",\"symbol\":\"KMD\"}" +echo "5533.00461690 <- expected amount RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic" + +# RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i KMD 50.26846585 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i\",\"symbol\":\"KMD\"}" +echo "50.26846585 <- expected amount RDoLVY35wbzTXZ9QgFRSAzHfAiYYG7e65i" + +# RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7 KMD 1733.05190072 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7\",\"symbol\":\"KMD\"}" +echo "1733.05190072 <- expected amount RMHZ76hvxs8n2yDnkUa122rs5gubMxhiw7" + +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290, REVS 139.09398517 +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y\",\"symbol\":\"KMD\"}" +echo "11852.83167290 <- expected amount RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y" + +# RH9CANWQNvqSktmX39ruDfiNFimcToD2ur KMD 43125.33019700 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RH9CANWQNvqSktmX39ruDfiNFimcToD2ur\",\"symbol\":\"KMD\"}" +echo "43125.33019700 <- expected amount RH9CANWQNvqSktmX39ruDfiNFimcToD2ur" + +# RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b KMD 36837.09249870 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b\",\"symbol\":\"KMD\"}" +echo "36837.09249870 <- expected amount RSp4ceoTDQt7fbweFBpEbvbTTH8J9SEp4b" + +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526, REVS 59.85500000 +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8\",\"symbol\":\"KMD\"}" +echo "3016.26045526 <- expected amount RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8" + +# RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb KMD 91240.39653929 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb\",\"symbol\":\"KMD\"}" +echo "91240.39653929 <- expected amount RLWvbjH97gqjGXsRyPijDmwuKNFqsaaerb" + +# RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury KMD 2440.00507548 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury\",\"symbol\":\"KMD\"}" +echo "2440.00507548 <- expected amount RGoB4uxdk2SDs5yCerizsQ3UFD7NqJjury" + +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934, REVS 75.88015839 +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX\",\"symbol\":\"KMD\"}" +echo "3823.81289934 <- expected amount RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX" + +# RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz KMD 2772.48246697 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz\",\"symbol\":\"KMD\"}" +echo "2772.48246697 <- expected amount RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz" + +# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv\",\"symbol\":\"KMD\"}" +echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv" + +# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 10316.17621736 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut\",\"symbol\":\"KMD\"}" +echo "10316.17621736 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut" + +# RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW KMD 29566.93551966 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW\",\"symbol\":\"KMD\"}" +echo "29566.93551966 <- expected amount RAGGPNoZgxAj6ABBTwehQfVYEa1PEN4qZW" + +# RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX KMD 19365.33667225 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX\",\"symbol\":\"KMD\"}" +echo "19365.33667225 <- expected amount RNQzdseaqPikT6Df2ECFQXxW4yUr4fahqX" + +# R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X KMD 55229.13842423 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X\",\"symbol\":\"KMD\"}" +echo "55229.13842423 <- expected amount R9PwsNzuksjJzZUAAX4yfDwdSy5Y4KP25X" + +# RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB KMD 29049.45748125 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB\",\"symbol\":\"KMD\"}" +echo "29049.45748125 <- expected amount RC3DmLpKZyMD66JnKXVRHT9AVcok9xwGgB" + +# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 10066.89321267 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47\",\"symbol\":\"KMD\"}" +echo "10066.89321267 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47" + +# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 2834.17657315 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ\",\"symbol\":\"KMD\"}" +echo "2834.17657315 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ" + diff --git a/iguana/tests/KMD.batch13 b/iguana/tests/KMD.batch13 new file mode 100755 index 000000000..0d9373fc4 --- /dev/null +++ b/iguana/tests/KMD.batch13 @@ -0,0 +1,147 @@ +sleep 999999 +# RTG2uSvYLnoxtxFeZJDFq2yPEqDvhTHhk2 KMD 341.29719958 +./komodo-cli sendtoaddress RTG2uSvYLnoxtxFeZJDFq2yPEqDvhTHhk2 341.29719958 +sleep 3 +echo "341.29719958 <- expected amount RTG2uSvYLnoxtxFeZJDFq2yPEqDvhTHhk2" + +# RD486qQaD85849AdDPH3Xy3iyppuvxDZYf KMD 177091.93551966 +./komodo-cli sendtoaddress RD486qQaD85849AdDPH3Xy3iyppuvxDZYf 177091.93551966 +sleep 3 +echo "177091.93551966 <- expected amount RD486qQaD85849AdDPH3Xy3iyppuvxDZYf" + +# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 10744.59269420 +./komodo-cli sendtoaddress RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 10744.59269420 +sleep 3 +echo "10744.59269420 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47" + +# RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ KMD 885.02977777 +./komodo-cli sendtoaddress RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ 885.02977777 +sleep 3 +echo "885.02977777 <- expected amount RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ" + +# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 1517.32401692 +./komodo-cli sendtoaddress RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ 1517.32401692 +sleep 3 +echo "1517.32401692 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ" + +# RPY5bFVqHKiSfTGhQgW6USqCA1fbD1auvP KMD 722.28571081 +./komodo-cli sendtoaddress RPY5bFVqHKiSfTGhQgW6USqCA1fbD1auvP 722.28571081 +sleep 3 +echo "722.28571081 <- expected amount RPY5bFVqHKiSfTGhQgW6USqCA1fbD1auvP" + +# RS12srxPnksnwwaXrSXLjhu14hBknd26aR KMD 1859.16527880 +./komodo-cli sendtoaddress RS12srxPnksnwwaXrSXLjhu14hBknd26aR 1859.16527880 +sleep 3 +echo "1859.16527880 <- expected amount RS12srxPnksnwwaXrSXLjhu14hBknd26aR" + +# RQCPDTicaag9aa9VF3Vfp97o8bTX4EW9Vw KMD 748.59289950 +./komodo-cli sendtoaddress RQCPDTicaag9aa9VF3Vfp97o8bTX4EW9Vw 748.59289950 +sleep 3 +echo "748.59289950 <- expected amount RQCPDTicaag9aa9VF3Vfp97o8bTX4EW9Vw" + +# RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy KMD 1684.62281766, REVS 33.43442069 +# RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy KMD 1684.62281766 +./komodo-cli sendtoaddress RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy 1684.62281766 +sleep 3 +echo "1684.62281766 <- expected amount RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy" + +# RNFgp4T5uusJXRa2Xy3zPxDe93NHBpw2Nc KMD 4850.29108411 +./komodo-cli sendtoaddress RNFgp4T5uusJXRa2Xy3zPxDe93NHBpw2Nc 4850.29108411 +sleep 3 +echo "4850.29108411 <- expected amount RNFgp4T5uusJXRa2Xy3zPxDe93NHBpw2Nc" + +# RCgPPsLuB9Do1RVSTpjsD27xxGvKGwr5EJ KMD 935.39253089 +./komodo-cli sendtoaddress RCgPPsLuB9Do1RVSTpjsD27xxGvKGwr5EJ 935.39253089 +sleep 3 +echo "935.39253089 <- expected amount RCgPPsLuB9Do1RVSTpjsD27xxGvKGwr5EJ" + +# RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4 KMD 86638.13975038, REVS 819.96000000 +# RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4 KMD 86638.13975038 +./komodo-cli sendtoaddress RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4 86638.13975038 +sleep 3 +echo "86638.13975038 <- expected amount RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4" + +# RTdoQxvwUbqmyF8EAX5uzNGGmWuPZLAy32 KMD 50.26846585 +./komodo-cli sendtoaddress RTdoQxvwUbqmyF8EAX5uzNGGmWuPZLAy32 50.26846585 +sleep 3 +echo "50.26846585 <- expected amount RTdoQxvwUbqmyF8EAX5uzNGGmWuPZLAy32" + +# RA5woupBAsRPAkaBVWiRsxWyoYdAV8v5pS KMD 3873.26099750 +./komodo-cli sendtoaddress RA5woupBAsRPAkaBVWiRsxWyoYdAV8v5pS 3873.26099750 +sleep 3 +echo "3873.26099750 <- expected amount RA5woupBAsRPAkaBVWiRsxWyoYdAV8v5pS" + +# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 212102.44577315 +./komodo-cli sendtoaddress RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT 212102.44577315 +sleep 3 +echo "212102.44577315 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT" + +# RPEpkD8hNeLC4eJTM3VZvem43nnbVpaetZ KMD 10486.02744190 +./komodo-cli sendtoaddress RPEpkD8hNeLC4eJTM3VZvem43nnbVpaetZ 10486.02744190 +sleep 3 +echo "10486.02744190 <- expected amount RPEpkD8hNeLC4eJTM3VZvem43nnbVpaetZ" + +# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289 +./komodo-cli sendtoaddress RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv 693.08132289 +sleep 3 +echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv" + +# RJxAyUaeV87C1evoXNPSV8qVeKygSQk4Do KMD 3389.10337281 +./komodo-cli sendtoaddress RJxAyUaeV87C1evoXNPSV8qVeKygSQk4Do 3389.10337281 +sleep 3 +echo "3389.10337281 <- expected amount RJxAyUaeV87C1evoXNPSV8qVeKygSQk4Do" + +# RKV15G5AC9HzEFVaZtYRwBLp33MaiHdHNc KMD 774.65219950 +./komodo-cli sendtoaddress RKV15G5AC9HzEFVaZtYRwBLp33MaiHdHNc 774.65219950 +sleep 3 +echo "774.65219950 <- expected amount RKV15G5AC9HzEFVaZtYRwBLp33MaiHdHNc" + +# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 190185.06275980 +./komodo-cli sendtoaddress RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB 190185.06275980 +sleep 3 +echo "190185.06275980 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB" + +# RLtagTCmTjMkWTBgM6ibGe12p7ufn9nWRg KMD 9683.15249375 +./komodo-cli sendtoaddress RLtagTCmTjMkWTBgM6ibGe12p7ufn9nWRg 9683.15249375 +sleep 3 +echo "9683.15249375 <- expected amount RLtagTCmTjMkWTBgM6ibGe12p7ufn9nWRg" + +# RSfqroC8ApjqJgTu7p4TdBp6M6sWVSYLmF KMD 8424.34266955 +./komodo-cli sendtoaddress RSfqroC8ApjqJgTu7p4TdBp6M6sWVSYLmF 8424.34266955 +sleep 3 +echo "8424.34266955 <- expected amount RSfqroC8ApjqJgTu7p4TdBp6M6sWVSYLmF" + +# R9M1LYyerZSgc6mtDVy3d4ViadhjAaSW9M KMD 6007.48089910 +./komodo-cli sendtoaddress R9M1LYyerZSgc6mtDVy3d4ViadhjAaSW9M 6007.48089910 +sleep 3 +echo "6007.48089910 <- expected amount R9M1LYyerZSgc6mtDVy3d4ViadhjAaSW9M" + +# RJgEYxCjh5HkxtU4kVaYZUQ7eBS2fEeosE KMD 534.11913087 +./komodo-cli sendtoaddress RJgEYxCjh5HkxtU4kVaYZUQ7eBS2fEeosE 534.11913087 +sleep 3 +echo "534.11913087 <- expected amount RJgEYxCjh5HkxtU4kVaYZUQ7eBS2fEeosE" + +# RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9 KMD 1.56326640 +./komodo-cli sendtoaddress RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9 1.56326640 +sleep 3 +echo "1.56326640 <- expected amount RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9" + +# RSVA6AL1Hi65zGg24YZU9GWu8Pd9ixSKuM KMD 678.12202237 +./komodo-cli sendtoaddress RSVA6AL1Hi65zGg24YZU9GWu8Pd9ixSKuM 678.12202237 +sleep 3 +echo "678.12202237 <- expected amount RSVA6AL1Hi65zGg24YZU9GWu8Pd9ixSKuM" + +# RPmxibGkVYqTSM2NcTcuxRYtha2WUeNAQE KMD 4841.57624687 +./komodo-cli sendtoaddress RPmxibGkVYqTSM2NcTcuxRYtha2WUeNAQE 4841.57624687 +sleep 3 +echo "4841.57624687 <- expected amount RPmxibGkVYqTSM2NcTcuxRYtha2WUeNAQE" + +# RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv KMD 25665.79190427 +./komodo-cli sendtoaddress RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv 25665.79190427 +sleep 3 +echo "25665.79190427 <- expected amount RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv" + +# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 6627.41635888 +./komodo-cli sendtoaddress RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut 6627.41635888 +sleep 3 +echo "6627.41635888 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut" diff --git a/iguana/tests/KMD.batch13.listunspent b/iguana/tests/KMD.batch13.listunspent new file mode 100755 index 000000000..06796ec86 --- /dev/null +++ b/iguana/tests/KMD.batch13.listunspent @@ -0,0 +1,118 @@ +# RTG2uSvYLnoxtxFeZJDFq2yPEqDvhTHhk2 KMD 341.29719958 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTG2uSvYLnoxtxFeZJDFq2yPEqDvhTHhk2\",\"symbol\":\"KMD\"}" +echo "341.29719958 <- expected amount RTG2uSvYLnoxtxFeZJDFq2yPEqDvhTHhk2" + +# RD486qQaD85849AdDPH3Xy3iyppuvxDZYf KMD 177091.93551966 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RD486qQaD85849AdDPH3Xy3iyppuvxDZYf\",\"symbol\":\"KMD\"}" +echo "177091.93551966 <- expected amount RD486qQaD85849AdDPH3Xy3iyppuvxDZYf" + +# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 10744.59269420 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47\",\"symbol\":\"KMD\"}" +echo "10744.59269420 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47" + +# RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ KMD 885.02977777 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ\",\"symbol\":\"KMD\"}" +echo "885.02977777 <- expected amount RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ" + +# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 1517.32401692 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ\",\"symbol\":\"KMD\"}" +echo "1517.32401692 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ" + +# RPY5bFVqHKiSfTGhQgW6USqCA1fbD1auvP KMD 722.28571081 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RPY5bFVqHKiSfTGhQgW6USqCA1fbD1auvP\",\"symbol\":\"KMD\"}" +echo "722.28571081 <- expected amount RPY5bFVqHKiSfTGhQgW6USqCA1fbD1auvP" + +# RS12srxPnksnwwaXrSXLjhu14hBknd26aR KMD 1859.16527880 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RS12srxPnksnwwaXrSXLjhu14hBknd26aR\",\"symbol\":\"KMD\"}" +echo "1859.16527880 <- expected amount RS12srxPnksnwwaXrSXLjhu14hBknd26aR" + +# RQCPDTicaag9aa9VF3Vfp97o8bTX4EW9Vw KMD 748.59289950 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RQCPDTicaag9aa9VF3Vfp97o8bTX4EW9Vw\",\"symbol\":\"KMD\"}" +echo "748.59289950 <- expected amount RQCPDTicaag9aa9VF3Vfp97o8bTX4EW9Vw" + +# RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy KMD 1684.62281766, REVS 33.43442069 +# RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy KMD 1684.62281766 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy\",\"symbol\":\"KMD\"}" +echo "1684.62281766 <- expected amount RLvFp2q8XmUpxnimcYUmpyC9vGr3woqTKy" + +# RNFgp4T5uusJXRa2Xy3zPxDe93NHBpw2Nc KMD 4850.29108411 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RNFgp4T5uusJXRa2Xy3zPxDe93NHBpw2Nc\",\"symbol\":\"KMD\"}" +echo "4850.29108411 <- expected amount RNFgp4T5uusJXRa2Xy3zPxDe93NHBpw2Nc" + +# RCgPPsLuB9Do1RVSTpjsD27xxGvKGwr5EJ KMD 935.39253089 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RCgPPsLuB9Do1RVSTpjsD27xxGvKGwr5EJ\",\"symbol\":\"KMD\"}" +echo "935.39253089 <- expected amount RCgPPsLuB9Do1RVSTpjsD27xxGvKGwr5EJ" + +# RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4 KMD 86638.13975038, REVS 819.96000000 +# RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4 KMD 86638.13975038 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4\",\"symbol\":\"KMD\"}" +echo "86638.13975038 <- expected amount RWXMMFMMSv6GZzP1qEKyTkeDmodAueEMp4" + +# RTdoQxvwUbqmyF8EAX5uzNGGmWuPZLAy32 KMD 50.26846585 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTdoQxvwUbqmyF8EAX5uzNGGmWuPZLAy32\",\"symbol\":\"KMD\"}" +echo "50.26846585 <- expected amount RTdoQxvwUbqmyF8EAX5uzNGGmWuPZLAy32" + +# RA5woupBAsRPAkaBVWiRsxWyoYdAV8v5pS KMD 3873.26099750 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RA5woupBAsRPAkaBVWiRsxWyoYdAV8v5pS\",\"symbol\":\"KMD\"}" +echo "3873.26099750 <- expected amount RA5woupBAsRPAkaBVWiRsxWyoYdAV8v5pS" + +# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 212102.44577315 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT\",\"symbol\":\"KMD\"}" +echo "212102.44577315 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT" + +# RPEpkD8hNeLC4eJTM3VZvem43nnbVpaetZ KMD 10486.02744190 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RPEpkD8hNeLC4eJTM3VZvem43nnbVpaetZ\",\"symbol\":\"KMD\"}" +echo "10486.02744190 <- expected amount RPEpkD8hNeLC4eJTM3VZvem43nnbVpaetZ" + +# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv\",\"symbol\":\"KMD\"}" +echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv" + +# RJxAyUaeV87C1evoXNPSV8qVeKygSQk4Do KMD 3389.10337281 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RJxAyUaeV87C1evoXNPSV8qVeKygSQk4Do\",\"symbol\":\"KMD\"}" +echo "3389.10337281 <- expected amount RJxAyUaeV87C1evoXNPSV8qVeKygSQk4Do" + +# RKV15G5AC9HzEFVaZtYRwBLp33MaiHdHNc KMD 774.65219950 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RKV15G5AC9HzEFVaZtYRwBLp33MaiHdHNc\",\"symbol\":\"KMD\"}" +echo "774.65219950 <- expected amount RKV15G5AC9HzEFVaZtYRwBLp33MaiHdHNc" + +# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 190185.06275980 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB\",\"symbol\":\"KMD\"}" +echo "190185.06275980 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB" + +# RLtagTCmTjMkWTBgM6ibGe12p7ufn9nWRg KMD 9683.15249375 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RLtagTCmTjMkWTBgM6ibGe12p7ufn9nWRg\",\"symbol\":\"KMD\"}" +echo "9683.15249375 <- expected amount RLtagTCmTjMkWTBgM6ibGe12p7ufn9nWRg" + +# RSfqroC8ApjqJgTu7p4TdBp6M6sWVSYLmF KMD 8424.34266955 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RSfqroC8ApjqJgTu7p4TdBp6M6sWVSYLmF\",\"symbol\":\"KMD\"}" +echo "8424.34266955 <- expected amount RSfqroC8ApjqJgTu7p4TdBp6M6sWVSYLmF" + +# R9M1LYyerZSgc6mtDVy3d4ViadhjAaSW9M KMD 6007.48089910 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"R9M1LYyerZSgc6mtDVy3d4ViadhjAaSW9M\",\"symbol\":\"KMD\"}" +echo "6007.48089910 <- expected amount R9M1LYyerZSgc6mtDVy3d4ViadhjAaSW9M" + +# RJgEYxCjh5HkxtU4kVaYZUQ7eBS2fEeosE KMD 534.11913087 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RJgEYxCjh5HkxtU4kVaYZUQ7eBS2fEeosE\",\"symbol\":\"KMD\"}" +echo "534.11913087 <- expected amount RJgEYxCjh5HkxtU4kVaYZUQ7eBS2fEeosE" + +# RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9 KMD 1.56326640 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9\",\"symbol\":\"KMD\"}" +echo "1.56326640 <- expected amount RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9" + +# RSVA6AL1Hi65zGg24YZU9GWu8Pd9ixSKuM KMD 678.12202237 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RSVA6AL1Hi65zGg24YZU9GWu8Pd9ixSKuM\",\"symbol\":\"KMD\"}" +echo "678.12202237 <- expected amount RSVA6AL1Hi65zGg24YZU9GWu8Pd9ixSKuM" + +# RPmxibGkVYqTSM2NcTcuxRYtha2WUeNAQE KMD 4841.57624687 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RPmxibGkVYqTSM2NcTcuxRYtha2WUeNAQE\",\"symbol\":\"KMD\"}" +echo "4841.57624687 <- expected amount RPmxibGkVYqTSM2NcTcuxRYtha2WUeNAQE" + +# RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv KMD 25665.79190427 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv\",\"symbol\":\"KMD\"}" +echo "25665.79190427 <- expected amount RXyXDkiMmU8jdnCuyCrZHqWthU4kp9PUhv" + +# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 6627.41635888 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut\",\"symbol\":\"KMD\"}" +echo "6627.41635888 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut" + diff --git a/iguana/tests/LPinit b/iguana/tests/LPinit index c7dfbb067..1905ec149 100755 --- a/iguana/tests/LPinit +++ b/iguana/tests/LPinit @@ -1,4 +1,5 @@ #!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"password\":\"3809853923098test\",\"timeout\":86444}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"amlp\"}" -#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"KMD\",\"vals\":{\"profit\":0.01}}" -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"MVP\",\"vals\":{\"rel\":\"USD\",\"bid\":0.09,\"ask\":0.11,\"maxvol\":100}}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"KMD\",\"vals\":{\"ask\":0.000077,\"bid\":0.000067,\"maxvol\":400,\"minvol\":100}}" +#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"MVP\",\"vals\":{\"rel\":\"USD\",\"bid\":0.09,\"ask\":0.11,\"maxvol\":100}}" diff --git a/iguana/tests/REVS.batch12 b/iguana/tests/REVS.batch12 new file mode 100755 index 000000000..78ad38586 --- /dev/null +++ b/iguana/tests/REVS.batch12 @@ -0,0 +1,14 @@ +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762, REVS 31.12033224 +sleep 1 +fiat/revs sendtoaddress RDTjem9CP97XPXvet1sQBb428xrmSZJSsd 31.12033224 +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290, REVS 139.09398517 +sleep 1 +fiat/revs sendtoaddress RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y 139.09398517 +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526, REVS 59.85500000 +sleep 1 +fiat/revs sendtoaddress RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 59.85500000 +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934, REVS 75.88015839 +sleep 1 +fiat/revs sendtoaddress RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX 75.88015839 + +# total KMD 0.00000000 REVS 305.94947580 diff --git a/iguana/tests/REVS.batch12.importaddress b/iguana/tests/REVS.batch12.importaddress new file mode 100755 index 000000000..53ae5be86 --- /dev/null +++ b/iguana/tests/REVS.batch12.importaddress @@ -0,0 +1,12 @@ +# RDTjem9CP97XPXvet1sQBb428xrmSZJSsd KMD 1568.45531762, REVS 31.12033224 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RDTjem9CP97XPXvet1sQBb428xrmSZJSsd\",\"symbol\":\"REVS\"}" # 31.12033224 +sleep 3 +# RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y KMD 11852.83167290, REVS 139.09398517 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHmVdfQM3PbJayYGbYnGtsqiWD9gDt2n4y\",\"symbol\":\"REVS\"}" # 139.09398517 +sleep 3 +# RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8 KMD 3016.26045526, REVS 59.85500000 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RUbMmLRMeSf2xnBHspdzS2JC3e8epKmoM8\",\"symbol\":\"REVS\"}" # 59.85500000 +sleep 3 +# RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX KMD 3823.81289934, REVS 75.88015839 +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RXQBgNYtszvmdwniLu1nteS9MX1xD75bNX\",\"symbol\":\"REVS\"}" # 75.88015839 +sleep 3 diff --git a/iguana/tests/amlp b/iguana/tests/amlp index 4a771e030..76856c320 100755 --- a/iguana/tests/amlp +++ b/iguana/tests/amlp @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"amlp\",\"blocktrail\":\"blocktrail_apikey\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"amlp\",\"blocktrail\":\"e5ddfdceb58fa6c1bf9411aaeff4b6ee28cbc370\"}" diff --git a/iguana/tests/cancelrefresh b/iguana/tests/cancelrefresh new file mode 100755 index 000000000..35c27504d --- /dev/null +++ b/iguana/tests/cancelrefresh @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"cancelrefresh\"}" diff --git a/iguana/tests/crash b/iguana/tests/crash new file mode 100755 index 000000000..90be8a6d1 --- /dev/null +++ b/iguana/tests/crash @@ -0,0 +1,7 @@ +../coins/basilisk/kmd + +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"encryptwallet\",\"passphrase\":\"amount common obey erupt ensure salon shrug digital phone vacant provide word nurse legend shaft ritual strike black fiscal circle dove tone inmate plunge\",\"timeout\":864445678904}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"password\":\"amount common obey erupt ensure salon shrug digital phone vacant provide word nurse legend shaft ritual strike black fiscal circle dove tone inmate plunge\",\"timeout\":864445678904}" + +curl --url "http://127.0.0.1:7778" --data "{\"symbol\":\"KMD\",\"agent\":\"basilisk\",\"method\":\"utxorawtx\",\"vals\":{\"timelock\":0,\"changeaddr\":\"RD5Sj6igy53nscMiFS4ECXByfqVeyV9NdG\",\"destaddr\":\"RD5Sj6igy53nscMiFS4ECXByfqVeyV9NdG\",\"txfee\":0,\"amount\":0.0001,\"sendflag\":0},\"utxos\":[{\"bestblock\":\"0000119186ecfaa8d72a7d3c62e78135043db220a6d29a9605f1fbe383bcedfb\",\"confirmations\":65549,\"value\":0.04900000,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 29a7bd36e6913b674bb2b5c65e61a6544426ddd7 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a91429a7bd36e6913b674bb2b5c65e61a6544426ddd788ac\",\"reqSigs\":1,\"type\":\"pubkeyhash\",\"addresses\":[\"RD5Sj6igy53nscMiFS4ECXByfqVeyV9NdG\"]},\"version\":1,\"coinbase\":false,\"randipbits\":579036043,\"coin\":\"KMD\",\"txid\":\"b32af9977bc8ed0e54631d27f490c79841a03bccce4d6b8181456657b06194ef\",\"vout\":0,\"amount\":0.04900000}, {\"bestblock\":\"0000119186ecfaa8d72a7d3c62e78135043db220a6d29a9605f1fbe383bcedfb\",\"confirmations\":65553,\"value\":1,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 29a7bd36e6913b674bb2b5c65e61a6544426ddd7 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a91429a7bd36e6913b674bb2b5c65e61a6544426ddd788ac\",\"reqSigs\":1,\"type\":\"pubkeyhash\",\"addresses\":[\"RD5Sj6igy53nscMiFS4ECXByfqVeyV9NdG\"]},\"version\":1,\"coinbase\":false,\"randipbits\":3795805790,\"coin\":\"KMD\",\"txid\":\"84ca2ba7f621c820ab642e358813fcc33171c9999a47bb99dcf3a309dc847419\",\"vout\":1,\"amount\":1}]}" + diff --git a/iguana/tests/dexgetO b/iguana/tests/dexgetO index 9c187166b..6f4290b48 100755 --- a/iguana/tests/dexgetO +++ b/iguana/tests/dexgetO @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettxout\",\"vout\":1,\"txid\":\"fa3321ed55e8e96ba7221e9cc4bc54b735616649abcc9734bb73f505ee712884\",\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettxout\",\"vout\":1,\"txid\":\"4a1a2026718ac10bd11ccccbdd85f29faa5f0b7c3ab95a57dcf7040c5ca0420c\",\"symbol\":\"KMD\"}" diff --git a/iguana/tests/dexgetT b/iguana/tests/dexgetT index 0cae93716..18241a84d 100755 --- a/iguana/tests/dexgetT +++ b/iguana/tests/dexgetT @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettransaction\",\"txid\":\"790211d19afd88f00537c2b847772cebe01853617528990e1c1f59eb45d2f1d9\",\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettransaction\",\"txid\":\"88794bbb699f130951c40dc99a27d2c7c7016e12824fd1040cbedf86980de04d\",\"symbol\":\"REVS\"}" diff --git a/iguana/tests/dexgetbalance b/iguana/tests/dexgetbalance index d0f90e62b..71efdf9af 100755 --- a/iguana/tests/dexgetbalance +++ b/iguana/tests/dexgetbalance @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getbalance\",\"address\":\"RU58D7nNLXwD29hgC2MPgtAF458gGxnPYS\",\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getbalance\",\"address\":\"RAGhCfNvxpL55JFV7h2HQa5dSEK86Jg3ic\",\"symbol\":\"KMD\"}" diff --git a/iguana/tests/dexkvupdate b/iguana/tests/dexkvupdate index a98240995..a6792a142 100755 --- a/iguana/tests/dexkvupdate +++ b/iguana/tests/dexkvupdate @@ -1,3 +1,3 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"test\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KMD\"}" -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"test\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KV\"}" +#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"test\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"testtest\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KV\"}" diff --git a/iguana/tests/dexlistunspent b/iguana/tests/dexlistunspent index 5cd82cdaa..4e353d69b 100755 --- a/iguana/tests/dexlistunspent +++ b/iguana/tests/dexlistunspent @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent2\",\"address\":\"RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC\",\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"1Hgzt5xsnbfc8UTWqWKSTLRm5bEYHYBoCE\",\"symbol\":\"BTC\"}" diff --git a/iguana/tests/dexpsock b/iguana/tests/dexpsock new file mode 100755 index 000000000..0a0e6fb16 --- /dev/null +++ b/iguana/tests/dexpsock @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"psock\"}" diff --git a/iguana/tests/dexsendrawtransaction b/iguana/tests/dexsendrawtransaction index d60706f4d..f3796ea37 100755 --- a/iguana/tests/dexsendrawtransaction +++ b/iguana/tests/dexsendrawtransaction @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"sendrawtransaction\",\"signedtx\":\"0100000001372105704c1303f4c928b788becce75b653b5e83d56fc25893f682875f9df00e010000006a47304402203c3e71c309fcf70d1b1b42207824b37cfec918930000b8d812844be9a8d06bae02202eafe0515f6cd775ba06be0fab6cea667a23508e69334310b959ebd7eade38c9012102320228e3f6f9b8db3d905bc21cefde46e72d622021b8fd40344ac2ab8346c287ffffffff02b0e20d000000000017a914077fa9d41d53cc38118b8280e97e4aee576d6e5a87c08c8a00000000001976a914838f4ea2f88f24b87247b72a1d66da225653e39788ac00000000\",\"symbol\":\"USD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"sendrawtransaction\",\"signedtx\":\"01000000010c42a05c0c04f7dc575ab93a7c0b5faa9ff285ddcbcc1cd10bc18a7126201a4a010000006b483045022100814b44c4af1beeb7ab3abdd7dfd95216b48da2f47ded4137f3dca366db4a94bc0220686108f29cc1eea5c845b7571e01412a373e5077d448e021bac7e8a19ec451a20121025879c9eaa100984ee1faaeb55bcbafed5b1f565c35ed7ebaadcce0a8416e6263ffffffff0240420f00000000001976a914c5a58530ee7bec4f5ab9a8c0c63069484273276c88ac34955836020000001976a914971f98b33fb838faee190e2fab799440d8c5170288acf70ab858\",\"symbol\":\"KMD\"}" diff --git a/iguana/tests/jumblrstatus b/iguana/tests/jumblrstatus new file mode 100755 index 000000000..6c1824244 --- /dev/null +++ b/iguana/tests/jumblrstatus @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"jumblr\",\"method\":\"status\"}" diff --git a/iguana/tests/loop b/iguana/tests/loop index 7f1a05445..460d2c4db 100755 --- a/iguana/tests/loop +++ b/iguana/tests/loop @@ -1,8 +1,6 @@ #!/bin/bash -pkill iguana while true do -../../agents/iguana -sleep 3 +./dexgetinfo done diff --git a/iguana/tests/notlp b/iguana/tests/notlp new file mode 100755 index 000000000..b29c9dde7 --- /dev/null +++ b/iguana/tests/notlp @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"notlp\"}" diff --git a/iguana/tests/request b/iguana/tests/request index 58ccace04..ac3337301 100755 --- a/iguana/tests/request +++ b/iguana/tests/request @@ -1,3 +1,3 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":0.03,\"dest\":\"BTC\",\"minprice\":0.002}}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"KMD\",\"amount\":20,\"dest\":\"USD\",\"minprice\":0.08}}" diff --git a/iguana/tests/swaplist b/iguana/tests/swaplist new file mode 100755 index 000000000..2db29548e --- /dev/null +++ b/iguana/tests/swaplist @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"getswaplist\"}" diff --git a/iguana/tests/test b/iguana/tests/test deleted file mode 100755 index 495928084..000000000 --- a/iguana/tests/test +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -echo "{\"field\":\"requiredvalue\"}" > /tmp/foo -./jsoncmp /tmp/foo {\"fields\":[{\"field\":\"requiredvalue\"}]} diff --git a/iguana/tests/utxorawtx b/iguana/tests/utxorawtx index a157a3ee9..57d252129 100755 --- a/iguana/tests/utxorawtx +++ b/iguana/tests/utxorawtx @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"symbol\":\"KMD\",\"agent\":\"basilisk\",\"method\":\"utxorawtx\",\"vals\":{\"timelock\":0,\"changeaddr\":\"RNmvQtThVZAbc1tFEFmKAnJZrc9XqciNog\",\"destaddr\":\"RHfraY22xd9aAuuUJ6Yjb6HFUXh535z6Lg\",\"txfee\":0.00011,\"amount\":0.01,\"sendflag\":0},\"utxos\":[{\"bestblock\":\"000000a7d7b317af7169a156f6b4b9538293da2a3707a69aa3048998a87fbf2c\",\"confirmations\":0,\"value\":0.02,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 b7128d2ee837cf03e30a2c0e3e0181f7b9669bb6 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\",\"reqSigs\":1,\"type\":\"pubkeyhash\",\"addresses\":[\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\"]},\"version\":1,\"coinbase\":false,\"randipbits\":3350674129,\"coin\":\"KMD\",\"txid\":\"9329814cc4c7a8cabf83627d4228c1a2090e776d669c585d824d912ce2e13b13\",\"vout\":1,\"amount\":0.02}]}" +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}]}" diff --git a/iguana/tests/walletpassphrase b/iguana/tests/walletpassphrase index 1416189c8..94d46e776 100755 --- a/iguana/tests/walletpassphrase +++ b/iguana/tests/walletpassphrase @@ -1,3 +1,4 @@ #!/bin/bash #curl --url "http://127.0.0.1:7778" --data "{\"method\":\"walletpassphrase\",\"params\":[\"test\", 600]}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"password\":\"test\",\"timeout\":86444}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"jumblr\",\"method\":\"setpassphrase\",\"passphrase\":\"jumblr test\"}" diff --git a/includes/curl/.gitignore b/includes/curl/.gitignore new file mode 100644 index 000000000..228a961fb --- /dev/null +++ b/includes/curl/.gitignore @@ -0,0 +1,4 @@ +curlbuild.h +curlver.h.dist +stamp-h2 +stamp-h3 diff --git a/includes/curl/Makefile.am b/includes/curl/Makefile.am new file mode 100644 index 000000000..7c924fcb5 --- /dev/null +++ b/includes/curl/Makefile.am @@ -0,0 +1,53 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.haxx.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +########################################################################### +pkginclude_HEADERS = \ + curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \ + typecheck-gcc.h curlbuild.h curlrules.h + +pkgincludedir= $(includedir)/curl + +# curlbuild.h does not exist in the git tree. When the original libcurl +# source code distribution archive file is created, curlbuild.h.dist is +# renamed to curlbuild.h and included in the tarball so that it can be +# used directly on non-configure systems. +# +# The distributed curlbuild.h will be overwritten on configure systems +# when the configure script runs, with one that is suitable and specific +# to the library being configured and built. +# +# curlbuild.h.in is the distributed template file from which the configure +# script creates curlbuild.h at library configuration time, overwiting the +# one included in the distribution archive. +# +# curlbuild.h.dist is not included in the source code distribution archive. + +EXTRA_DIST = curlbuild.h.in + +DISTCLEANFILES = curlbuild.h + +checksrc: + @@PERL@ $(top_srcdir)/lib/checksrc.pl -Wcurlbuild.h -D$(top_srcdir)/include/curl $(pkginclude_HEADERS) $(EXTRA_DIST) + +if CURLDEBUG +# for debug builds, we scan the sources on all regular make invokes +all-local: checksrc +endif diff --git a/includes/curl/curl.h b/includes/curl/curl.h new file mode 100644 index 000000000..7c7d28d6a --- /dev/null +++ b/includes/curl/curl.h @@ -0,0 +1,2551 @@ +#ifndef __CURL_CURL_H +#define __CURL_CURL_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* + * If you have libcurl problems, all docs and details are found here: + * https://curl.haxx.se/libcurl/ + * + * curl-library mailing list subscription and unsubscription web interface: + * https://cool.haxx.se/mailman/listinfo/curl-library/ + */ + +#ifdef CURL_NO_OLDIES +#define CURL_STRICTER +#endif + +#include "curlver.h" /* libcurl version defines */ +#include "curlbuild.h" /* libcurl build definitions */ +#include "curlrules.h" /* libcurl rules enforcement */ + +/* + * Define WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__)) && \ + !defined(WIN32) && !defined(__SYMBIAN32__) +#define WIN32 +#endif + +#include +#include + +#if defined(__FreeBSD__) && (__FreeBSD__ >= 2) +/* Needed for __FreeBSD_version symbol definition */ +#include +#endif + +/* The include stuff here below is mainly for time_t! */ +#include +#include + +#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) +#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || \ + defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)) +/* The check above prevents the winsock2 inclusion if winsock.h already was + included, since they can't co-exist without problems */ +#include +#include +#endif +#endif + +/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish + libc5-based Linux systems. Only include it on systems that are known to + require it! */ +#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ + defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \ + defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \ + (defined(__FreeBSD_version) && (__FreeBSD_version < 800000)) +#include +#endif + +#if !defined(WIN32) && !defined(_WIN32_WCE) +#include +#endif + +#if !defined(WIN32) && !defined(__WATCOMC__) && !defined(__VXWORKS__) +#include +#endif + +#ifdef __BEOS__ +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) +typedef struct Curl_easy CURL; +typedef struct Curl_share CURLSH; +#else +typedef void CURL; +typedef void CURLSH; +#endif + +/* + * libcurl external API function linkage decorations. + */ + +#ifdef CURL_STATICLIB +# define CURL_EXTERN +#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__) +# if defined(BUILDING_LIBCURL) +# define CURL_EXTERN __declspec(dllexport) +# else +# define CURL_EXTERN __declspec(dllimport) +# endif +#elif defined(BUILDING_LIBCURL) && defined(CURL_HIDDEN_SYMBOLS) +# define CURL_EXTERN CURL_EXTERN_SYMBOL +#else +# define CURL_EXTERN +#endif + +#ifndef curl_socket_typedef +/* socket typedef */ +#if defined(WIN32) && !defined(__LWIP_OPT_H__) && !defined(LWIP_HDR_OPT_H) +typedef SOCKET curl_socket_t; +#define CURL_SOCKET_BAD INVALID_SOCKET +#else +typedef int curl_socket_t; +#define CURL_SOCKET_BAD -1 +#endif +#define curl_socket_typedef +#endif /* curl_socket_typedef */ + +struct curl_httppost { + struct curl_httppost *next; /* next entry in the list */ + char *name; /* pointer to allocated name */ + long namelength; /* length of name length */ + char *contents; /* pointer to allocated data contents */ + long contentslength; /* length of contents field, see also + CURL_HTTPPOST_LARGE */ + char *buffer; /* pointer to allocated buffer contents */ + long bufferlength; /* length of buffer field */ + char *contenttype; /* Content-Type */ + struct curl_slist *contentheader; /* list of extra headers for this form */ + struct curl_httppost *more; /* if one field name has more than one + file, this link should link to following + files */ + long flags; /* as defined below */ + +/* specified content is a file name */ +#define CURL_HTTPPOST_FILENAME (1<<0) +/* specified content is a file name */ +#define CURL_HTTPPOST_READFILE (1<<1) +/* name is only stored pointer do not free in formfree */ +#define CURL_HTTPPOST_PTRNAME (1<<2) +/* contents is only stored pointer do not free in formfree */ +#define CURL_HTTPPOST_PTRCONTENTS (1<<3) +/* upload file from buffer */ +#define CURL_HTTPPOST_BUFFER (1<<4) +/* upload file from pointer contents */ +#define CURL_HTTPPOST_PTRBUFFER (1<<5) +/* upload file contents by using the regular read callback to get the data and + pass the given pointer as custom pointer */ +#define CURL_HTTPPOST_CALLBACK (1<<6) +/* use size in 'contentlen', added in 7.46.0 */ +#define CURL_HTTPPOST_LARGE (1<<7) + + char *showfilename; /* The file name to show. If not set, the + actual file name will be used (if this + is a file part) */ + void *userp; /* custom pointer used for + HTTPPOST_CALLBACK posts */ + curl_off_t contentlen; /* alternative length of contents + field. Used if CURL_HTTPPOST_LARGE is + set. Added in 7.46.0 */ +}; + +/* This is the CURLOPT_PROGRESSFUNCTION callback proto. It is now considered + deprecated but was the only choice up until 7.31.0 */ +typedef int (*curl_progress_callback)(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow); + +/* This is the CURLOPT_XFERINFOFUNCTION callback proto. It was introduced in + 7.32.0, it avoids floating point and provides more detailed information. */ +typedef int (*curl_xferinfo_callback)(void *clientp, + curl_off_t dltotal, + curl_off_t dlnow, + curl_off_t ultotal, + curl_off_t ulnow); + +#ifndef CURL_MAX_READ_SIZE + /* The maximum receive buffer size configurable via CURLOPT_BUFFERSIZE. */ +#define CURL_MAX_READ_SIZE 524288 +#endif + +#ifndef CURL_MAX_WRITE_SIZE + /* Tests have proven that 20K is a very bad buffer size for uploads on + Windows, while 16K for some odd reason performed a lot better. + We do the ifndef check to allow this value to easier be changed at build + time for those who feel adventurous. The practical minimum is about + 400 bytes since libcurl uses a buffer of this size as a scratch area + (unrelated to network send operations). */ +#define CURL_MAX_WRITE_SIZE 16384 +#endif + +#ifndef CURL_MAX_HTTP_HEADER +/* The only reason to have a max limit for this is to avoid the risk of a bad + server feeding libcurl with a never-ending header that will cause reallocs + infinitely */ +#define CURL_MAX_HTTP_HEADER (100*1024) +#endif + +/* This is a magic return code for the write callback that, when returned, + will signal libcurl to pause receiving on the current transfer. */ +#define CURL_WRITEFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_write_callback)(char *buffer, + size_t size, + size_t nitems, + void *outstream); + + + +/* enumeration of file types */ +typedef enum { + CURLFILETYPE_FILE = 0, + CURLFILETYPE_DIRECTORY, + CURLFILETYPE_SYMLINK, + CURLFILETYPE_DEVICE_BLOCK, + CURLFILETYPE_DEVICE_CHAR, + CURLFILETYPE_NAMEDPIPE, + CURLFILETYPE_SOCKET, + CURLFILETYPE_DOOR, /* is possible only on Sun Solaris now */ + + CURLFILETYPE_UNKNOWN /* should never occur */ +} curlfiletype; + +#define CURLFINFOFLAG_KNOWN_FILENAME (1<<0) +#define CURLFINFOFLAG_KNOWN_FILETYPE (1<<1) +#define CURLFINFOFLAG_KNOWN_TIME (1<<2) +#define CURLFINFOFLAG_KNOWN_PERM (1<<3) +#define CURLFINFOFLAG_KNOWN_UID (1<<4) +#define CURLFINFOFLAG_KNOWN_GID (1<<5) +#define CURLFINFOFLAG_KNOWN_SIZE (1<<6) +#define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1<<7) + +/* Content of this structure depends on information which is known and is + achievable (e.g. by FTP LIST parsing). Please see the url_easy_setopt(3) man + page for callbacks returning this structure -- some fields are mandatory, + some others are optional. The FLAG field has special meaning. */ +struct curl_fileinfo { + char *filename; + curlfiletype filetype; + time_t time; + unsigned int perm; + int uid; + int gid; + curl_off_t size; + long int hardlinks; + + struct { + /* If some of these fields is not NULL, it is a pointer to b_data. */ + char *time; + char *perm; + char *user; + char *group; + char *target; /* pointer to the target filename of a symlink */ + } strings; + + unsigned int flags; + + /* used internally */ + char *b_data; + size_t b_size; + size_t b_used; +}; + +/* return codes for CURLOPT_CHUNK_BGN_FUNCTION */ +#define CURL_CHUNK_BGN_FUNC_OK 0 +#define CURL_CHUNK_BGN_FUNC_FAIL 1 /* tell the lib to end the task */ +#define CURL_CHUNK_BGN_FUNC_SKIP 2 /* skip this chunk over */ + +/* if splitting of data transfer is enabled, this callback is called before + download of an individual chunk started. Note that parameter "remains" works + only for FTP wildcard downloading (for now), otherwise is not used */ +typedef long (*curl_chunk_bgn_callback)(const void *transfer_info, + void *ptr, + int remains); + +/* return codes for CURLOPT_CHUNK_END_FUNCTION */ +#define CURL_CHUNK_END_FUNC_OK 0 +#define CURL_CHUNK_END_FUNC_FAIL 1 /* tell the lib to end the task */ + +/* If splitting of data transfer is enabled this callback is called after + download of an individual chunk finished. + Note! After this callback was set then it have to be called FOR ALL chunks. + Even if downloading of this chunk was skipped in CHUNK_BGN_FUNC. + This is the reason why we don't need "transfer_info" parameter in this + callback and we are not interested in "remains" parameter too. */ +typedef long (*curl_chunk_end_callback)(void *ptr); + +/* return codes for FNMATCHFUNCTION */ +#define CURL_FNMATCHFUNC_MATCH 0 /* string corresponds to the pattern */ +#define CURL_FNMATCHFUNC_NOMATCH 1 /* pattern doesn't match the string */ +#define CURL_FNMATCHFUNC_FAIL 2 /* an error occurred */ + +/* callback type for wildcard downloading pattern matching. If the + string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */ +typedef int (*curl_fnmatch_callback)(void *ptr, + const char *pattern, + const char *string); + +/* These are the return codes for the seek callbacks */ +#define CURL_SEEKFUNC_OK 0 +#define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */ +#define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking can't be done, so + libcurl might try other means instead */ +typedef int (*curl_seek_callback)(void *instream, + curl_off_t offset, + int origin); /* 'whence' */ + +/* This is a return code for the read callback that, when returned, will + signal libcurl to immediately abort the current transfer. */ +#define CURL_READFUNC_ABORT 0x10000000 +/* This is a return code for the read callback that, when returned, will + signal libcurl to pause sending data on the current transfer. */ +#define CURL_READFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_read_callback)(char *buffer, + size_t size, + size_t nitems, + void *instream); + +typedef enum { + CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */ + CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */ + CURLSOCKTYPE_LAST /* never use */ +} curlsocktype; + +/* The return code from the sockopt_callback can signal information back + to libcurl: */ +#define CURL_SOCKOPT_OK 0 +#define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return + CURLE_ABORTED_BY_CALLBACK */ +#define CURL_SOCKOPT_ALREADY_CONNECTED 2 + +typedef int (*curl_sockopt_callback)(void *clientp, + curl_socket_t curlfd, + curlsocktype purpose); + +struct curl_sockaddr { + int family; + int socktype; + int protocol; + unsigned int addrlen; /* addrlen was a socklen_t type before 7.18.0 but it + turned really ugly and painful on the systems that + lack this type */ + struct sockaddr addr; +}; + +typedef curl_socket_t +(*curl_opensocket_callback)(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address); + +typedef int +(*curl_closesocket_callback)(void *clientp, curl_socket_t item); + +typedef enum { + CURLIOE_OK, /* I/O operation successful */ + CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ + CURLIOE_FAILRESTART, /* failed to restart the read */ + CURLIOE_LAST /* never use */ +} curlioerr; + +typedef enum { + CURLIOCMD_NOP, /* no operation */ + CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ + CURLIOCMD_LAST /* never use */ +} curliocmd; + +typedef curlioerr (*curl_ioctl_callback)(CURL *handle, + int cmd, + void *clientp); + +#ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS +/* + * The following typedef's are signatures of malloc, free, realloc, strdup and + * calloc respectively. Function pointers of these types can be passed to the + * curl_global_init_mem() function to set user defined memory management + * callback routines. + */ +typedef void *(*curl_malloc_callback)(size_t size); +typedef void (*curl_free_callback)(void *ptr); +typedef void *(*curl_realloc_callback)(void *ptr, size_t size); +typedef char *(*curl_strdup_callback)(const char *str); +typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size); + +#define CURL_DID_MEMORY_FUNC_TYPEDEFS +#endif + +/* the kind of data that is passed to information_callback*/ +typedef enum { + CURLINFO_TEXT = 0, + CURLINFO_HEADER_IN, /* 1 */ + CURLINFO_HEADER_OUT, /* 2 */ + CURLINFO_DATA_IN, /* 3 */ + CURLINFO_DATA_OUT, /* 4 */ + CURLINFO_SSL_DATA_IN, /* 5 */ + CURLINFO_SSL_DATA_OUT, /* 6 */ + CURLINFO_END +} curl_infotype; + +typedef int (*curl_debug_callback) + (CURL *handle, /* the handle/transfer this concerns */ + curl_infotype type, /* what kind of data */ + char *data, /* points to the data */ + size_t size, /* size of the data pointed to */ + void *userptr); /* whatever the user please */ + +/* All possible error codes from all sorts of curl functions. Future versions + may return other values, stay prepared. + + Always add new return codes last. Never *EVER* remove any. The return + codes must remain the same! + */ + +typedef enum { + CURLE_OK = 0, + CURLE_UNSUPPORTED_PROTOCOL, /* 1 */ + CURLE_FAILED_INIT, /* 2 */ + CURLE_URL_MALFORMAT, /* 3 */ + CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for + 7.17.0, reused in April 2011 for 7.21.5] */ + CURLE_COULDNT_RESOLVE_PROXY, /* 5 */ + CURLE_COULDNT_RESOLVE_HOST, /* 6 */ + CURLE_COULDNT_CONNECT, /* 7 */ + CURLE_WEIRD_SERVER_REPLY, /* 8 */ + CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server + due to lack of access - when login fails + this is not returned. */ + CURLE_FTP_ACCEPT_FAILED, /* 10 - [was obsoleted in April 2006 for + 7.15.4, reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */ + CURLE_FTP_ACCEPT_TIMEOUT, /* 12 - timeout occurred accepting server + [was obsoleted in August 2007 for 7.17.0, + reused in Dec 2011 for 7.24.0]*/ + CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */ + CURLE_FTP_WEIRD_227_FORMAT, /* 14 */ + CURLE_FTP_CANT_GET_HOST, /* 15 */ + CURLE_HTTP2, /* 16 - A problem in the http2 framing layer. + [was obsoleted in August 2007 for 7.17.0, + reused in July 2014 for 7.38.0] */ + CURLE_FTP_COULDNT_SET_TYPE, /* 17 */ + CURLE_PARTIAL_FILE, /* 18 */ + CURLE_FTP_COULDNT_RETR_FILE, /* 19 */ + CURLE_OBSOLETE20, /* 20 - NOT USED */ + CURLE_QUOTE_ERROR, /* 21 - quote command failure */ + CURLE_HTTP_RETURNED_ERROR, /* 22 */ + CURLE_WRITE_ERROR, /* 23 */ + CURLE_OBSOLETE24, /* 24 - NOT USED */ + CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */ + CURLE_READ_ERROR, /* 26 - couldn't open/read from file */ + CURLE_OUT_OF_MEMORY, /* 27 */ + /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error + instead of a memory allocation error if CURL_DOES_CONVERSIONS + is defined + */ + CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */ + CURLE_OBSOLETE29, /* 29 - NOT USED */ + CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */ + CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */ + CURLE_OBSOLETE32, /* 32 - NOT USED */ + CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */ + CURLE_HTTP_POST_ERROR, /* 34 */ + CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */ + CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */ + CURLE_FILE_COULDNT_READ_FILE, /* 37 */ + CURLE_LDAP_CANNOT_BIND, /* 38 */ + CURLE_LDAP_SEARCH_FAILED, /* 39 */ + CURLE_OBSOLETE40, /* 40 - NOT USED */ + CURLE_FUNCTION_NOT_FOUND, /* 41 - NOT USED starting with 7.53.0 */ + CURLE_ABORTED_BY_CALLBACK, /* 42 */ + CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */ + CURLE_OBSOLETE44, /* 44 - NOT USED */ + CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */ + CURLE_OBSOLETE46, /* 46 - NOT USED */ + CURLE_TOO_MANY_REDIRECTS, /* 47 - catch endless re-direct loops */ + CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */ + CURLE_TELNET_OPTION_SYNTAX, /* 49 - Malformed telnet option */ + CURLE_OBSOLETE50, /* 50 - NOT USED */ + CURLE_PEER_FAILED_VERIFICATION, /* 51 - peer's certificate or fingerprint + wasn't verified fine */ + CURLE_GOT_NOTHING, /* 52 - when this is a specific error */ + CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */ + CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as + default */ + CURLE_SEND_ERROR, /* 55 - failed sending network data */ + CURLE_RECV_ERROR, /* 56 - failure in receiving network data */ + CURLE_OBSOLETE57, /* 57 - NOT IN USE */ + CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */ + CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */ + CURLE_SSL_CACERT, /* 60 - problem with the CA cert (path?) */ + CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */ + CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */ + CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */ + CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */ + CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind + that failed */ + CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */ + CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not + accepted and we failed to login */ + CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */ + CURLE_TFTP_PERM, /* 69 - permission problem on server */ + CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */ + CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */ + CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */ + CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */ + CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */ + CURLE_CONV_FAILED, /* 75 - conversion failed */ + CURLE_CONV_REQD, /* 76 - caller must register conversion + callbacks using curl_easy_setopt options + CURLOPT_CONV_FROM_NETWORK_FUNCTION, + CURLOPT_CONV_TO_NETWORK_FUNCTION, and + CURLOPT_CONV_FROM_UTF8_FUNCTION */ + CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing + or wrong format */ + CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */ + CURLE_SSH, /* 79 - error from the SSH layer, somewhat + generic so the error message will be of + interest when this has happened */ + + CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL + connection */ + CURLE_AGAIN, /* 81 - socket is not ready for send/recv, + wait till it's ready and try again (Added + in 7.18.2) */ + CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or + wrong format (Added in 7.19.0) */ + CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in + 7.19.0) */ + CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */ + CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */ + CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Ids */ + CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */ + CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */ + CURLE_NO_CONNECTION_AVAILABLE, /* 89 - No connection available, the + session will be queued */ + CURLE_SSL_PINNEDPUBKEYNOTMATCH, /* 90 - specified pinned public key did not + match */ + CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */ + CURLE_HTTP2_STREAM, /* 92 - stream error in HTTP/2 framing layer + */ + CURL_LAST /* never use! */ +} CURLcode; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Previously obsolete error code re-used in 7.38.0 */ +#define CURLE_OBSOLETE16 CURLE_HTTP2 + +/* Previously obsolete error codes re-used in 7.24.0 */ +#define CURLE_OBSOLETE10 CURLE_FTP_ACCEPT_FAILED +#define CURLE_OBSOLETE12 CURLE_FTP_ACCEPT_TIMEOUT + +/* compatibility with older names */ +#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING +#define CURLE_FTP_WEIRD_SERVER_REPLY CURLE_WEIRD_SERVER_REPLY + +/* The following were added in 7.21.5, April 2011 */ +#define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION + +/* The following were added in 7.17.1 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_SSL_PEER_CERTIFICATE CURLE_PEER_FAILED_VERIFICATION + +/* The following were added in 7.17.0 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_OBSOLETE CURLE_OBSOLETE50 /* no one should be using this! */ +#define CURLE_BAD_PASSWORD_ENTERED CURLE_OBSOLETE46 +#define CURLE_BAD_CALLING_ORDER CURLE_OBSOLETE44 +#define CURLE_FTP_USER_PASSWORD_INCORRECT CURLE_OBSOLETE10 +#define CURLE_FTP_CANT_RECONNECT CURLE_OBSOLETE16 +#define CURLE_FTP_COULDNT_GET_SIZE CURLE_OBSOLETE32 +#define CURLE_FTP_COULDNT_SET_ASCII CURLE_OBSOLETE29 +#define CURLE_FTP_WEIRD_USER_REPLY CURLE_OBSOLETE12 +#define CURLE_FTP_WRITE_ERROR CURLE_OBSOLETE20 +#define CURLE_LIBRARY_NOT_FOUND CURLE_OBSOLETE40 +#define CURLE_MALFORMAT_USER CURLE_OBSOLETE24 +#define CURLE_SHARE_IN_USE CURLE_OBSOLETE57 +#define CURLE_URL_MALFORMAT_USER CURLE_NOT_BUILT_IN + +#define CURLE_FTP_ACCESS_DENIED CURLE_REMOTE_ACCESS_DENIED +#define CURLE_FTP_COULDNT_SET_BINARY CURLE_FTP_COULDNT_SET_TYPE +#define CURLE_FTP_QUOTE_ERROR CURLE_QUOTE_ERROR +#define CURLE_TFTP_DISKFULL CURLE_REMOTE_DISK_FULL +#define CURLE_TFTP_EXISTS CURLE_REMOTE_FILE_EXISTS +#define CURLE_HTTP_RANGE_ERROR CURLE_RANGE_ERROR +#define CURLE_FTP_SSL_FAILED CURLE_USE_SSL_FAILED + +/* The following were added earlier */ + +#define CURLE_OPERATION_TIMEOUTED CURLE_OPERATION_TIMEDOUT + +#define CURLE_HTTP_NOT_FOUND CURLE_HTTP_RETURNED_ERROR +#define CURLE_HTTP_PORT_FAILED CURLE_INTERFACE_FAILED +#define CURLE_FTP_COULDNT_STOR_FILE CURLE_UPLOAD_FAILED + +#define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE +#define CURLE_FTP_BAD_DOWNLOAD_RESUME CURLE_BAD_DOWNLOAD_RESUME + +/* This was the error code 50 in 7.7.3 and a few earlier versions, this + is no longer used by libcurl but is instead #defined here only to not + make programs break */ +#define CURLE_ALREADY_COMPLETE 99999 + +/* Provide defines for really old option names */ +#define CURLOPT_FILE CURLOPT_WRITEDATA /* name changed in 7.9.7 */ +#define CURLOPT_INFILE CURLOPT_READDATA /* name changed in 7.9.7 */ +#define CURLOPT_WRITEHEADER CURLOPT_HEADERDATA + +/* Since long deprecated options with no code in the lib that does anything + with them. */ +#define CURLOPT_WRITEINFO CURLOPT_OBSOLETE40 +#define CURLOPT_CLOSEPOLICY CURLOPT_OBSOLETE72 + +#endif /*!CURL_NO_OLDIES*/ + +/* This prototype applies to all conversion callbacks */ +typedef CURLcode (*curl_conv_callback)(char *buffer, size_t length); + +typedef CURLcode (*curl_ssl_ctx_callback)(CURL *curl, /* easy handle */ + void *ssl_ctx, /* actually an + OpenSSL SSL_CTX */ + void *userptr); + +typedef enum { + CURLPROXY_HTTP = 0, /* added in 7.10, new in 7.19.4 default is to use + CONNECT HTTP/1.1 */ + CURLPROXY_HTTP_1_0 = 1, /* added in 7.19.4, force to use CONNECT + HTTP/1.0 */ + CURLPROXY_HTTPS = 2, /* added in 7.52.0 */ + CURLPROXY_SOCKS4 = 4, /* support added in 7.15.2, enum existed already + in 7.10 */ + CURLPROXY_SOCKS5 = 5, /* added in 7.10 */ + CURLPROXY_SOCKS4A = 6, /* added in 7.18.0 */ + CURLPROXY_SOCKS5_HOSTNAME = 7 /* Use the SOCKS5 protocol but pass along the + host name rather than the IP address. added + in 7.18.0 */ +} curl_proxytype; /* this enum was added in 7.10 */ + +/* + * Bitmasks for CURLOPT_HTTPAUTH and CURLOPT_PROXYAUTH options: + * + * CURLAUTH_NONE - No HTTP authentication + * CURLAUTH_BASIC - HTTP Basic authentication (default) + * CURLAUTH_DIGEST - HTTP Digest authentication + * CURLAUTH_NEGOTIATE - HTTP Negotiate (SPNEGO) authentication + * CURLAUTH_GSSNEGOTIATE - Alias for CURLAUTH_NEGOTIATE (deprecated) + * CURLAUTH_NTLM - HTTP NTLM authentication + * CURLAUTH_DIGEST_IE - HTTP Digest authentication with IE flavour + * CURLAUTH_NTLM_WB - HTTP NTLM authentication delegated to winbind helper + * CURLAUTH_ONLY - Use together with a single other type to force no + * authentication or just that single type + * CURLAUTH_ANY - All fine types set + * CURLAUTH_ANYSAFE - All fine types except Basic + */ + +#define CURLAUTH_NONE ((unsigned long)0) +#define CURLAUTH_BASIC (((unsigned long)1)<<0) +#define CURLAUTH_DIGEST (((unsigned long)1)<<1) +#define CURLAUTH_NEGOTIATE (((unsigned long)1)<<2) +/* Deprecated since the advent of CURLAUTH_NEGOTIATE */ +#define CURLAUTH_GSSNEGOTIATE CURLAUTH_NEGOTIATE +#define CURLAUTH_NTLM (((unsigned long)1)<<3) +#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4) +#define CURLAUTH_NTLM_WB (((unsigned long)1)<<5) +#define CURLAUTH_ONLY (((unsigned long)1)<<31) +#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) +#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) + +#define CURLSSH_AUTH_ANY ~0 /* all types supported by the server */ +#define CURLSSH_AUTH_NONE 0 /* none allowed, silly but complete */ +#define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */ +#define CURLSSH_AUTH_PASSWORD (1<<1) /* password */ +#define CURLSSH_AUTH_HOST (1<<2) /* host key files */ +#define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */ +#define CURLSSH_AUTH_AGENT (1<<4) /* agent (ssh-agent, pageant...) */ +#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY + +#define CURLGSSAPI_DELEGATION_NONE 0 /* no delegation (default) */ +#define CURLGSSAPI_DELEGATION_POLICY_FLAG (1<<0) /* if permitted by policy */ +#define CURLGSSAPI_DELEGATION_FLAG (1<<1) /* delegate always */ + +#define CURL_ERROR_SIZE 256 + +enum curl_khtype { + CURLKHTYPE_UNKNOWN, + CURLKHTYPE_RSA1, + CURLKHTYPE_RSA, + CURLKHTYPE_DSS +}; + +struct curl_khkey { + const char *key; /* points to a zero-terminated string encoded with base64 + if len is zero, otherwise to the "raw" data */ + size_t len; + enum curl_khtype keytype; +}; + +/* this is the set of return values expected from the curl_sshkeycallback + callback */ +enum curl_khstat { + CURLKHSTAT_FINE_ADD_TO_FILE, + CURLKHSTAT_FINE, + CURLKHSTAT_REJECT, /* reject the connection, return an error */ + CURLKHSTAT_DEFER, /* do not accept it, but we can't answer right now so + this causes a CURLE_DEFER error but otherwise the + connection will be left intact etc */ + CURLKHSTAT_LAST /* not for use, only a marker for last-in-list */ +}; + +/* this is the set of status codes pass in to the callback */ +enum curl_khmatch { + CURLKHMATCH_OK, /* match */ + CURLKHMATCH_MISMATCH, /* host found, key mismatch! */ + CURLKHMATCH_MISSING, /* no matching host/key found */ + CURLKHMATCH_LAST /* not for use, only a marker for last-in-list */ +}; + +typedef int + (*curl_sshkeycallback) (CURL *easy, /* easy handle */ + const struct curl_khkey *knownkey, /* known */ + const struct curl_khkey *foundkey, /* found */ + enum curl_khmatch, /* libcurl's view on the keys */ + void *clientp); /* custom pointer passed from app */ + +/* parameter for the CURLOPT_USE_SSL option */ +typedef enum { + CURLUSESSL_NONE, /* do not attempt to use SSL */ + CURLUSESSL_TRY, /* try using SSL, proceed anyway otherwise */ + CURLUSESSL_CONTROL, /* SSL for the control connection or fail */ + CURLUSESSL_ALL, /* SSL for all communication or fail */ + CURLUSESSL_LAST /* not an option, never use */ +} curl_usessl; + +/* Definition of bits for the CURLOPT_SSL_OPTIONS argument: */ + +/* - ALLOW_BEAST tells libcurl to allow the BEAST SSL vulnerability in the + name of improving interoperability with older servers. Some SSL libraries + have introduced work-arounds for this flaw but those work-arounds sometimes + make the SSL communication fail. To regain functionality with those broken + servers, a user can this way allow the vulnerability back. */ +#define CURLSSLOPT_ALLOW_BEAST (1<<0) + +/* - NO_REVOKE tells libcurl to disable certificate revocation checks for those + SSL backends where such behavior is present. */ +#define CURLSSLOPT_NO_REVOKE (1<<1) + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2009 */ + +#define CURLFTPSSL_NONE CURLUSESSL_NONE +#define CURLFTPSSL_TRY CURLUSESSL_TRY +#define CURLFTPSSL_CONTROL CURLUSESSL_CONTROL +#define CURLFTPSSL_ALL CURLUSESSL_ALL +#define CURLFTPSSL_LAST CURLUSESSL_LAST +#define curl_ftpssl curl_usessl +#endif /*!CURL_NO_OLDIES*/ + +/* parameter for the CURLOPT_FTP_SSL_CCC option */ +typedef enum { + CURLFTPSSL_CCC_NONE, /* do not send CCC */ + CURLFTPSSL_CCC_PASSIVE, /* Let the server initiate the shutdown */ + CURLFTPSSL_CCC_ACTIVE, /* Initiate the shutdown */ + CURLFTPSSL_CCC_LAST /* not an option, never use */ +} curl_ftpccc; + +/* parameter for the CURLOPT_FTPSSLAUTH option */ +typedef enum { + CURLFTPAUTH_DEFAULT, /* let libcurl decide */ + CURLFTPAUTH_SSL, /* use "AUTH SSL" */ + CURLFTPAUTH_TLS, /* use "AUTH TLS" */ + CURLFTPAUTH_LAST /* not an option, never use */ +} curl_ftpauth; + +/* parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */ +typedef enum { + CURLFTP_CREATE_DIR_NONE, /* do NOT create missing dirs! */ + CURLFTP_CREATE_DIR, /* (FTP/SFTP) if CWD fails, try MKD and then CWD + again if MKD succeeded, for SFTP this does + similar magic */ + CURLFTP_CREATE_DIR_RETRY, /* (FTP only) if CWD fails, try MKD and then CWD + again even if MKD failed! */ + CURLFTP_CREATE_DIR_LAST /* not an option, never use */ +} curl_ftpcreatedir; + +/* parameter for the CURLOPT_FTP_FILEMETHOD option */ +typedef enum { + CURLFTPMETHOD_DEFAULT, /* let libcurl pick */ + CURLFTPMETHOD_MULTICWD, /* single CWD operation for each path part */ + CURLFTPMETHOD_NOCWD, /* no CWD at all */ + CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */ + CURLFTPMETHOD_LAST /* not an option, never use */ +} curl_ftpmethod; + +/* bitmask defines for CURLOPT_HEADEROPT */ +#define CURLHEADER_UNIFIED 0 +#define CURLHEADER_SEPARATE (1<<0) + +/* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */ +#define CURLPROTO_HTTP (1<<0) +#define CURLPROTO_HTTPS (1<<1) +#define CURLPROTO_FTP (1<<2) +#define CURLPROTO_FTPS (1<<3) +#define CURLPROTO_SCP (1<<4) +#define CURLPROTO_SFTP (1<<5) +#define CURLPROTO_TELNET (1<<6) +#define CURLPROTO_LDAP (1<<7) +#define CURLPROTO_LDAPS (1<<8) +#define CURLPROTO_DICT (1<<9) +#define CURLPROTO_FILE (1<<10) +#define CURLPROTO_TFTP (1<<11) +#define CURLPROTO_IMAP (1<<12) +#define CURLPROTO_IMAPS (1<<13) +#define CURLPROTO_POP3 (1<<14) +#define CURLPROTO_POP3S (1<<15) +#define CURLPROTO_SMTP (1<<16) +#define CURLPROTO_SMTPS (1<<17) +#define CURLPROTO_RTSP (1<<18) +#define CURLPROTO_RTMP (1<<19) +#define CURLPROTO_RTMPT (1<<20) +#define CURLPROTO_RTMPE (1<<21) +#define CURLPROTO_RTMPTE (1<<22) +#define CURLPROTO_RTMPS (1<<23) +#define CURLPROTO_RTMPTS (1<<24) +#define CURLPROTO_GOPHER (1<<25) +#define CURLPROTO_SMB (1<<26) +#define CURLPROTO_SMBS (1<<27) +#define CURLPROTO_ALL (~0) /* enable everything */ + +/* long may be 32 or 64 bits, but we should never depend on anything else + but 32 */ +#define CURLOPTTYPE_LONG 0 +#define CURLOPTTYPE_OBJECTPOINT 10000 +#define CURLOPTTYPE_STRINGPOINT 10000 +#define CURLOPTTYPE_FUNCTIONPOINT 20000 +#define CURLOPTTYPE_OFF_T 30000 + +/* *STRINGPOINT is an alias for OBJECTPOINT to allow tools to extract the + string options from the header file */ + +/* name is uppercase CURLOPT_, + type is one of the defined CURLOPTTYPE_ + number is unique identifier */ +#ifdef CINIT +#undef CINIT +#endif + +#ifdef CURL_ISOCPP +#define CINIT(na,t,nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define STRINGPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLOPT_/**/name = type + number +#endif + +/* + * This macro-mania below setups the CURLOPT_[what] enum, to be used with + * curl_easy_setopt(). The first argument in the CINIT() macro is the [what] + * word. + */ + +typedef enum { + /* This is the FILE * or void * the regular output should be written to. */ + CINIT(WRITEDATA, OBJECTPOINT, 1), + + /* The full URL to get/put */ + CINIT(URL, STRINGPOINT, 2), + + /* Port number to connect to, if other than default. */ + CINIT(PORT, LONG, 3), + + /* Name of proxy to use. */ + CINIT(PROXY, STRINGPOINT, 4), + + /* "user:password;options" to use when fetching. */ + CINIT(USERPWD, STRINGPOINT, 5), + + /* "user:password" to use with proxy. */ + CINIT(PROXYUSERPWD, STRINGPOINT, 6), + + /* Range to get, specified as an ASCII string. */ + CINIT(RANGE, STRINGPOINT, 7), + + /* not used */ + + /* Specified file stream to upload from (use as input): */ + CINIT(READDATA, OBJECTPOINT, 9), + + /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE + * bytes big. If this is not used, error messages go to stderr instead: */ + CINIT(ERRORBUFFER, OBJECTPOINT, 10), + + /* Function that will be called to store the output (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(WRITEFUNCTION, FUNCTIONPOINT, 11), + + /* Function that will be called to read the input (instead of fread). The + * parameters will use fread() syntax, make sure to follow them. */ + CINIT(READFUNCTION, FUNCTIONPOINT, 12), + + /* Time-out the read operation after this amount of seconds */ + CINIT(TIMEOUT, LONG, 13), + + /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about + * how large the file being sent really is. That allows better error + * checking and better verifies that the upload was successful. -1 means + * unknown size. + * + * For large file support, there is also a _LARGE version of the key + * which takes an off_t type, allowing platforms with larger off_t + * sizes to handle larger files. See below for INFILESIZE_LARGE. + */ + CINIT(INFILESIZE, LONG, 14), + + /* POST static input fields. */ + CINIT(POSTFIELDS, OBJECTPOINT, 15), + + /* Set the referrer page (needed by some CGIs) */ + CINIT(REFERER, STRINGPOINT, 16), + + /* Set the FTP PORT string (interface name, named or numerical IP address) + Use i.e '-' to use default address. */ + CINIT(FTPPORT, STRINGPOINT, 17), + + /* Set the User-Agent string (examined by some CGIs) */ + CINIT(USERAGENT, STRINGPOINT, 18), + + /* If the download receives less than "low speed limit" bytes/second + * during "low speed time" seconds, the operations is aborted. + * You could i.e if you have a pretty high speed connection, abort if + * it is less than 2000 bytes/sec during 20 seconds. + */ + + /* Set the "low speed limit" */ + CINIT(LOW_SPEED_LIMIT, LONG, 19), + + /* Set the "low speed time" */ + CINIT(LOW_SPEED_TIME, LONG, 20), + + /* Set the continuation offset. + * + * Note there is also a _LARGE version of this key which uses + * off_t types, allowing for large file offsets on platforms which + * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE. + */ + CINIT(RESUME_FROM, LONG, 21), + + /* Set cookie in request: */ + CINIT(COOKIE, STRINGPOINT, 22), + + /* This points to a linked list of headers, struct curl_slist kind. This + list is also used for RTSP (in spite of its name) */ + CINIT(HTTPHEADER, OBJECTPOINT, 23), + + /* This points to a linked list of post entries, struct curl_httppost */ + CINIT(HTTPPOST, OBJECTPOINT, 24), + + /* name of the file keeping your private SSL-certificate */ + CINIT(SSLCERT, STRINGPOINT, 25), + + /* password for the SSL or SSH private key */ + CINIT(KEYPASSWD, STRINGPOINT, 26), + + /* send TYPE parameter? */ + CINIT(CRLF, LONG, 27), + + /* send linked-list of QUOTE commands */ + CINIT(QUOTE, OBJECTPOINT, 28), + + /* send FILE * or void * to store headers to, if you use a callback it + is simply passed to the callback unmodified */ + CINIT(HEADERDATA, OBJECTPOINT, 29), + + /* point to a file to read the initial cookies from, also enables + "cookie awareness" */ + CINIT(COOKIEFILE, STRINGPOINT, 31), + + /* What version to specifically try to use. + See CURL_SSLVERSION defines below. */ + CINIT(SSLVERSION, LONG, 32), + + /* What kind of HTTP time condition to use, see defines */ + CINIT(TIMECONDITION, LONG, 33), + + /* Time to use with the above condition. Specified in number of seconds + since 1 Jan 1970 */ + CINIT(TIMEVALUE, LONG, 34), + + /* 35 = OBSOLETE */ + + /* Custom request, for customizing the get command like + HTTP: DELETE, TRACE and others + FTP: to use a different list command + */ + CINIT(CUSTOMREQUEST, STRINGPOINT, 36), + + /* FILE handle to use instead of stderr */ + CINIT(STDERR, OBJECTPOINT, 37), + + /* 38 is not used */ + + /* send linked-list of post-transfer QUOTE commands */ + CINIT(POSTQUOTE, OBJECTPOINT, 39), + + CINIT(OBSOLETE40, OBJECTPOINT, 40), /* OBSOLETE, do not use! */ + + CINIT(VERBOSE, LONG, 41), /* talk a lot */ + CINIT(HEADER, LONG, 42), /* throw the header out too */ + CINIT(NOPROGRESS, LONG, 43), /* shut off the progress meter */ + CINIT(NOBODY, LONG, 44), /* use HEAD to get http document */ + CINIT(FAILONERROR, LONG, 45), /* no output on http error codes >= 400 */ + CINIT(UPLOAD, LONG, 46), /* this is an upload */ + CINIT(POST, LONG, 47), /* HTTP POST method */ + CINIT(DIRLISTONLY, LONG, 48), /* bare names when listing directories */ + + CINIT(APPEND, LONG, 50), /* Append instead of overwrite on upload! */ + + /* Specify whether to read the user+password from the .netrc or the URL. + * This must be one of the CURL_NETRC_* enums below. */ + CINIT(NETRC, LONG, 51), + + CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */ + + CINIT(TRANSFERTEXT, LONG, 53), /* transfer data in text/ASCII format */ + CINIT(PUT, LONG, 54), /* HTTP PUT */ + + /* 55 = OBSOLETE */ + + /* DEPRECATED + * Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_progress_callback + * prototype defines. */ + CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56), + + /* Data passed to the CURLOPT_PROGRESSFUNCTION and CURLOPT_XFERINFOFUNCTION + callbacks */ + CINIT(PROGRESSDATA, OBJECTPOINT, 57), +#define CURLOPT_XFERINFODATA CURLOPT_PROGRESSDATA + + /* We want the referrer field set automatically when following locations */ + CINIT(AUTOREFERER, LONG, 58), + + /* Port of the proxy, can be set in the proxy string as well with: + "[host]:[port]" */ + CINIT(PROXYPORT, LONG, 59), + + /* size of the POST input data, if strlen() is not good to use */ + CINIT(POSTFIELDSIZE, LONG, 60), + + /* tunnel non-http operations through a HTTP proxy */ + CINIT(HTTPPROXYTUNNEL, LONG, 61), + + /* Set the interface string to use as outgoing network interface */ + CINIT(INTERFACE, STRINGPOINT, 62), + + /* Set the krb4/5 security level, this also enables krb4/5 awareness. This + * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string + * is set but doesn't match one of these, 'private' will be used. */ + CINIT(KRBLEVEL, STRINGPOINT, 63), + + /* Set if we should verify the peer in ssl handshake, set 1 to verify. */ + CINIT(SSL_VERIFYPEER, LONG, 64), + + /* The CApath or CAfile used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAINFO, STRINGPOINT, 65), + + /* 66 = OBSOLETE */ + /* 67 = OBSOLETE */ + + /* Maximum number of http redirects to follow */ + CINIT(MAXREDIRS, LONG, 68), + + /* Pass a long set to 1 to get the date of the requested document (if + possible)! Pass a zero to shut it off. */ + CINIT(FILETIME, LONG, 69), + + /* This points to a linked list of telnet options */ + CINIT(TELNETOPTIONS, OBJECTPOINT, 70), + + /* Max amount of cached alive connections */ + CINIT(MAXCONNECTS, LONG, 71), + + CINIT(OBSOLETE72, LONG, 72), /* OBSOLETE, do not use! */ + + /* 73 = OBSOLETE */ + + /* Set to explicitly use a new connection for the upcoming transfer. + Do not use this unless you're absolutely sure of this, as it makes the + operation slower and is less friendly for the network. */ + CINIT(FRESH_CONNECT, LONG, 74), + + /* Set to explicitly forbid the upcoming transfer's connection to be re-used + when done. Do not use this unless you're absolutely sure of this, as it + makes the operation slower and is less friendly for the network. */ + CINIT(FORBID_REUSE, LONG, 75), + + /* Set to a file name that contains random data for libcurl to use to + seed the random engine when doing SSL connects. */ + CINIT(RANDOM_FILE, STRINGPOINT, 76), + + /* Set to the Entropy Gathering Daemon socket pathname */ + CINIT(EGDSOCKET, STRINGPOINT, 77), + + /* Time-out connect operations after this amount of seconds, if connects are + OK within this time, then fine... This only aborts the connect phase. */ + CINIT(CONNECTTIMEOUT, LONG, 78), + + /* Function that will be called to store headers (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79), + + /* Set this to force the HTTP request to get back to GET. Only really usable + if POST, PUT or a custom request have been used first. + */ + CINIT(HTTPGET, LONG, 80), + + /* Set if we should verify the Common name from the peer certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches the + * provided hostname. */ + CINIT(SSL_VERIFYHOST, LONG, 81), + + /* Specify which file name to write all known cookies in after completed + operation. Set file name to "-" (dash) to make it go to stdout. */ + CINIT(COOKIEJAR, STRINGPOINT, 82), + + /* Specify which SSL ciphers to use */ + CINIT(SSL_CIPHER_LIST, STRINGPOINT, 83), + + /* Specify which HTTP version to use! This must be set to one of the + CURL_HTTP_VERSION* enums set below. */ + CINIT(HTTP_VERSION, LONG, 84), + + /* Specifically switch on or off the FTP engine's use of the EPSV command. By + default, that one will always be attempted before the more traditional + PASV command. */ + CINIT(FTP_USE_EPSV, LONG, 85), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */ + CINIT(SSLCERTTYPE, STRINGPOINT, 86), + + /* name of the file keeping your private SSL-key */ + CINIT(SSLKEY, STRINGPOINT, 87), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */ + CINIT(SSLKEYTYPE, STRINGPOINT, 88), + + /* crypto engine for the SSL-sub system */ + CINIT(SSLENGINE, STRINGPOINT, 89), + + /* set the crypto engine for the SSL-sub system as default + the param has no meaning... + */ + CINIT(SSLENGINE_DEFAULT, LONG, 90), + + /* Non-zero value means to use the global dns cache */ + CINIT(DNS_USE_GLOBAL_CACHE, LONG, 91), /* DEPRECATED, do not use! */ + + /* DNS cache timeout */ + CINIT(DNS_CACHE_TIMEOUT, LONG, 92), + + /* send linked-list of pre-transfer QUOTE commands */ + CINIT(PREQUOTE, OBJECTPOINT, 93), + + /* set the debug function */ + CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94), + + /* set the data for the debug function */ + CINIT(DEBUGDATA, OBJECTPOINT, 95), + + /* mark this as start of a cookie session */ + CINIT(COOKIESESSION, LONG, 96), + + /* The CApath directory used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAPATH, STRINGPOINT, 97), + + /* Instruct libcurl to use a smaller receive buffer */ + CINIT(BUFFERSIZE, LONG, 98), + + /* Instruct libcurl to not use any signal/alarm handlers, even when using + timeouts. This option is useful for multi-threaded applications. + See libcurl-the-guide for more background information. */ + CINIT(NOSIGNAL, LONG, 99), + + /* Provide a CURLShare for mutexing non-ts data */ + CINIT(SHARE, OBJECTPOINT, 100), + + /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default), + CURLPROXY_HTTPS, CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and + CURLPROXY_SOCKS5. */ + CINIT(PROXYTYPE, LONG, 101), + + /* Set the Accept-Encoding string. Use this to tell a server you would like + the response to be compressed. Before 7.21.6, this was known as + CURLOPT_ENCODING */ + CINIT(ACCEPT_ENCODING, STRINGPOINT, 102), + + /* Set pointer to private data */ + CINIT(PRIVATE, OBJECTPOINT, 103), + + /* Set aliases for HTTP 200 in the HTTP Response header */ + CINIT(HTTP200ALIASES, OBJECTPOINT, 104), + + /* Continue to send authentication (user+password) when following locations, + even when hostname changed. This can potentially send off the name + and password to whatever host the server decides. */ + CINIT(UNRESTRICTED_AUTH, LONG, 105), + + /* Specifically switch on or off the FTP engine's use of the EPRT command ( + it also disables the LPRT attempt). By default, those ones will always be + attempted before the good old traditional PORT command. */ + CINIT(FTP_USE_EPRT, LONG, 106), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_USERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(HTTPAUTH, LONG, 107), + + /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx + in second argument. The function must be matching the + curl_ssl_ctx_callback proto. */ + CINIT(SSL_CTX_FUNCTION, FUNCTIONPOINT, 108), + + /* Set the userdata for the ssl context callback function's third + argument */ + CINIT(SSL_CTX_DATA, OBJECTPOINT, 109), + + /* FTP Option that causes missing dirs to be created on the remote server. + In 7.19.4 we introduced the convenience enums for this option using the + CURLFTP_CREATE_DIR prefix. + */ + CINIT(FTP_CREATE_MISSING_DIRS, LONG, 110), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_PROXYUSERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(PROXYAUTH, LONG, 111), + + /* FTP option that changes the timeout, in seconds, associated with + getting a response. This is different from transfer timeout time and + essentially places a demand on the FTP server to acknowledge commands + in a timely manner. */ + CINIT(FTP_RESPONSE_TIMEOUT, LONG, 112), +#define CURLOPT_SERVER_RESPONSE_TIMEOUT CURLOPT_FTP_RESPONSE_TIMEOUT + + /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to + tell libcurl to resolve names to those IP versions only. This only has + affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */ + CINIT(IPRESOLVE, LONG, 113), + + /* Set this option to limit the size of a file that will be downloaded from + an HTTP or FTP server. + + Note there is also _LARGE version which adds large file support for + platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */ + CINIT(MAXFILESIZE, LONG, 114), + + /* See the comment for INFILESIZE above, but in short, specifies + * the size of the file being uploaded. -1 means unknown. + */ + CINIT(INFILESIZE_LARGE, OFF_T, 115), + + /* Sets the continuation offset. There is also a LONG version of this; + * look above for RESUME_FROM. + */ + CINIT(RESUME_FROM_LARGE, OFF_T, 116), + + /* Sets the maximum size of data that will be downloaded from + * an HTTP or FTP server. See MAXFILESIZE above for the LONG version. + */ + CINIT(MAXFILESIZE_LARGE, OFF_T, 117), + + /* Set this option to the file name of your .netrc file you want libcurl + to parse (using the CURLOPT_NETRC option). If not set, libcurl will do + a poor attempt to find the user's home directory and check for a .netrc + file in there. */ + CINIT(NETRC_FILE, STRINGPOINT, 118), + + /* Enable SSL/TLS for FTP, pick one of: + CURLUSESSL_TRY - try using SSL, proceed anyway otherwise + CURLUSESSL_CONTROL - SSL for the control connection or fail + CURLUSESSL_ALL - SSL for all communication or fail + */ + CINIT(USE_SSL, LONG, 119), + + /* The _LARGE version of the standard POSTFIELDSIZE option */ + CINIT(POSTFIELDSIZE_LARGE, OFF_T, 120), + + /* Enable/disable the TCP Nagle algorithm */ + CINIT(TCP_NODELAY, LONG, 121), + + /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 123 OBSOLETE. Gone in 7.16.0 */ + /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 127 OBSOLETE. Gone in 7.16.0 */ + /* 128 OBSOLETE. Gone in 7.16.0 */ + + /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option + can be used to change libcurl's default action which is to first try + "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK + response has been received. + + Available parameters are: + CURLFTPAUTH_DEFAULT - let libcurl decide + CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS + CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL + */ + CINIT(FTPSSLAUTH, LONG, 129), + + CINIT(IOCTLFUNCTION, FUNCTIONPOINT, 130), + CINIT(IOCTLDATA, OBJECTPOINT, 131), + + /* 132 OBSOLETE. Gone in 7.16.0 */ + /* 133 OBSOLETE. Gone in 7.16.0 */ + + /* zero terminated string for pass on to the FTP server when asked for + "account" info */ + CINIT(FTP_ACCOUNT, STRINGPOINT, 134), + + /* feed cookie into cookie engine */ + CINIT(COOKIELIST, STRINGPOINT, 135), + + /* ignore Content-Length */ + CINIT(IGNORE_CONTENT_LENGTH, LONG, 136), + + /* Set to non-zero to skip the IP address received in a 227 PASV FTP server + response. Typically used for FTP-SSL purposes but is not restricted to + that. libcurl will then instead use the same IP address it used for the + control connection. */ + CINIT(FTP_SKIP_PASV_IP, LONG, 137), + + /* Select "file method" to use when doing FTP, see the curl_ftpmethod + above. */ + CINIT(FTP_FILEMETHOD, LONG, 138), + + /* Local port number to bind the socket to */ + CINIT(LOCALPORT, LONG, 139), + + /* Number of ports to try, including the first one set with LOCALPORT. + Thus, setting it to 1 will make no additional attempts but the first. + */ + CINIT(LOCALPORTRANGE, LONG, 140), + + /* no transfer, set up connection and let application use the socket by + extracting it with CURLINFO_LASTSOCKET */ + CINIT(CONNECT_ONLY, LONG, 141), + + /* Function that will be called to convert from the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_FROM_NETWORK_FUNCTION, FUNCTIONPOINT, 142), + + /* Function that will be called to convert to the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_TO_NETWORK_FUNCTION, FUNCTIONPOINT, 143), + + /* Function that will be called to convert from UTF8 + (instead of using the iconv calls in libcurl) + Note that this is used only for SSL certificate processing */ + CINIT(CONV_FROM_UTF8_FUNCTION, FUNCTIONPOINT, 144), + + /* if the connection proceeds too quickly then need to slow it down */ + /* limit-rate: maximum number of bytes per second to send or receive */ + CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145), + CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146), + + /* Pointer to command string to send if USER/PASS fails. */ + CINIT(FTP_ALTERNATIVE_TO_USER, STRINGPOINT, 147), + + /* callback function for setting socket options */ + CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148), + CINIT(SOCKOPTDATA, OBJECTPOINT, 149), + + /* set to 0 to disable session ID re-use for this transfer, default is + enabled (== 1) */ + CINIT(SSL_SESSIONID_CACHE, LONG, 150), + + /* allowed SSH authentication methods */ + CINIT(SSH_AUTH_TYPES, LONG, 151), + + /* Used by scp/sftp to do public/private key authentication */ + CINIT(SSH_PUBLIC_KEYFILE, STRINGPOINT, 152), + CINIT(SSH_PRIVATE_KEYFILE, STRINGPOINT, 153), + + /* Send CCC (Clear Command Channel) after authentication */ + CINIT(FTP_SSL_CCC, LONG, 154), + + /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */ + CINIT(TIMEOUT_MS, LONG, 155), + CINIT(CONNECTTIMEOUT_MS, LONG, 156), + + /* set to zero to disable the libcurl's decoding and thus pass the raw body + data to the application even when it is encoded/compressed */ + CINIT(HTTP_TRANSFER_DECODING, LONG, 157), + CINIT(HTTP_CONTENT_DECODING, LONG, 158), + + /* Permission used when creating new files and directories on the remote + server for protocols that support it, SFTP/SCP/FILE */ + CINIT(NEW_FILE_PERMS, LONG, 159), + CINIT(NEW_DIRECTORY_PERMS, LONG, 160), + + /* Set the behaviour of POST when redirecting. Values must be set to one + of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */ + CINIT(POSTREDIR, LONG, 161), + + /* used by scp/sftp to verify the host's public key */ + CINIT(SSH_HOST_PUBLIC_KEY_MD5, STRINGPOINT, 162), + + /* Callback function for opening socket (instead of socket(2)). Optionally, + callback is able change the address or refuse to connect returning + CURL_SOCKET_BAD. The callback should have type + curl_opensocket_callback */ + CINIT(OPENSOCKETFUNCTION, FUNCTIONPOINT, 163), + CINIT(OPENSOCKETDATA, OBJECTPOINT, 164), + + /* POST volatile input fields. */ + CINIT(COPYPOSTFIELDS, OBJECTPOINT, 165), + + /* set transfer mode (;type=) when doing FTP via an HTTP proxy */ + CINIT(PROXY_TRANSFER_MODE, LONG, 166), + + /* Callback function for seeking in the input stream */ + CINIT(SEEKFUNCTION, FUNCTIONPOINT, 167), + CINIT(SEEKDATA, OBJECTPOINT, 168), + + /* CRL file */ + CINIT(CRLFILE, STRINGPOINT, 169), + + /* Issuer certificate */ + CINIT(ISSUERCERT, STRINGPOINT, 170), + + /* (IPv6) Address scope */ + CINIT(ADDRESS_SCOPE, LONG, 171), + + /* Collect certificate chain info and allow it to get retrievable with + CURLINFO_CERTINFO after the transfer is complete. */ + CINIT(CERTINFO, LONG, 172), + + /* "name" and "pwd" to use when fetching. */ + CINIT(USERNAME, STRINGPOINT, 173), + CINIT(PASSWORD, STRINGPOINT, 174), + + /* "name" and "pwd" to use with Proxy when fetching. */ + CINIT(PROXYUSERNAME, STRINGPOINT, 175), + CINIT(PROXYPASSWORD, STRINGPOINT, 176), + + /* Comma separated list of hostnames defining no-proxy zones. These should + match both hostnames directly, and hostnames within a domain. For + example, local.com will match local.com and www.local.com, but NOT + notlocal.com or www.notlocal.com. For compatibility with other + implementations of this, .local.com will be considered to be the same as + local.com. A single * is the only valid wildcard, and effectively + disables the use of proxy. */ + CINIT(NOPROXY, STRINGPOINT, 177), + + /* block size for TFTP transfers */ + CINIT(TFTP_BLKSIZE, LONG, 178), + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_SERVICE, STRINGPOINT, 179), /* DEPRECATED, do not use! */ + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_NEC, LONG, 180), + + /* set the bitmask for the protocols that are allowed to be used for the + transfer, which thus helps the app which takes URLs from users or other + external inputs and want to restrict what protocol(s) to deal + with. Defaults to CURLPROTO_ALL. */ + CINIT(PROTOCOLS, LONG, 181), + + /* set the bitmask for the protocols that libcurl is allowed to follow to, + as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs + to be set in both bitmasks to be allowed to get redirected to. Defaults + to all protocols except FILE and SCP. */ + CINIT(REDIR_PROTOCOLS, LONG, 182), + + /* set the SSH knownhost file name to use */ + CINIT(SSH_KNOWNHOSTS, STRINGPOINT, 183), + + /* set the SSH host key callback, must point to a curl_sshkeycallback + function */ + CINIT(SSH_KEYFUNCTION, FUNCTIONPOINT, 184), + + /* set the SSH host key callback custom pointer */ + CINIT(SSH_KEYDATA, OBJECTPOINT, 185), + + /* set the SMTP mail originator */ + CINIT(MAIL_FROM, STRINGPOINT, 186), + + /* set the list of SMTP mail receiver(s) */ + CINIT(MAIL_RCPT, OBJECTPOINT, 187), + + /* FTP: send PRET before PASV */ + CINIT(FTP_USE_PRET, LONG, 188), + + /* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */ + CINIT(RTSP_REQUEST, LONG, 189), + + /* The RTSP session identifier */ + CINIT(RTSP_SESSION_ID, STRINGPOINT, 190), + + /* The RTSP stream URI */ + CINIT(RTSP_STREAM_URI, STRINGPOINT, 191), + + /* The Transport: header to use in RTSP requests */ + CINIT(RTSP_TRANSPORT, STRINGPOINT, 192), + + /* Manually initialize the client RTSP CSeq for this handle */ + CINIT(RTSP_CLIENT_CSEQ, LONG, 193), + + /* Manually initialize the server RTSP CSeq for this handle */ + CINIT(RTSP_SERVER_CSEQ, LONG, 194), + + /* The stream to pass to INTERLEAVEFUNCTION. */ + CINIT(INTERLEAVEDATA, OBJECTPOINT, 195), + + /* Let the application define a custom write method for RTP data */ + CINIT(INTERLEAVEFUNCTION, FUNCTIONPOINT, 196), + + /* Turn on wildcard matching */ + CINIT(WILDCARDMATCH, LONG, 197), + + /* Directory matching callback called before downloading of an + individual file (chunk) started */ + CINIT(CHUNK_BGN_FUNCTION, FUNCTIONPOINT, 198), + + /* Directory matching callback called after the file (chunk) + was downloaded, or skipped */ + CINIT(CHUNK_END_FUNCTION, FUNCTIONPOINT, 199), + + /* Change match (fnmatch-like) callback for wildcard matching */ + CINIT(FNMATCH_FUNCTION, FUNCTIONPOINT, 200), + + /* Let the application define custom chunk data pointer */ + CINIT(CHUNK_DATA, OBJECTPOINT, 201), + + /* FNMATCH_FUNCTION user pointer */ + CINIT(FNMATCH_DATA, OBJECTPOINT, 202), + + /* send linked-list of name:port:address sets */ + CINIT(RESOLVE, OBJECTPOINT, 203), + + /* Set a username for authenticated TLS */ + CINIT(TLSAUTH_USERNAME, STRINGPOINT, 204), + + /* Set a password for authenticated TLS */ + CINIT(TLSAUTH_PASSWORD, STRINGPOINT, 205), + + /* Set authentication type for authenticated TLS */ + CINIT(TLSAUTH_TYPE, STRINGPOINT, 206), + + /* Set to 1 to enable the "TE:" header in HTTP requests to ask for + compressed transfer-encoded responses. Set to 0 to disable the use of TE: + in outgoing requests. The current default is 0, but it might change in a + future libcurl release. + + libcurl will ask for the compressed methods it knows of, and if that + isn't any, it will not ask for transfer-encoding at all even if this + option is set to 1. + + */ + CINIT(TRANSFER_ENCODING, LONG, 207), + + /* Callback function for closing socket (instead of close(2)). The callback + should have type curl_closesocket_callback */ + CINIT(CLOSESOCKETFUNCTION, FUNCTIONPOINT, 208), + CINIT(CLOSESOCKETDATA, OBJECTPOINT, 209), + + /* allow GSSAPI credential delegation */ + CINIT(GSSAPI_DELEGATION, LONG, 210), + + /* Set the name servers to use for DNS resolution */ + CINIT(DNS_SERVERS, STRINGPOINT, 211), + + /* Time-out accept operations (currently for FTP only) after this amount + of miliseconds. */ + CINIT(ACCEPTTIMEOUT_MS, LONG, 212), + + /* Set TCP keepalive */ + CINIT(TCP_KEEPALIVE, LONG, 213), + + /* non-universal keepalive knobs (Linux, AIX, HP-UX, more) */ + CINIT(TCP_KEEPIDLE, LONG, 214), + CINIT(TCP_KEEPINTVL, LONG, 215), + + /* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */ + CINIT(SSL_OPTIONS, LONG, 216), + + /* Set the SMTP auth originator */ + CINIT(MAIL_AUTH, STRINGPOINT, 217), + + /* Enable/disable SASL initial response */ + CINIT(SASL_IR, LONG, 218), + + /* Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_xferinfo_callback + * prototype defines. (Deprecates CURLOPT_PROGRESSFUNCTION) */ + CINIT(XFERINFOFUNCTION, FUNCTIONPOINT, 219), + + /* The XOAUTH2 bearer token */ + CINIT(XOAUTH2_BEARER, STRINGPOINT, 220), + + /* Set the interface string to use as outgoing network + * interface for DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_INTERFACE, STRINGPOINT, 221), + + /* Set the local IPv4 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_LOCAL_IP4, STRINGPOINT, 222), + + /* Set the local IPv4 address to use for outgoing DNS requests. + * Only supported by the c-ares DNS backend */ + CINIT(DNS_LOCAL_IP6, STRINGPOINT, 223), + + /* Set authentication options directly */ + CINIT(LOGIN_OPTIONS, STRINGPOINT, 224), + + /* Enable/disable TLS NPN extension (http2 over ssl might fail without) */ + CINIT(SSL_ENABLE_NPN, LONG, 225), + + /* Enable/disable TLS ALPN extension (http2 over ssl might fail without) */ + CINIT(SSL_ENABLE_ALPN, LONG, 226), + + /* Time to wait for a response to a HTTP request containing an + * Expect: 100-continue header before sending the data anyway. */ + CINIT(EXPECT_100_TIMEOUT_MS, LONG, 227), + + /* This points to a linked list of headers used for proxy requests only, + struct curl_slist kind */ + CINIT(PROXYHEADER, OBJECTPOINT, 228), + + /* Pass in a bitmask of "header options" */ + CINIT(HEADEROPT, LONG, 229), + + /* The public key in DER form used to validate the peer public key + this option is used only if SSL_VERIFYPEER is true */ + CINIT(PINNEDPUBLICKEY, STRINGPOINT, 230), + + /* Path to Unix domain socket */ + CINIT(UNIX_SOCKET_PATH, STRINGPOINT, 231), + + /* Set if we should verify the certificate status. */ + CINIT(SSL_VERIFYSTATUS, LONG, 232), + + /* Set if we should enable TLS false start. */ + CINIT(SSL_FALSESTART, LONG, 233), + + /* Do not squash dot-dot sequences */ + CINIT(PATH_AS_IS, LONG, 234), + + /* Proxy Service Name */ + CINIT(PROXY_SERVICE_NAME, STRINGPOINT, 235), + + /* Service Name */ + CINIT(SERVICE_NAME, STRINGPOINT, 236), + + /* Wait/don't wait for pipe/mutex to clarify */ + CINIT(PIPEWAIT, LONG, 237), + + /* Set the protocol used when curl is given a URL without a protocol */ + CINIT(DEFAULT_PROTOCOL, STRINGPOINT, 238), + + /* Set stream weight, 1 - 256 (default is 16) */ + CINIT(STREAM_WEIGHT, LONG, 239), + + /* Set stream dependency on another CURL handle */ + CINIT(STREAM_DEPENDS, OBJECTPOINT, 240), + + /* Set E-xclusive stream dependency on another CURL handle */ + CINIT(STREAM_DEPENDS_E, OBJECTPOINT, 241), + + /* Do not send any tftp option requests to the server */ + CINIT(TFTP_NO_OPTIONS, LONG, 242), + + /* Linked-list of host:port:connect-to-host:connect-to-port, + overrides the URL's host:port (only for the network layer) */ + CINIT(CONNECT_TO, OBJECTPOINT, 243), + + /* Set TCP Fast Open */ + CINIT(TCP_FASTOPEN, LONG, 244), + + /* Continue to send data if the server responds early with an + * HTTP status code >= 300 */ + CINIT(KEEP_SENDING_ON_ERROR, LONG, 245), + + /* The CApath or CAfile used to validate the proxy certificate + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CINIT(PROXY_CAINFO, STRINGPOINT, 246), + + /* The CApath directory used to validate the proxy certificate + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CINIT(PROXY_CAPATH, STRINGPOINT, 247), + + /* Set if we should verify the proxy in ssl handshake, + set 1 to verify. */ + CINIT(PROXY_SSL_VERIFYPEER, LONG, 248), + + /* Set if we should verify the Common name from the proxy certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches + * the provided hostname. */ + CINIT(PROXY_SSL_VERIFYHOST, LONG, 249), + + /* What version to specifically try to use for proxy. + See CURL_SSLVERSION defines below. */ + CINIT(PROXY_SSLVERSION, LONG, 250), + + /* Set a username for authenticated TLS for proxy */ + CINIT(PROXY_TLSAUTH_USERNAME, STRINGPOINT, 251), + + /* Set a password for authenticated TLS for proxy */ + CINIT(PROXY_TLSAUTH_PASSWORD, STRINGPOINT, 252), + + /* Set authentication type for authenticated TLS for proxy */ + CINIT(PROXY_TLSAUTH_TYPE, STRINGPOINT, 253), + + /* name of the file keeping your private SSL-certificate for proxy */ + CINIT(PROXY_SSLCERT, STRINGPOINT, 254), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") for + proxy */ + CINIT(PROXY_SSLCERTTYPE, STRINGPOINT, 255), + + /* name of the file keeping your private SSL-key for proxy */ + CINIT(PROXY_SSLKEY, STRINGPOINT, 256), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") for + proxy */ + CINIT(PROXY_SSLKEYTYPE, STRINGPOINT, 257), + + /* password for the SSL private key for proxy */ + CINIT(PROXY_KEYPASSWD, STRINGPOINT, 258), + + /* Specify which SSL ciphers to use for proxy */ + CINIT(PROXY_SSL_CIPHER_LIST, STRINGPOINT, 259), + + /* CRL file for proxy */ + CINIT(PROXY_CRLFILE, STRINGPOINT, 260), + + /* Enable/disable specific SSL features with a bitmask for proxy, see + CURLSSLOPT_* */ + CINIT(PROXY_SSL_OPTIONS, LONG, 261), + + /* Name of pre proxy to use. */ + CINIT(PRE_PROXY, STRINGPOINT, 262), + + /* The public key in DER form used to validate the proxy public key + this option is used only if PROXY_SSL_VERIFYPEER is true */ + CINIT(PROXY_PINNEDPUBLICKEY, STRINGPOINT, 263), + + /* Path to an abstract Unix domain socket */ + CINIT(ABSTRACT_UNIX_SOCKET, STRINGPOINT, 264), + + /* Suppress proxy CONNECT response headers from user callbacks */ + CINIT(SUPPRESS_CONNECT_HEADERS, LONG, 265), + + CURLOPT_LASTENTRY /* the last unused */ +} CURLoption; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2011 */ + +/* This was added in version 7.19.1 */ +#define CURLOPT_POST301 CURLOPT_POSTREDIR + +/* These are scheduled to disappear by 2009 */ + +/* The following were added in 7.17.0 */ +#define CURLOPT_SSLKEYPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_FTPAPPEND CURLOPT_APPEND +#define CURLOPT_FTPLISTONLY CURLOPT_DIRLISTONLY +#define CURLOPT_FTP_SSL CURLOPT_USE_SSL + +/* The following were added earlier */ + +#define CURLOPT_SSLCERTPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_KRB4LEVEL CURLOPT_KRBLEVEL + +#else +/* This is set if CURL_NO_OLDIES is defined at compile-time */ +#undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */ +#endif + + + /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host + name resolves addresses using more than one IP protocol version, this + option might be handy to force libcurl to use a specific IP version. */ +#define CURL_IPRESOLVE_WHATEVER 0 /* default, resolves addresses to all IP + versions that your system allows */ +#define CURL_IPRESOLVE_V4 1 /* resolve to IPv4 addresses */ +#define CURL_IPRESOLVE_V6 2 /* resolve to IPv6 addresses */ + + /* three convenient "aliases" that follow the name scheme better */ +#define CURLOPT_RTSPHEADER CURLOPT_HTTPHEADER + + /* These enums are for use with the CURLOPT_HTTP_VERSION option. */ +enum { + CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd + like the library to choose the best possible + for us! */ + CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */ + CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */ + CURL_HTTP_VERSION_2_0, /* please use HTTP 2 in the request */ + CURL_HTTP_VERSION_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */ + CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, /* please use HTTP 2 without HTTP/1.1 + Upgrade */ + + CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */ +}; + +/* Convenience definition simple because the name of the version is HTTP/2 and + not 2.0. The 2_0 version of the enum name was set while the version was + still planned to be 2.0 and we stick to it for compatibility. */ +#define CURL_HTTP_VERSION_2 CURL_HTTP_VERSION_2_0 + +/* + * Public API enums for RTSP requests + */ +enum { + CURL_RTSPREQ_NONE, /* first in list */ + CURL_RTSPREQ_OPTIONS, + CURL_RTSPREQ_DESCRIBE, + CURL_RTSPREQ_ANNOUNCE, + CURL_RTSPREQ_SETUP, + CURL_RTSPREQ_PLAY, + CURL_RTSPREQ_PAUSE, + CURL_RTSPREQ_TEARDOWN, + CURL_RTSPREQ_GET_PARAMETER, + CURL_RTSPREQ_SET_PARAMETER, + CURL_RTSPREQ_RECORD, + CURL_RTSPREQ_RECEIVE, + CURL_RTSPREQ_LAST /* last in list */ +}; + + /* These enums are for use with the CURLOPT_NETRC option. */ +enum CURL_NETRC_OPTION { + CURL_NETRC_IGNORED, /* The .netrc will never be read. + * This is the default. */ + CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred + * to one in the .netrc. */ + CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored. + * Unless one is set programmatically, the .netrc + * will be queried. */ + CURL_NETRC_LAST +}; + +enum { + CURL_SSLVERSION_DEFAULT, + CURL_SSLVERSION_TLSv1, /* TLS 1.x */ + CURL_SSLVERSION_SSLv2, + CURL_SSLVERSION_SSLv3, + CURL_SSLVERSION_TLSv1_0, + CURL_SSLVERSION_TLSv1_1, + CURL_SSLVERSION_TLSv1_2, + CURL_SSLVERSION_TLSv1_3, + + CURL_SSLVERSION_LAST /* never use, keep last */ +}; + +enum { + CURL_SSLVERSION_MAX_NONE = 0, + CURL_SSLVERSION_MAX_DEFAULT = (CURL_SSLVERSION_TLSv1 << 16), + CURL_SSLVERSION_MAX_TLSv1_0 = (CURL_SSLVERSION_TLSv1_0 << 16), + CURL_SSLVERSION_MAX_TLSv1_1 = (CURL_SSLVERSION_TLSv1_1 << 16), + CURL_SSLVERSION_MAX_TLSv1_2 = (CURL_SSLVERSION_TLSv1_2 << 16), + CURL_SSLVERSION_MAX_TLSv1_3 = (CURL_SSLVERSION_TLSv1_3 << 16), + + /* never use, keep last */ + CURL_SSLVERSION_MAX_LAST = (CURL_SSLVERSION_LAST << 16) +}; + +enum CURL_TLSAUTH { + CURL_TLSAUTH_NONE, + CURL_TLSAUTH_SRP, + CURL_TLSAUTH_LAST /* never use, keep last */ +}; + +/* symbols to use with CURLOPT_POSTREDIR. + CURL_REDIR_POST_301, CURL_REDIR_POST_302 and CURL_REDIR_POST_303 + can be bitwise ORed so that CURL_REDIR_POST_301 | CURL_REDIR_POST_302 + | CURL_REDIR_POST_303 == CURL_REDIR_POST_ALL */ + +#define CURL_REDIR_GET_ALL 0 +#define CURL_REDIR_POST_301 1 +#define CURL_REDIR_POST_302 2 +#define CURL_REDIR_POST_303 4 +#define CURL_REDIR_POST_ALL \ + (CURL_REDIR_POST_301|CURL_REDIR_POST_302|CURL_REDIR_POST_303) + +typedef enum { + CURL_TIMECOND_NONE, + + CURL_TIMECOND_IFMODSINCE, + CURL_TIMECOND_IFUNMODSINCE, + CURL_TIMECOND_LASTMOD, + + CURL_TIMECOND_LAST +} curl_TimeCond; + + +/* curl_strequal() and curl_strnequal() are subject for removal in a future + libcurl, see lib/README.curlx for details + + !checksrc! disable SPACEBEFOREPAREN 2 +*/ +CURL_EXTERN int (curl_strequal)(const char *s1, const char *s2); +CURL_EXTERN int (curl_strnequal)(const char *s1, const char *s2, size_t n); + +/* name is uppercase CURLFORM_ */ +#ifdef CFINIT +#undef CFINIT +#endif + +#ifdef CURL_ISOCPP +#define CFINIT(name) CURLFORM_ ## name +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define CFINIT(name) CURLFORM_/**/name +#endif + +typedef enum { + CFINIT(NOTHING), /********* the first one is unused ************/ + + /* */ + CFINIT(COPYNAME), + CFINIT(PTRNAME), + CFINIT(NAMELENGTH), + CFINIT(COPYCONTENTS), + CFINIT(PTRCONTENTS), + CFINIT(CONTENTSLENGTH), + CFINIT(FILECONTENT), + CFINIT(ARRAY), + CFINIT(OBSOLETE), + CFINIT(FILE), + + CFINIT(BUFFER), + CFINIT(BUFFERPTR), + CFINIT(BUFFERLENGTH), + + CFINIT(CONTENTTYPE), + CFINIT(CONTENTHEADER), + CFINIT(FILENAME), + CFINIT(END), + CFINIT(OBSOLETE2), + + CFINIT(STREAM), + CFINIT(CONTENTLEN), /* added in 7.46.0, provide a curl_off_t length */ + + CURLFORM_LASTENTRY /* the last unused */ +} CURLformoption; + +#undef CFINIT /* done */ + +/* structure to be used as parameter for CURLFORM_ARRAY */ +struct curl_forms { + CURLformoption option; + const char *value; +}; + +/* use this for multipart formpost building */ +/* Returns code for curl_formadd() + * + * Returns: + * CURL_FORMADD_OK on success + * CURL_FORMADD_MEMORY if the FormInfo allocation fails + * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form + * CURL_FORMADD_NULL if a null pointer was given for a char + * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed + * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used + * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) + * CURL_FORMADD_MEMORY if a curl_httppost struct cannot be allocated + * CURL_FORMADD_MEMORY if some allocation for string copying failed. + * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array + * + ***************************************************************************/ +typedef enum { + CURL_FORMADD_OK, /* first, no error */ + + CURL_FORMADD_MEMORY, + CURL_FORMADD_OPTION_TWICE, + CURL_FORMADD_NULL, + CURL_FORMADD_UNKNOWN_OPTION, + CURL_FORMADD_INCOMPLETE, + CURL_FORMADD_ILLEGAL_ARRAY, + CURL_FORMADD_DISABLED, /* libcurl was built with this disabled */ + + CURL_FORMADD_LAST /* last */ +} CURLFORMcode; + +/* + * NAME curl_formadd() + * + * DESCRIPTION + * + * Pretty advanced function for building multi-part formposts. Each invoke + * adds one part that together construct a full post. Then use + * CURLOPT_HTTPPOST to send it off to libcurl. + */ +CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, + struct curl_httppost **last_post, + ...); + +/* + * callback function for curl_formget() + * The void *arg pointer will be the one passed as second argument to + * curl_formget(). + * The character buffer passed to it must not be freed. + * Should return the buffer length passed to it as the argument "len" on + * success. + */ +typedef size_t (*curl_formget_callback)(void *arg, const char *buf, + size_t len); + +/* + * NAME curl_formget() + * + * DESCRIPTION + * + * Serialize a curl_httppost struct built with curl_formadd(). + * Accepts a void pointer as second argument which will be passed to + * the curl_formget_callback function. + * Returns 0 on success. + */ +CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg, + curl_formget_callback append); +/* + * NAME curl_formfree() + * + * DESCRIPTION + * + * Free a multipart formpost previously built with curl_formadd(). + */ +CURL_EXTERN void curl_formfree(struct curl_httppost *form); + +/* + * NAME curl_getenv() + * + * DESCRIPTION + * + * Returns a malloc()'ed string that MUST be curl_free()ed after usage is + * complete. DEPRECATED - see lib/README.curlx + */ +CURL_EXTERN char *curl_getenv(const char *variable); + +/* + * NAME curl_version() + * + * DESCRIPTION + * + * Returns a static ascii string of the libcurl version. + */ +CURL_EXTERN char *curl_version(void); + +/* + * NAME curl_easy_escape() + * + * DESCRIPTION + * + * Escapes URL strings (converts all letters consider illegal in URLs to their + * %XX versions). This function returns a new allocated string or NULL if an + * error occurred. + */ +CURL_EXTERN char *curl_easy_escape(CURL *handle, + const char *string, + int length); + +/* the previous version: */ +CURL_EXTERN char *curl_escape(const char *string, + int length); + + +/* + * NAME curl_easy_unescape() + * + * DESCRIPTION + * + * Unescapes URL encoding in strings (converts all %XX codes to their 8bit + * versions). This function returns a new allocated string or NULL if an error + * occurred. + * Conversion Note: On non-ASCII platforms the ASCII %XX codes are + * converted into the host encoding. + */ +CURL_EXTERN char *curl_easy_unescape(CURL *handle, + const char *string, + int length, + int *outlength); + +/* the previous version */ +CURL_EXTERN char *curl_unescape(const char *string, + int length); + +/* + * NAME curl_free() + * + * DESCRIPTION + * + * Provided for de-allocation in the same translation unit that did the + * allocation. Added in libcurl 7.10 + */ +CURL_EXTERN void curl_free(void *p); + +/* + * NAME curl_global_init() + * + * DESCRIPTION + * + * curl_global_init() should be invoked exactly once for each application that + * uses libcurl and before any call of other libcurl functions. + * + * This function is not thread-safe! + */ +CURL_EXTERN CURLcode curl_global_init(long flags); + +/* + * NAME curl_global_init_mem() + * + * DESCRIPTION + * + * curl_global_init() or curl_global_init_mem() should be invoked exactly once + * for each application that uses libcurl. This function can be used to + * initialize libcurl and set user defined memory management callback + * functions. Users can implement memory management routines to check for + * memory leaks, check for mis-use of the curl library etc. User registered + * callback routines with be invoked by this library instead of the system + * memory management routines like malloc, free etc. + */ +CURL_EXTERN CURLcode curl_global_init_mem(long flags, + curl_malloc_callback m, + curl_free_callback f, + curl_realloc_callback r, + curl_strdup_callback s, + curl_calloc_callback c); + +/* + * NAME curl_global_cleanup() + * + * DESCRIPTION + * + * curl_global_cleanup() should be invoked exactly once for each application + * that uses libcurl + */ +CURL_EXTERN void curl_global_cleanup(void); + +/* linked-list structure for the CURLOPT_QUOTE option (and other) */ +struct curl_slist { + char *data; + struct curl_slist *next; +}; + +/* + * NAME curl_slist_append() + * + * DESCRIPTION + * + * Appends a string to a linked list. If no list exists, it will be created + * first. Returns the new list, after appending. + */ +CURL_EXTERN struct curl_slist *curl_slist_append(struct curl_slist *, + const char *); + +/* + * NAME curl_slist_free_all() + * + * DESCRIPTION + * + * free a previously built curl_slist. + */ +CURL_EXTERN void curl_slist_free_all(struct curl_slist *); + +/* + * NAME curl_getdate() + * + * DESCRIPTION + * + * Returns the time, in seconds since 1 Jan 1970 of the time string given in + * the first argument. The time argument in the second parameter is unused + * and should be set to NULL. + */ +CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused); + +/* info about the certificate chain, only for OpenSSL builds. Asked + for with CURLOPT_CERTINFO / CURLINFO_CERTINFO */ +struct curl_certinfo { + int num_of_certs; /* number of certificates with information */ + struct curl_slist **certinfo; /* for each index in this array, there's a + linked list with textual information in the + format "name: value" */ +}; + +/* enum for the different supported SSL backends */ +typedef enum { + CURLSSLBACKEND_NONE = 0, + CURLSSLBACKEND_OPENSSL = 1, + CURLSSLBACKEND_GNUTLS = 2, + CURLSSLBACKEND_NSS = 3, + CURLSSLBACKEND_OBSOLETE4 = 4, /* Was QSOSSL. */ + CURLSSLBACKEND_GSKIT = 5, + CURLSSLBACKEND_POLARSSL = 6, + CURLSSLBACKEND_CYASSL = 7, + CURLSSLBACKEND_SCHANNEL = 8, + CURLSSLBACKEND_DARWINSSL = 9, + CURLSSLBACKEND_AXTLS = 10, + CURLSSLBACKEND_MBEDTLS = 11 +} curl_sslbackend; + +/* aliases for library clones and renames */ +#define CURLSSLBACKEND_LIBRESSL 1 +#define CURLSSLBACKEND_BORINGSSL 1 +#define CURLSSLBACKEND_WOLFSSL 6 + +/* Information about the SSL library used and the respective internal SSL + handle, which can be used to obtain further information regarding the + connection. Asked for with CURLINFO_TLS_SSL_PTR or CURLINFO_TLS_SESSION. */ +struct curl_tlssessioninfo { + curl_sslbackend backend; + void *internals; +}; + +#define CURLINFO_STRING 0x100000 +#define CURLINFO_LONG 0x200000 +#define CURLINFO_DOUBLE 0x300000 +#define CURLINFO_SLIST 0x400000 +#define CURLINFO_SOCKET 0x500000 +#define CURLINFO_MASK 0x0fffff +#define CURLINFO_TYPEMASK 0xf00000 + +typedef enum { + CURLINFO_NONE, /* first, never use this */ + CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1, + CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, + CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3, + CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4, + CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5, + CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6, + CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7, + CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8, + CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9, + CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10, + CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11, + CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12, + CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13, + CURLINFO_FILETIME = CURLINFO_LONG + 14, + CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15, + CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16, + CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17, + CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18, + CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19, + CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20, + CURLINFO_PRIVATE = CURLINFO_STRING + 21, + CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22, + CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23, + CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24, + CURLINFO_OS_ERRNO = CURLINFO_LONG + 25, + CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26, + CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27, + CURLINFO_COOKIELIST = CURLINFO_SLIST + 28, + CURLINFO_LASTSOCKET = CURLINFO_LONG + 29, + CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30, + CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31, + CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32, + CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33, + CURLINFO_CERTINFO = CURLINFO_SLIST + 34, + CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35, + CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36, + CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37, + CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38, + CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39, + CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40, + CURLINFO_LOCAL_IP = CURLINFO_STRING + 41, + CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42, + CURLINFO_TLS_SESSION = CURLINFO_SLIST + 43, + CURLINFO_ACTIVESOCKET = CURLINFO_SOCKET + 44, + CURLINFO_TLS_SSL_PTR = CURLINFO_SLIST + 45, + CURLINFO_HTTP_VERSION = CURLINFO_LONG + 46, + CURLINFO_PROXY_SSL_VERIFYRESULT = CURLINFO_LONG + 47, + CURLINFO_PROTOCOL = CURLINFO_LONG + 48, + CURLINFO_SCHEME = CURLINFO_STRING + 49, + /* Fill in new entries below here! */ + + CURLINFO_LASTONE = 49 +} CURLINFO; + +/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as + CURLINFO_HTTP_CODE */ +#define CURLINFO_HTTP_CODE CURLINFO_RESPONSE_CODE + +typedef enum { + CURLCLOSEPOLICY_NONE, /* first, never use this */ + + CURLCLOSEPOLICY_OLDEST, + CURLCLOSEPOLICY_LEAST_RECENTLY_USED, + CURLCLOSEPOLICY_LEAST_TRAFFIC, + CURLCLOSEPOLICY_SLOWEST, + CURLCLOSEPOLICY_CALLBACK, + + CURLCLOSEPOLICY_LAST /* last, never use this */ +} curl_closepolicy; + +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_NOTHING 0 +#define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL +#define CURL_GLOBAL_ACK_EINTR (1<<2) + + +/***************************************************************************** + * Setup defines, protos etc for the sharing stuff. + */ + +/* Different data locks for a single share */ +typedef enum { + CURL_LOCK_DATA_NONE = 0, + /* CURL_LOCK_DATA_SHARE is used internally to say that + * the locking is just made to change the internal state of the share + * itself. + */ + CURL_LOCK_DATA_SHARE, + CURL_LOCK_DATA_COOKIE, + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_SSL_SESSION, + CURL_LOCK_DATA_CONNECT, + CURL_LOCK_DATA_LAST +} curl_lock_data; + +/* Different lock access types */ +typedef enum { + CURL_LOCK_ACCESS_NONE = 0, /* unspecified action */ + CURL_LOCK_ACCESS_SHARED = 1, /* for read perhaps */ + CURL_LOCK_ACCESS_SINGLE = 2, /* for write perhaps */ + CURL_LOCK_ACCESS_LAST /* never use */ +} curl_lock_access; + +typedef void (*curl_lock_function)(CURL *handle, + curl_lock_data data, + curl_lock_access locktype, + void *userptr); +typedef void (*curl_unlock_function)(CURL *handle, + curl_lock_data data, + void *userptr); + + +typedef enum { + CURLSHE_OK, /* all is fine */ + CURLSHE_BAD_OPTION, /* 1 */ + CURLSHE_IN_USE, /* 2 */ + CURLSHE_INVALID, /* 3 */ + CURLSHE_NOMEM, /* 4 out of memory */ + CURLSHE_NOT_BUILT_IN, /* 5 feature not present in lib */ + CURLSHE_LAST /* never use */ +} CURLSHcode; + +typedef enum { + CURLSHOPT_NONE, /* don't use */ + CURLSHOPT_SHARE, /* specify a data type to share */ + CURLSHOPT_UNSHARE, /* specify which data type to stop sharing */ + CURLSHOPT_LOCKFUNC, /* pass in a 'curl_lock_function' pointer */ + CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */ + CURLSHOPT_USERDATA, /* pass in a user data pointer used in the lock/unlock + callback functions */ + CURLSHOPT_LAST /* never use */ +} CURLSHoption; + +CURL_EXTERN CURLSH *curl_share_init(void); +CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...); +CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *); + +/**************************************************************************** + * Structures for querying information about the curl library at runtime. + */ + +typedef enum { + CURLVERSION_FIRST, + CURLVERSION_SECOND, + CURLVERSION_THIRD, + CURLVERSION_FOURTH, + CURLVERSION_LAST /* never actually use this */ +} CURLversion; + +/* The 'CURLVERSION_NOW' is the symbolic name meant to be used by + basically all programs ever that want to get version information. It is + meant to be a built-in version number for what kind of struct the caller + expects. If the struct ever changes, we redefine the NOW to another enum + from above. */ +#define CURLVERSION_NOW CURLVERSION_FOURTH + +typedef struct { + CURLversion age; /* age of the returned struct */ + const char *version; /* LIBCURL_VERSION */ + unsigned int version_num; /* LIBCURL_VERSION_NUM */ + const char *host; /* OS/host/cpu/machine when configured */ + int features; /* bitmask, see defines below */ + const char *ssl_version; /* human readable string */ + long ssl_version_num; /* not used anymore, always 0 */ + const char *libz_version; /* human readable string */ + /* protocols is terminated by an entry with a NULL protoname */ + const char * const *protocols; + + /* The fields below this were added in CURLVERSION_SECOND */ + const char *ares; + int ares_num; + + /* This field was added in CURLVERSION_THIRD */ + const char *libidn; + + /* These field were added in CURLVERSION_FOURTH */ + + /* Same as '_libiconv_version' if built with HAVE_ICONV */ + int iconv_ver_num; + + const char *libssh_version; /* human readable string */ + +} curl_version_info_data; + +#define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */ +#define CURL_VERSION_KERBEROS4 (1<<1) /* Kerberos V4 auth is supported + (deprecated) */ +#define CURL_VERSION_SSL (1<<2) /* SSL options are present */ +#define CURL_VERSION_LIBZ (1<<3) /* libz features are present */ +#define CURL_VERSION_NTLM (1<<4) /* NTLM auth is supported */ +#define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth is supported + (deprecated) */ +#define CURL_VERSION_DEBUG (1<<6) /* Built with debug capabilities */ +#define CURL_VERSION_ASYNCHDNS (1<<7) /* Asynchronous DNS resolves */ +#define CURL_VERSION_SPNEGO (1<<8) /* SPNEGO auth is supported */ +#define CURL_VERSION_LARGEFILE (1<<9) /* Supports files larger than 2GB */ +#define CURL_VERSION_IDN (1<<10) /* Internationized Domain Names are + supported */ +#define CURL_VERSION_SSPI (1<<11) /* Built against Windows SSPI */ +#define CURL_VERSION_CONV (1<<12) /* Character conversions supported */ +#define CURL_VERSION_CURLDEBUG (1<<13) /* Debug memory tracking supported */ +#define CURL_VERSION_TLSAUTH_SRP (1<<14) /* TLS-SRP auth is supported */ +#define CURL_VERSION_NTLM_WB (1<<15) /* NTLM delegation to winbind helper + is suported */ +#define CURL_VERSION_HTTP2 (1<<16) /* HTTP2 support built-in */ +#define CURL_VERSION_GSSAPI (1<<17) /* Built against a GSS-API library */ +#define CURL_VERSION_KERBEROS5 (1<<18) /* Kerberos V5 auth is supported */ +#define CURL_VERSION_UNIX_SOCKETS (1<<19) /* Unix domain sockets support */ +#define CURL_VERSION_PSL (1<<20) /* Mozilla's Public Suffix List, used + for cookie domain verification */ +#define CURL_VERSION_HTTPS_PROXY (1<<21) /* HTTPS-proxy support built-in */ + + /* + * NAME curl_version_info() + * + * DESCRIPTION + * + * This function returns a pointer to a static copy of the version info + * struct. See above. + */ +CURL_EXTERN curl_version_info_data *curl_version_info(CURLversion); + +/* + * NAME curl_easy_strerror() + * + * DESCRIPTION + * + * The curl_easy_strerror function may be used to turn a CURLcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_easy_strerror(CURLcode); + +/* + * NAME curl_share_strerror() + * + * DESCRIPTION + * + * The curl_share_strerror function may be used to turn a CURLSHcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_share_strerror(CURLSHcode); + +/* + * NAME curl_easy_pause() + * + * DESCRIPTION + * + * The curl_easy_pause function pauses or unpauses transfers. Select the new + * state by setting the bitmask, use the convenience defines below. + * + */ +CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask); + +#define CURLPAUSE_RECV (1<<0) +#define CURLPAUSE_RECV_CONT (0) + +#define CURLPAUSE_SEND (1<<2) +#define CURLPAUSE_SEND_CONT (0) + +#define CURLPAUSE_ALL (CURLPAUSE_RECV|CURLPAUSE_SEND) +#define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT|CURLPAUSE_SEND_CONT) + +#ifdef __cplusplus +} +#endif + +/* unfortunately, the easy.h and multi.h include files need options and info + stuff before they can be included! */ +#include "easy.h" /* nothing in curl is fun without the easy stuff */ +#include "multi.h" + +/* the typechecker doesn't work in C++ (yet) */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ + ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && \ + !defined(__cplusplus) && !defined(CURL_DISABLE_TYPECHECK) +#include "typecheck-gcc.h" +#else +#if defined(__STDC__) && (__STDC__ >= 1) +/* This preprocessor magic that replaces a call with the exact same call is + only done to make sure application authors pass exactly three arguments + to these functions. */ +#define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) +#define curl_easy_getinfo(handle,info,arg) curl_easy_getinfo(handle,info,arg) +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) +#endif /* __STDC__ >= 1 */ +#endif /* gcc >= 4.3 && !__cplusplus */ + +#endif /* __CURL_CURL_H */ diff --git a/includes/curl/curlbuild.h b/includes/curl/curlbuild.h new file mode 100644 index 000000000..ae95095fa --- /dev/null +++ b/includes/curl/curlbuild.h @@ -0,0 +1,586 @@ +#ifndef __CURL_CURLBUILD_H +#define __CURL_CURLBUILD_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * See file include/curl/curlbuild.h.in, run configure, and forget + * that this file exists it is only used for non-configure systems. + * But you can keep reading if you want ;-) + * + */ + +/* ================================================================ */ +/* NOTES FOR NON-CONFIGURE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * If you think that something actually needs to be changed, adjusted + * or fixed in this file, then, report it on the libcurl development + * mailing list: https://cool.haxx.se/mailman/listinfo/curl-library/ + * + * Try to keep one section per platform, compiler and architecture, + * otherwise, if an existing section is reused for a different one and + * later on the original is adjusted, probably the piggybacking one can + * be adversely changed. + * + * In order to differentiate between platforms/compilers/architectures + * use only compiler built in predefined preprocessor symbols. + * + * This header file shall only export symbols which are 'curl' or 'CURL' + * prefixed, otherwise public name space would be polluted. + * + * NOTE 2: + * ------- + * + * For any given platform/compiler curl_off_t must be typedef'ed to a + * 64-bit wide signed integral data type. The width of this data type + * must remain constant and independent of any possible large file + * support settings. + * + * As an exception to the above, curl_off_t shall be typedef'ed to a + * 32-bit wide signed integral data type if there is no 64-bit type. + * + * As a general rule, curl_off_t shall not be mapped to off_t. This + * rule shall only be violated if off_t is the only 64-bit data type + * available and the size of off_t is independent of large file support + * settings. Keep your build on the safe side avoiding an off_t gating. + * If you have a 64-bit off_t then take for sure that another 64-bit + * data type exists, dig deeper and you will find it. + * + * NOTE 3: + * ------- + * + * Right now you might be staring at file include/curl/curlbuild.h.dist or + * at file include/curl/curlbuild.h, this is due to the following reason: + * file include/curl/curlbuild.h.dist is renamed to include/curl/curlbuild.h + * when the libcurl source code distribution archive file is created. + * + * File include/curl/curlbuild.h.dist is not included in the distribution + * archive. File include/curl/curlbuild.h is not present in the git tree. + * + * The distributed include/curl/curlbuild.h file is only intended to be used + * on systems which can not run the also distributed configure script. + * + * On systems capable of running the configure script, the configure process + * will overwrite the distributed include/curl/curlbuild.h file with one that + * is suitable and specific to the library being configured and built, which + * is generated from the include/curl/curlbuild.h.in template file. + * + * If you check out from git on a non-configure platform, you must run the + * appropriate buildconf* script to set up curlbuild.h and other local files. + * + */ + +/* ================================================================ */ +/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */ +/* ================================================================ */ + +#ifdef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined +#endif + +#ifdef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined +#endif + +/* ================================================================ */ +/* EXTERNAL INTERFACE SETTINGS FOR NON-CONFIGURE SYSTEMS ONLY */ +/* ================================================================ */ + +#if defined(__DJGPP__) || defined(__GO32__) +# if defined(__DJGPP__) && (__DJGPP__ > 1) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SALFORDC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__BORLANDC__) +# if (__BORLANDC__ < 0x520) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__TURBOC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__WATCOMC__) +# if defined(__386__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__POCC__) +# if (__POCC__ < 280) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# elif defined(_MSC_VER) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__LCC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SYMBIAN32__) +# if defined(__EABI__) /* Treat all ARM compilers equally */ +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__CW32__) +# pragma longlong on +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__VC32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MWERKS__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(_WIN32_WCE) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MINGW32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__VMS) +# if defined(__VAX) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__OS400__) +# if defined(__ILEC400__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__MVS__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__370__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(TPF) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP MSVC THE PENULTIMATE ENTRY */ +/* ===================================== */ + +#elif defined(_MSC_VER) +# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP GENERIC GCC THE LAST ENTRY */ +/* ===================================== */ + +#elif defined(__GNUC__) +# if !defined(__LP64__) && (defined(__ILP32__) || \ + defined(__i386__) || defined(__ppc__) || defined(__arm__) || \ + defined(__sparc__) || defined(__mips__) || defined(__sh__)) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__LP64__) || \ + defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +#else +# error "Unknown non-configure build target!" + Error Compilation_aborted_Unknown_non_configure_build_target +#endif + +/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */ +/* sys/types.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_TYPES_H +# include +#endif + +/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ +/* sys/socket.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_SOCKET_H +# include +#endif + +/* Data type definition of curl_socklen_t. */ + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T + typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; +#endif + +/* Data type definition of curl_off_t. */ + +#ifdef CURL_TYPEOF_CURL_OFF_T + typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; +#endif + +#endif /* __CURL_CURLBUILD_H */ diff --git a/includes/curl/curlbuild.h.cmake b/includes/curl/curlbuild.h.cmake new file mode 100644 index 000000000..bbb31a940 --- /dev/null +++ b/includes/curl/curlbuild.h.cmake @@ -0,0 +1,197 @@ +#ifndef __CURL_CURLBUILD_H +#define __CURL_CURLBUILD_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * If you think that something actually needs to be changed, adjusted + * or fixed in this file, then, report it on the libcurl development + * mailing list: https://cool.haxx.se/mailman/listinfo/curl-library/ + * + * This header file shall only export symbols which are 'curl' or 'CURL' + * prefixed, otherwise public name space would be polluted. + * + * NOTE 2: + * ------- + * + * Right now you might be staring at file include/curl/curlbuild.h.in or + * at file include/curl/curlbuild.h, this is due to the following reason: + * + * On systems capable of running the configure script, the configure process + * will overwrite the distributed include/curl/curlbuild.h file with one that + * is suitable and specific to the library being configured and built, which + * is generated from the include/curl/curlbuild.h.in template file. + * + */ + +/* ================================================================ */ +/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */ +/* ================================================================ */ + +#ifdef CURL_SIZEOF_LONG +#error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T +#error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_SOCKLEN_T +#error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_OFF_T +#error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_T +#error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_TU +#error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined +#endif + +#ifdef CURL_FORMAT_OFF_T +#error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_OFF_T +#error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_T +#error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_TU +#error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined +#endif + +/* ================================================================ */ +/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */ +/* ================================================================ */ + +/* Configure process defines this to 1 when it finds out that system */ +/* header file ws2tcpip.h must be included by the external interface. */ +#cmakedefine CURL_PULL_WS2TCPIP_H +#ifdef CURL_PULL_WS2TCPIP_H +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +# include +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/types.h must be included by the external interface. */ +#cmakedefine CURL_PULL_SYS_TYPES_H +#ifdef CURL_PULL_SYS_TYPES_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file stdint.h must be included by the external interface. */ +#cmakedefine CURL_PULL_STDINT_H +#ifdef CURL_PULL_STDINT_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file inttypes.h must be included by the external interface. */ +#cmakedefine CURL_PULL_INTTYPES_H +#ifdef CURL_PULL_INTTYPES_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/socket.h must be included by the external interface. */ +#cmakedefine CURL_PULL_SYS_SOCKET_H +#ifdef CURL_PULL_SYS_SOCKET_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/poll.h must be included by the external interface. */ +#cmakedefine CURL_PULL_SYS_POLL_H +#ifdef CURL_PULL_SYS_POLL_H +# include +#endif + +/* The size of `long', as computed by sizeof. */ +#define CURL_SIZEOF_LONG ${CURL_SIZEOF_LONG} + +/* Integral data type used for curl_socklen_t. */ +#define CURL_TYPEOF_CURL_SOCKLEN_T ${CURL_TYPEOF_CURL_SOCKLEN_T} + +/* The size of `curl_socklen_t', as computed by sizeof. */ +#define CURL_SIZEOF_CURL_SOCKLEN_T ${CURL_SIZEOF_CURL_SOCKLEN_T} + +/* Data type definition of curl_socklen_t. */ +typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; + +/* Signed integral data type used for curl_off_t. */ +#define CURL_TYPEOF_CURL_OFF_T ${CURL_TYPEOF_CURL_OFF_T} + +/* Data type definition of curl_off_t. */ +typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; + +/* curl_off_t formatting string directive without "%" conversion specifier. */ +#define CURL_FORMAT_CURL_OFF_T "${CURL_FORMAT_CURL_OFF_T}" + +/* unsigned curl_off_t formatting string without "%" conversion specifier. */ +#define CURL_FORMAT_CURL_OFF_TU "${CURL_FORMAT_CURL_OFF_TU}" + +/* curl_off_t formatting string directive with "%" conversion specifier. */ +#define CURL_FORMAT_OFF_T "${CURL_FORMAT_OFF_T}" + +/* The size of `curl_off_t', as computed by sizeof. */ +#define CURL_SIZEOF_CURL_OFF_T ${CURL_SIZEOF_CURL_OFF_T} + +/* curl_off_t constant suffix. */ +#define CURL_SUFFIX_CURL_OFF_T ${CURL_SUFFIX_CURL_OFF_T} + +/* unsigned curl_off_t constant suffix. */ +#define CURL_SUFFIX_CURL_OFF_TU ${CURL_SUFFIX_CURL_OFF_TU} + +#endif /* __CURL_CURLBUILD_H */ diff --git a/includes/curl/curlbuild.h.dist b/includes/curl/curlbuild.h.dist new file mode 100644 index 000000000..ae95095fa --- /dev/null +++ b/includes/curl/curlbuild.h.dist @@ -0,0 +1,586 @@ +#ifndef __CURL_CURLBUILD_H +#define __CURL_CURLBUILD_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * See file include/curl/curlbuild.h.in, run configure, and forget + * that this file exists it is only used for non-configure systems. + * But you can keep reading if you want ;-) + * + */ + +/* ================================================================ */ +/* NOTES FOR NON-CONFIGURE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * If you think that something actually needs to be changed, adjusted + * or fixed in this file, then, report it on the libcurl development + * mailing list: https://cool.haxx.se/mailman/listinfo/curl-library/ + * + * Try to keep one section per platform, compiler and architecture, + * otherwise, if an existing section is reused for a different one and + * later on the original is adjusted, probably the piggybacking one can + * be adversely changed. + * + * In order to differentiate between platforms/compilers/architectures + * use only compiler built in predefined preprocessor symbols. + * + * This header file shall only export symbols which are 'curl' or 'CURL' + * prefixed, otherwise public name space would be polluted. + * + * NOTE 2: + * ------- + * + * For any given platform/compiler curl_off_t must be typedef'ed to a + * 64-bit wide signed integral data type. The width of this data type + * must remain constant and independent of any possible large file + * support settings. + * + * As an exception to the above, curl_off_t shall be typedef'ed to a + * 32-bit wide signed integral data type if there is no 64-bit type. + * + * As a general rule, curl_off_t shall not be mapped to off_t. This + * rule shall only be violated if off_t is the only 64-bit data type + * available and the size of off_t is independent of large file support + * settings. Keep your build on the safe side avoiding an off_t gating. + * If you have a 64-bit off_t then take for sure that another 64-bit + * data type exists, dig deeper and you will find it. + * + * NOTE 3: + * ------- + * + * Right now you might be staring at file include/curl/curlbuild.h.dist or + * at file include/curl/curlbuild.h, this is due to the following reason: + * file include/curl/curlbuild.h.dist is renamed to include/curl/curlbuild.h + * when the libcurl source code distribution archive file is created. + * + * File include/curl/curlbuild.h.dist is not included in the distribution + * archive. File include/curl/curlbuild.h is not present in the git tree. + * + * The distributed include/curl/curlbuild.h file is only intended to be used + * on systems which can not run the also distributed configure script. + * + * On systems capable of running the configure script, the configure process + * will overwrite the distributed include/curl/curlbuild.h file with one that + * is suitable and specific to the library being configured and built, which + * is generated from the include/curl/curlbuild.h.in template file. + * + * If you check out from git on a non-configure platform, you must run the + * appropriate buildconf* script to set up curlbuild.h and other local files. + * + */ + +/* ================================================================ */ +/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */ +/* ================================================================ */ + +#ifdef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined +#endif + +#ifdef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined +#endif + +/* ================================================================ */ +/* EXTERNAL INTERFACE SETTINGS FOR NON-CONFIGURE SYSTEMS ONLY */ +/* ================================================================ */ + +#if defined(__DJGPP__) || defined(__GO32__) +# if defined(__DJGPP__) && (__DJGPP__ > 1) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SALFORDC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__BORLANDC__) +# if (__BORLANDC__ < 0x520) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__TURBOC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__WATCOMC__) +# if defined(__386__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__POCC__) +# if (__POCC__ < 280) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# elif defined(_MSC_VER) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__LCC__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__SYMBIAN32__) +# if defined(__EABI__) /* Treat all ARM compilers equally */ +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__CW32__) +# pragma longlong on +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__VC32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MWERKS__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(_WIN32_WCE) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__MINGW32__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__VMS) +# if defined(__VAX) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +#elif defined(__OS400__) +# if defined(__ILEC400__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__MVS__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(__370__) +# if defined(__IBMC__) || defined(__IBMCPP__) +# if defined(_ILP32) +# define CURL_SIZEOF_LONG 4 +# elif defined(_LP64) +# define CURL_SIZEOF_LONG 8 +# endif +# if defined(_LONG_LONG) +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(_LP64) +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# else +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 +# endif + +#elif defined(TPF) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP MSVC THE PENULTIMATE ENTRY */ +/* ===================================== */ + +#elif defined(_MSC_VER) +# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_FORMAT_OFF_T "%I64d" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# else +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 4 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* ===================================== */ +/* KEEP GENERIC GCC THE LAST ENTRY */ +/* ===================================== */ + +#elif defined(__GNUC__) +# if !defined(__LP64__) && (defined(__ILP32__) || \ + defined(__i386__) || defined(__ppc__) || defined(__arm__) || \ + defined(__sparc__) || defined(__mips__) || defined(__sh__)) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# elif defined(__LP64__) || \ + defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) +# define CURL_SIZEOF_LONG 8 +# define CURL_TYPEOF_CURL_OFF_T long +# define CURL_FORMAT_CURL_OFF_T "ld" +# define CURL_FORMAT_CURL_OFF_TU "lu" +# define CURL_FORMAT_OFF_T "%ld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T L +# define CURL_SUFFIX_CURL_OFF_TU UL +# endif +# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 +# define CURL_PULL_SYS_SOCKET_H 1 + +#else +# error "Unknown non-configure build target!" + Error Compilation_aborted_Unknown_non_configure_build_target +#endif + +/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */ +/* sys/types.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_TYPES_H +# include +#endif + +/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ +/* sys/socket.h is required here to properly make type definitions below. */ +#ifdef CURL_PULL_SYS_SOCKET_H +# include +#endif + +/* Data type definition of curl_socklen_t. */ + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T + typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; +#endif + +/* Data type definition of curl_off_t. */ + +#ifdef CURL_TYPEOF_CURL_OFF_T + typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; +#endif + +#endif /* __CURL_CURLBUILD_H */ diff --git a/includes/curl/curlbuild.h.in b/includes/curl/curlbuild.h.in new file mode 100644 index 000000000..ffab35670 --- /dev/null +++ b/includes/curl/curlbuild.h.in @@ -0,0 +1,197 @@ +#ifndef __CURL_CURLBUILD_H +#define __CURL_CURLBUILD_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * If you think that something actually needs to be changed, adjusted + * or fixed in this file, then, report it on the libcurl development + * mailing list: https://cool.haxx.se/mailman/listinfo/curl-library/ + * + * This header file shall only export symbols which are 'curl' or 'CURL' + * prefixed, otherwise public name space would be polluted. + * + * NOTE 2: + * ------- + * + * Right now you might be staring at file include/curl/curlbuild.h.in or + * at file include/curl/curlbuild.h, this is due to the following reason: + * + * On systems capable of running the configure script, the configure process + * will overwrite the distributed include/curl/curlbuild.h file with one that + * is suitable and specific to the library being configured and built, which + * is generated from the include/curl/curlbuild.h.in template file. + * + */ + +/* ================================================================ */ +/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */ +/* ================================================================ */ + +#ifdef CURL_SIZEOF_LONG +#error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T +#error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_SOCKLEN_T +#error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_OFF_T +#error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_T +#error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_TU +#error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined +#endif + +#ifdef CURL_FORMAT_OFF_T +#error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_OFF_T +#error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_T +#error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_TU +#error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined +#endif + +/* ================================================================ */ +/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */ +/* ================================================================ */ + +/* Configure process defines this to 1 when it finds out that system */ +/* header file ws2tcpip.h must be included by the external interface. */ +#undef CURL_PULL_WS2TCPIP_H +#ifdef CURL_PULL_WS2TCPIP_H +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +# include +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/types.h must be included by the external interface. */ +#undef CURL_PULL_SYS_TYPES_H +#ifdef CURL_PULL_SYS_TYPES_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file stdint.h must be included by the external interface. */ +#undef CURL_PULL_STDINT_H +#ifdef CURL_PULL_STDINT_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file inttypes.h must be included by the external interface. */ +#undef CURL_PULL_INTTYPES_H +#ifdef CURL_PULL_INTTYPES_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/socket.h must be included by the external interface. */ +#undef CURL_PULL_SYS_SOCKET_H +#ifdef CURL_PULL_SYS_SOCKET_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/poll.h must be included by the external interface. */ +#undef CURL_PULL_SYS_POLL_H +#ifdef CURL_PULL_SYS_POLL_H +# include +#endif + +/* The size of `long', as computed by sizeof. */ +#undef CURL_SIZEOF_LONG + +/* Integral data type used for curl_socklen_t. */ +#undef CURL_TYPEOF_CURL_SOCKLEN_T + +/* The size of `curl_socklen_t', as computed by sizeof. */ +#undef CURL_SIZEOF_CURL_SOCKLEN_T + +/* Data type definition of curl_socklen_t. */ +typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; + +/* Signed integral data type used for curl_off_t. */ +#undef CURL_TYPEOF_CURL_OFF_T + +/* Data type definition of curl_off_t. */ +typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; + +/* curl_off_t formatting string directive without "%" conversion specifier. */ +#undef CURL_FORMAT_CURL_OFF_T + +/* unsigned curl_off_t formatting string without "%" conversion specifier. */ +#undef CURL_FORMAT_CURL_OFF_TU + +/* curl_off_t formatting string directive with "%" conversion specifier. */ +#undef CURL_FORMAT_OFF_T + +/* The size of `curl_off_t', as computed by sizeof. */ +#undef CURL_SIZEOF_CURL_OFF_T + +/* curl_off_t constant suffix. */ +#undef CURL_SUFFIX_CURL_OFF_T + +/* unsigned curl_off_t constant suffix. */ +#undef CURL_SUFFIX_CURL_OFF_TU + +#endif /* __CURL_CURLBUILD_H */ diff --git a/includes/curl/curlrules.h b/includes/curl/curlrules.h new file mode 100644 index 000000000..55d21f68f --- /dev/null +++ b/includes/curl/curlrules.h @@ -0,0 +1,262 @@ +#ifndef __CURL_CURLRULES_H +#define __CURL_CURLRULES_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* COMPILE TIME SANITY CHECKS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * All checks done in this file are intentionally placed in a public + * header file which is pulled by curl/curl.h when an application is + * being built using an already built libcurl library. Additionally + * this file is also included and used when building the library. + * + * If compilation fails on this file it is certainly sure that the + * problem is elsewhere. It could be a problem in the curlbuild.h + * header file, or simply that you are using different compilation + * settings than those used to build the library. + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * Do not deactivate any check, these are done to make sure that the + * library is properly built and used. + * + * You can find further help on the libcurl development mailing list: + * https://cool.haxx.se/mailman/listinfo/curl-library/ + * + * NOTE 2 + * ------ + * + * Some of the following compile time checks are based on the fact + * that the dimension of a constant array can not be a negative one. + * In this way if the compile time verification fails, the compilation + * will fail issuing an error. The error description wording is compiler + * dependent but it will be quite similar to one of the following: + * + * "negative subscript or subscript is too large" + * "array must have at least one element" + * "-1 is an illegal array size" + * "size of array is negative" + * + * If you are building an application which tries to use an already + * built libcurl library and you are getting this kind of errors on + * this file, it is a clear indication that there is a mismatch between + * how the library was built and how you are trying to use it for your + * application. Your already compiled or binary library provider is the + * only one who can give you the details you need to properly use it. + */ + +/* + * Verify that some macros are actually defined. + */ + +#ifndef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_LONG_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_is_missing +#endif + +#ifndef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T definition is missing!" + Error Compilation_aborted_CURL_FORMAT_OFF_T_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing +#endif + +/* + * Macros private to this header file. + */ + +#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1 + +#define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1 + +/* + * Verify that the size previously defined and expected for long + * is the same as the one reported by sizeof() at compile time. + */ + +typedef char + __curl_rule_01__ + [CurlchkszEQ(long, CURL_SIZEOF_LONG)]; + +/* + * Verify that the size previously defined and expected for + * curl_off_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_02__ + [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)]; + +/* + * Verify at compile time that the size of curl_off_t as reported + * by sizeof() is greater or equal than the one reported for long + * for the current compilation. + */ + +typedef char + __curl_rule_03__ + [CurlchkszGE(curl_off_t, long)]; + +/* + * Verify that the size previously defined and expected for + * curl_socklen_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_04__ + [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)]; + +/* + * Verify at compile time that the size of curl_socklen_t as reported + * by sizeof() is greater or equal than the one reported for int for + * the current compilation. + */ + +typedef char + __curl_rule_05__ + [CurlchkszGE(curl_socklen_t, int)]; + +/* ================================================================ */ +/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */ +/* ================================================================ */ + +/* + * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow + * these to be visible and exported by the external libcurl interface API, + * while also making them visible to the library internals, simply including + * curl_setup.h, without actually needing to include curl.h internally. + * If some day this section would grow big enough, all this should be moved + * to its own header file. + */ + +/* + * Figure out if we can use the ## preprocessor operator, which is supported + * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ + * or __cplusplus so we need to carefully check for them too. + */ + +#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ + defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ + defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ + defined(__ILEC400__) + /* This compiler is believed to have an ISO compatible preprocessor */ +#define CURL_ISOCPP +#else + /* This compiler is believed NOT to have an ISO compatible preprocessor */ +#undef CURL_ISOCPP +#endif + +/* + * Macros for minimum-width signed and unsigned curl_off_t integer constants. + */ + +#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) +# define __CURL_OFF_T_C_HLPR2(x) x +# define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) +#else +# ifdef CURL_ISOCPP +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix +# else +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix +# endif +# define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) +#endif + +/* + * Get rid of macros private to this header file. + */ + +#undef CurlchkszEQ +#undef CurlchkszGE + +/* + * Get rid of macros not intended to exist beyond this point. + */ + +#undef CURL_PULL_WS2TCPIP_H +#undef CURL_PULL_SYS_TYPES_H +#undef CURL_PULL_SYS_SOCKET_H +#undef CURL_PULL_SYS_POLL_H +#undef CURL_PULL_STDINT_H +#undef CURL_PULL_INTTYPES_H + +#undef CURL_TYPEOF_CURL_SOCKLEN_T +#undef CURL_TYPEOF_CURL_OFF_T + +#ifdef CURL_NO_OLDIES +#undef CURL_FORMAT_OFF_T /* not required since 7.19.0 - obsoleted in 7.20.0 */ +#endif + +#endif /* __CURL_CURLRULES_H */ diff --git a/includes/curl/curlver.h b/includes/curl/curlver.h new file mode 100644 index 000000000..7beda3fa7 --- /dev/null +++ b/includes/curl/curlver.h @@ -0,0 +1,77 @@ +#ifndef __CURL_CURLVER_H +#define __CURL_CURLVER_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* This header file contains nothing but libcurl version info, generated by + a script at release-time. This was made its own header file in 7.11.2 */ + +/* This is the global package copyright */ +#define LIBCURL_COPYRIGHT "1996 - 2017 Daniel Stenberg, ." + +/* This is the version number of the libcurl package from which this header + file origins: */ +#define LIBCURL_VERSION "7.54.0-DEV" + +/* The numeric version number is also available "in parts" by using these + defines: */ +#define LIBCURL_VERSION_MAJOR 7 +#define LIBCURL_VERSION_MINOR 54 +#define LIBCURL_VERSION_PATCH 0 + +/* This is the numeric version of the libcurl version number, meant for easier + parsing and comparions by programs. The LIBCURL_VERSION_NUM define will + always follow this syntax: + + 0xXXYYZZ + + Where XX, YY and ZZ are the main version, release and patch numbers in + hexadecimal (using 8 bits each). All three numbers are always represented + using two digits. 1.2 would appear as "0x010200" while version 9.11.7 + appears as "0x090b07". + + This 6-digit (24 bits) hexadecimal number does not show pre-release number, + and it is always a greater number in a more recent release. It makes + comparisons with greater than and less than work. + + Note: This define is the full hex number and _does not_ use the + CURL_VERSION_BITS() macro since curl's own configure script greps for it + and needs it to contain the full number. +*/ +#define LIBCURL_VERSION_NUM 0x073600 + +/* + * This is the date and time when the full source package was created. The + * timestamp is not stored in git, as the timestamp is properly set in the + * tarballs by the maketgz script. + * + * The format of the date should follow this template: + * + * "Mon Feb 12 11:35:33 UTC 2007" + */ +#define LIBCURL_TIMESTAMP "DEV" + +#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z) +#define CURL_AT_LEAST_VERSION(x,y,z) \ + (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) + +#endif /* __CURL_CURLVER_H */ diff --git a/includes/curl/easy.h b/includes/curl/easy.h new file mode 100644 index 000000000..752c5049f --- /dev/null +++ b/includes/curl/easy.h @@ -0,0 +1,102 @@ +#ifndef __CURL_EASY_H +#define __CURL_EASY_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN CURL *curl_easy_init(void); +CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); +CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); +CURL_EXTERN void curl_easy_cleanup(CURL *curl); + +/* + * NAME curl_easy_getinfo() + * + * DESCRIPTION + * + * Request internal information from the curl session with this function. The + * third argument MUST be a pointer to a long, a pointer to a char * or a + * pointer to a double (as the documentation describes elsewhere). The data + * pointed to will be filled in accordingly and can be relied upon only if the + * function returns CURLE_OK. This function is intended to get used *AFTER* a + * performed transfer, all results from this function are undefined until the + * transfer is completed. + */ +CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); + + +/* + * NAME curl_easy_duphandle() + * + * DESCRIPTION + * + * Creates a new curl session handle with the same options set for the handle + * passed in. Duplicating a handle could only be a matter of cloning data and + * options, internal state info and things like persistent connections cannot + * be transferred. It is useful in multithreaded applications when you can run + * curl_easy_duphandle() for each new thread to avoid a series of identical + * curl_easy_setopt() invokes in every thread. + */ +CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl); + +/* + * NAME curl_easy_reset() + * + * DESCRIPTION + * + * Re-initializes a CURL handle to the default values. This puts back the + * handle to the same state as it was in when it was just created. + * + * It does keep: live connections, the Session ID cache, the DNS cache and the + * cookies. + */ +CURL_EXTERN void curl_easy_reset(CURL *curl); + +/* + * NAME curl_easy_recv() + * + * DESCRIPTION + * + * Receives data from the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, + size_t *n); + +/* + * NAME curl_easy_send() + * + * DESCRIPTION + * + * Sends data over the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, + size_t buflen, size_t *n); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/includes/curl/mprintf.h b/includes/curl/mprintf.h new file mode 100644 index 000000000..e20f546e1 --- /dev/null +++ b/includes/curl/mprintf.h @@ -0,0 +1,50 @@ +#ifndef __CURL_MPRINTF_H +#define __CURL_MPRINTF_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include +#include /* needed for FILE */ +#include "curl.h" /* for CURL_EXTERN */ + +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN int curl_mprintf(const char *format, ...); +CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); +CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); +CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, + const char *format, ...); +CURL_EXTERN int curl_mvprintf(const char *format, va_list args); +CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); +CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); +CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, + const char *format, va_list args); +CURL_EXTERN char *curl_maprintf(const char *format, ...); +CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); + +#ifdef __cplusplus +} +#endif + +#endif /* __CURL_MPRINTF_H */ diff --git a/includes/curl/multi.h b/includes/curl/multi.h new file mode 100644 index 000000000..d1e00cc5d --- /dev/null +++ b/includes/curl/multi.h @@ -0,0 +1,439 @@ +#ifndef __CURL_MULTI_H +#define __CURL_MULTI_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* + This is an "external" header file. Don't give away any internals here! + + GOALS + + o Enable a "pull" interface. The application that uses libcurl decides where + and when to ask libcurl to get/send data. + + o Enable multiple simultaneous transfers in the same thread without making it + complicated for the application. + + o Enable the application to select() on its own file descriptors and curl's + file descriptors simultaneous easily. + +*/ + +/* + * This header file should not really need to include "curl.h" since curl.h + * itself includes this file and we expect user applications to do #include + * without the need for especially including multi.h. + * + * For some reason we added this include here at one point, and rather than to + * break existing (wrongly written) libcurl applications, we leave it as-is + * but with this warning attached. + */ +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) +typedef struct Curl_multi CURLM; +#else +typedef void CURLM; +#endif + +typedef enum { + CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or + curl_multi_socket*() soon */ + CURLM_OK, + CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ + CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ + CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ + CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ + CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ + CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ + CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was + attempted to get added - again */ + CURLM_LAST +} CURLMcode; + +/* just to make code nicer when using curl_multi_socket() you can now check + for CURLM_CALL_MULTI_SOCKET too in the same style it works for + curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ +#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM + +/* bitmask bits for CURLMOPT_PIPELINING */ +#define CURLPIPE_NOTHING 0L +#define CURLPIPE_HTTP1 1L +#define CURLPIPE_MULTIPLEX 2L + +typedef enum { + CURLMSG_NONE, /* first, not used */ + CURLMSG_DONE, /* This easy handle has completed. 'result' contains + the CURLcode of the transfer */ + CURLMSG_LAST /* last, not used */ +} CURLMSG; + +struct CURLMsg { + CURLMSG msg; /* what this message means */ + CURL *easy_handle; /* the handle it concerns */ + union { + void *whatever; /* message-specific data */ + CURLcode result; /* return code for transfer */ + } data; +}; +typedef struct CURLMsg CURLMsg; + +/* Based on poll(2) structure and values. + * We don't use pollfd and POLL* constants explicitly + * to cover platforms without poll(). */ +#define CURL_WAIT_POLLIN 0x0001 +#define CURL_WAIT_POLLPRI 0x0002 +#define CURL_WAIT_POLLOUT 0x0004 + +struct curl_waitfd { + curl_socket_t fd; + short events; + short revents; /* not supported yet */ +}; + +/* + * Name: curl_multi_init() + * + * Desc: inititalize multi-style curl usage + * + * Returns: a new CURLM handle to use in all 'curl_multi' functions. + */ +CURL_EXTERN CURLM *curl_multi_init(void); + +/* + * Name: curl_multi_add_handle() + * + * Desc: add a standard curl handle to the multi stack + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_remove_handle() + * + * Desc: removes a curl handle from the multi stack again + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_fdset() + * + * Desc: Ask curl for its fd_set sets. The app can use these to select() or + * poll() on. We want curl_multi_perform() called as soon as one of + * them are ready. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, + fd_set *read_fd_set, + fd_set *write_fd_set, + fd_set *exc_fd_set, + int *max_fd); + +/* + * Name: curl_multi_wait() + * + * Desc: Poll on all fds within a CURLM set as well as any + * additional fds passed to the function. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, + struct curl_waitfd extra_fds[], + unsigned int extra_nfds, + int timeout_ms, + int *ret); + + /* + * Name: curl_multi_perform() + * + * Desc: When the app thinks there's data available for curl it calls this + * function to read/write whatever there is right now. This returns + * as soon as the reads and writes are done. This function does not + * require that there actually is data available for reading or that + * data can be written, it can be called just in case. It returns + * the number of handles that still transfer data in the second + * argument's integer-pointer. + * + * Returns: CURLMcode type, general multi error code. *NOTE* that this only + * returns errors etc regarding the whole multi stack. There might + * still have occurred problems on invidual transfers even when this + * returns OK. + */ +CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, + int *running_handles); + + /* + * Name: curl_multi_cleanup() + * + * Desc: Cleans up and removes a whole multi stack. It does not free or + * touch any individual easy handles in any way. We need to define + * in what state those handles will be if this function is called + * in the middle of a transfer. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); + +/* + * Name: curl_multi_info_read() + * + * Desc: Ask the multi handle if there's any messages/informationals from + * the individual transfers. Messages include informationals such as + * error code from the transfer or just the fact that a transfer is + * completed. More details on these should be written down as well. + * + * Repeated calls to this function will return a new struct each + * time, until a special "end of msgs" struct is returned as a signal + * that there is no more to get at this point. + * + * The data the returned pointer points to will not survive calling + * curl_multi_cleanup(). + * + * The 'CURLMsg' struct is meant to be very simple and only contain + * very basic informations. If more involved information is wanted, + * we will provide the particular "transfer handle" in that struct + * and that should/could/would be used in subsequent + * curl_easy_getinfo() calls (or similar). The point being that we + * must never expose complex structs to applications, as then we'll + * undoubtably get backwards compatibility problems in the future. + * + * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out + * of structs. It also writes the number of messages left in the + * queue (after this read) in the integer the second argument points + * to. + */ +CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, + int *msgs_in_queue); + +/* + * Name: curl_multi_strerror() + * + * Desc: The curl_multi_strerror function may be used to turn a CURLMcode + * value into the equivalent human readable error string. This is + * useful for printing meaningful error messages. + * + * Returns: A pointer to a zero-terminated error message. + */ +CURL_EXTERN const char *curl_multi_strerror(CURLMcode); + +/* + * Name: curl_multi_socket() and + * curl_multi_socket_all() + * + * Desc: An alternative version of curl_multi_perform() that allows the + * application to pass in one of the file descriptors that have been + * detected to have "action" on them and let libcurl perform. + * See man page for details. + */ +#define CURL_POLL_NONE 0 +#define CURL_POLL_IN 1 +#define CURL_POLL_OUT 2 +#define CURL_POLL_INOUT 3 +#define CURL_POLL_REMOVE 4 + +#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD + +#define CURL_CSELECT_IN 0x01 +#define CURL_CSELECT_OUT 0x02 +#define CURL_CSELECT_ERR 0x04 + +typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ + curl_socket_t s, /* socket */ + int what, /* see above */ + void *userp, /* private callback + pointer */ + void *socketp); /* private socket + pointer */ +/* + * Name: curl_multi_timer_callback + * + * Desc: Called by libcurl whenever the library detects a change in the + * maximum number of milliseconds the app is allowed to wait before + * curl_multi_socket() or curl_multi_perform() must be called + * (to allow libcurl's timed events to take place). + * + * Returns: The callback should return zero. + */ +typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ + long timeout_ms, /* see above */ + void *userp); /* private callback + pointer */ + +CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, + curl_socket_t s, + int ev_bitmask, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, + int *running_handles); + +#ifndef CURL_ALLOW_OLD_MULTI_SOCKET +/* This macro below was added in 7.16.3 to push users who recompile to use + the new curl_multi_socket_action() instead of the old curl_multi_socket() +*/ +#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) +#endif + +/* + * Name: curl_multi_timeout() + * + * Desc: Returns the maximum number of milliseconds the app is allowed to + * wait before curl_multi_socket() or curl_multi_perform() must be + * called (to allow libcurl's timed events to take place). + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, + long *milliseconds); + +#undef CINIT /* re-using the same name as in curl.h */ + +#ifdef CURL_ISOCPP +#define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLMOPT_/**/name = type + number +#endif + +typedef enum { + /* This is the socket callback function pointer */ + CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1), + + /* This is the argument passed to the socket callback */ + CINIT(SOCKETDATA, OBJECTPOINT, 2), + + /* set to 1 to enable pipelining for this multi handle */ + CINIT(PIPELINING, LONG, 3), + + /* This is the timer callback function pointer */ + CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4), + + /* This is the argument passed to the timer callback */ + CINIT(TIMERDATA, OBJECTPOINT, 5), + + /* maximum number of entries in the connection cache */ + CINIT(MAXCONNECTS, LONG, 6), + + /* maximum number of (pipelining) connections to one host */ + CINIT(MAX_HOST_CONNECTIONS, LONG, 7), + + /* maximum number of requests in a pipeline */ + CINIT(MAX_PIPELINE_LENGTH, LONG, 8), + + /* a connection with a content-length longer than this + will not be considered for pipelining */ + CINIT(CONTENT_LENGTH_PENALTY_SIZE, OFF_T, 9), + + /* a connection with a chunk length longer than this + will not be considered for pipelining */ + CINIT(CHUNK_LENGTH_PENALTY_SIZE, OFF_T, 10), + + /* a list of site names(+port) that are blacklisted from + pipelining */ + CINIT(PIPELINING_SITE_BL, OBJECTPOINT, 11), + + /* a list of server types that are blacklisted from + pipelining */ + CINIT(PIPELINING_SERVER_BL, OBJECTPOINT, 12), + + /* maximum number of open connections in total */ + CINIT(MAX_TOTAL_CONNECTIONS, LONG, 13), + + /* This is the server push callback function pointer */ + CINIT(PUSHFUNCTION, FUNCTIONPOINT, 14), + + /* This is the argument passed to the server push callback */ + CINIT(PUSHDATA, OBJECTPOINT, 15), + + CURLMOPT_LASTENTRY /* the last unused */ +} CURLMoption; + + +/* + * Name: curl_multi_setopt() + * + * Desc: Sets options for the multi handle. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, + CURLMoption option, ...); + + +/* + * Name: curl_multi_assign() + * + * Desc: This function sets an association in the multi handle between the + * given socket and a private pointer of the application. This is + * (only) useful for curl_multi_socket uses. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, + curl_socket_t sockfd, void *sockp); + + +/* + * Name: curl_push_callback + * + * Desc: This callback gets called when a new stream is being pushed by the + * server. It approves or denies the new stream. + * + * Returns: CURL_PUSH_OK or CURL_PUSH_DENY. + */ +#define CURL_PUSH_OK 0 +#define CURL_PUSH_DENY 1 + +struct curl_pushheaders; /* forward declaration only */ + +CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h, + size_t num); +CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h, + const char *name); + +typedef int (*curl_push_callback)(CURL *parent, + CURL *easy, + size_t num_headers, + struct curl_pushheaders *headers, + void *userp); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif diff --git a/includes/curl/stdcheaders.h b/includes/curl/stdcheaders.h new file mode 100644 index 000000000..027b6f421 --- /dev/null +++ b/includes/curl/stdcheaders.h @@ -0,0 +1,33 @@ +#ifndef __STDC_HEADERS_H +#define __STDC_HEADERS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include + +size_t fread(void *, size_t, size_t, FILE *); +size_t fwrite(const void *, size_t, size_t, FILE *); + +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); + +#endif /* __STDC_HEADERS_H */ diff --git a/includes/curl/typecheck-gcc.h b/includes/curl/typecheck-gcc.h new file mode 100644 index 000000000..3d683152b --- /dev/null +++ b/includes/curl/typecheck-gcc.h @@ -0,0 +1,624 @@ +#ifndef __CURL_TYPECHECK_GCC_H +#define __CURL_TYPECHECK_GCC_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* wraps curl_easy_setopt() with typechecking */ + +/* To add a new kind of warning, add an + * if(_curl_is_sometype_option(_curl_opt)) + * if(!_curl_is_sometype(value)) + * _curl_easy_setopt_err_sometype(); + * block and define _curl_is_sometype_option, _curl_is_sometype and + * _curl_easy_setopt_err_sometype below + * + * NOTE: We use two nested 'if' statements here instead of the && operator, in + * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x + * when compiling with -Wlogical-op. + * + * To add an option that uses the same type as an existing option, you'll just + * need to extend the appropriate _curl_*_option macro + */ +#define curl_easy_setopt(handle, option, value) \ +__extension__ ({ \ + __typeof__(option) _curl_opt = option; \ + if(__builtin_constant_p(_curl_opt)) { \ + if(_curl_is_long_option(_curl_opt)) \ + if(!_curl_is_long(value)) \ + _curl_easy_setopt_err_long(); \ + if(_curl_is_off_t_option(_curl_opt)) \ + if(!_curl_is_off_t(value)) \ + _curl_easy_setopt_err_curl_off_t(); \ + if(_curl_is_string_option(_curl_opt)) \ + if(!_curl_is_string(value)) \ + _curl_easy_setopt_err_string(); \ + if(_curl_is_write_cb_option(_curl_opt)) \ + if(!_curl_is_write_cb(value)) \ + _curl_easy_setopt_err_write_callback(); \ + if((_curl_opt) == CURLOPT_READFUNCTION) \ + if(!_curl_is_read_cb(value)) \ + _curl_easy_setopt_err_read_cb(); \ + if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \ + if(!_curl_is_ioctl_cb(value)) \ + _curl_easy_setopt_err_ioctl_cb(); \ + if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \ + if(!_curl_is_sockopt_cb(value)) \ + _curl_easy_setopt_err_sockopt_cb(); \ + if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \ + if(!_curl_is_opensocket_cb(value)) \ + _curl_easy_setopt_err_opensocket_cb(); \ + if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \ + if(!_curl_is_progress_cb(value)) \ + _curl_easy_setopt_err_progress_cb(); \ + if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \ + if(!_curl_is_debug_cb(value)) \ + _curl_easy_setopt_err_debug_cb(); \ + if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \ + if(!_curl_is_ssl_ctx_cb(value)) \ + _curl_easy_setopt_err_ssl_ctx_cb(); \ + if(_curl_is_conv_cb_option(_curl_opt)) \ + if(!_curl_is_conv_cb(value)) \ + _curl_easy_setopt_err_conv_cb(); \ + if((_curl_opt) == CURLOPT_SEEKFUNCTION) \ + if(!_curl_is_seek_cb(value)) \ + _curl_easy_setopt_err_seek_cb(); \ + if(_curl_is_cb_data_option(_curl_opt)) \ + if(!_curl_is_cb_data(value)) \ + _curl_easy_setopt_err_cb_data(); \ + if((_curl_opt) == CURLOPT_ERRORBUFFER) \ + if(!_curl_is_error_buffer(value)) \ + _curl_easy_setopt_err_error_buffer(); \ + if((_curl_opt) == CURLOPT_STDERR) \ + if(!_curl_is_FILE(value)) \ + _curl_easy_setopt_err_FILE(); \ + if(_curl_is_postfields_option(_curl_opt)) \ + if(!_curl_is_postfields(value)) \ + _curl_easy_setopt_err_postfields(); \ + if((_curl_opt) == CURLOPT_HTTPPOST) \ + if(!_curl_is_arr((value), struct curl_httppost)) \ + _curl_easy_setopt_err_curl_httpost(); \ + if(_curl_is_slist_option(_curl_opt)) \ + if(!_curl_is_arr((value), struct curl_slist)) \ + _curl_easy_setopt_err_curl_slist(); \ + if((_curl_opt) == CURLOPT_SHARE) \ + if(!_curl_is_ptr((value), CURLSH)) \ + _curl_easy_setopt_err_CURLSH(); \ + } \ + curl_easy_setopt(handle, _curl_opt, value); \ +}) + +/* wraps curl_easy_getinfo() with typechecking */ +/* FIXME: don't allow const pointers */ +#define curl_easy_getinfo(handle, info, arg) \ +__extension__ ({ \ + __typeof__(info) _curl_info = info; \ + if(__builtin_constant_p(_curl_info)) { \ + if(_curl_is_string_info(_curl_info)) \ + if(!_curl_is_arr((arg), char *)) \ + _curl_easy_getinfo_err_string(); \ + if(_curl_is_long_info(_curl_info)) \ + if(!_curl_is_arr((arg), long)) \ + _curl_easy_getinfo_err_long(); \ + if(_curl_is_double_info(_curl_info)) \ + if(!_curl_is_arr((arg), double)) \ + _curl_easy_getinfo_err_double(); \ + if(_curl_is_slist_info(_curl_info)) \ + if(!_curl_is_arr((arg), struct curl_slist *)) \ + _curl_easy_getinfo_err_curl_slist(); \ + } \ + curl_easy_getinfo(handle, _curl_info, arg); \ +}) + +/* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(), + * for now just make sure that the functions are called with three + * arguments + */ +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) + + +/* the actual warnings, triggered by calling the _curl_easy_setopt_err* + * functions */ + +/* To define a new warning, use _CURL_WARNING(identifier, "message") */ +#define _CURL_WARNING(id, message) \ + static void __attribute__((__warning__(message))) \ + __attribute__((__unused__)) __attribute__((__noinline__)) \ + id(void) { __asm__(""); } + +_CURL_WARNING(_curl_easy_setopt_err_long, + "curl_easy_setopt expects a long argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_off_t, + "curl_easy_setopt expects a curl_off_t argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_string, + "curl_easy_setopt expects a " + "string ('char *' or char[]) argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_write_callback, + "curl_easy_setopt expects a curl_write_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_read_cb, + "curl_easy_setopt expects a curl_read_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ioctl_cb, + "curl_easy_setopt expects a curl_ioctl_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_sockopt_cb, + "curl_easy_setopt expects a curl_sockopt_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_opensocket_cb, + "curl_easy_setopt expects a " + "curl_opensocket_callback argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_progress_cb, + "curl_easy_setopt expects a curl_progress_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_debug_cb, + "curl_easy_setopt expects a curl_debug_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb, + "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_conv_cb, + "curl_easy_setopt expects a curl_conv_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_seek_cb, + "curl_easy_setopt expects a curl_seek_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_cb_data, + "curl_easy_setopt expects a " + "private data pointer as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_error_buffer, + "curl_easy_setopt expects a " + "char buffer of CURL_ERROR_SIZE as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_FILE, + "curl_easy_setopt expects a 'FILE *' argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_postfields, + "curl_easy_setopt expects a 'void *' or 'char *' argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_httpost, + "curl_easy_setopt expects a 'struct curl_httppost *' " + "argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_slist, + "curl_easy_setopt expects a 'struct curl_slist *' argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_CURLSH, + "curl_easy_setopt expects a CURLSH* argument for this option") + +_CURL_WARNING(_curl_easy_getinfo_err_string, + "curl_easy_getinfo expects a pointer to 'char *' for this info") +_CURL_WARNING(_curl_easy_getinfo_err_long, + "curl_easy_getinfo expects a pointer to long for this info") +_CURL_WARNING(_curl_easy_getinfo_err_double, + "curl_easy_getinfo expects a pointer to double for this info") +_CURL_WARNING(_curl_easy_getinfo_err_curl_slist, + "curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info") + +/* groups of curl_easy_setops options that take the same type of argument */ + +/* To add a new option to one of the groups, just add + * (option) == CURLOPT_SOMETHING + * to the or-expression. If the option takes a long or curl_off_t, you don't + * have to do anything + */ + +/* evaluates to true if option takes a long argument */ +#define _curl_is_long_option(option) \ + (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT) + +#define _curl_is_off_t_option(option) \ + ((option) > CURLOPTTYPE_OFF_T) + +/* evaluates to true if option takes a char* argument */ +#define _curl_is_string_option(option) \ + ((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \ + (option) == CURLOPT_ACCEPT_ENCODING || \ + (option) == CURLOPT_CAINFO || \ + (option) == CURLOPT_CAPATH || \ + (option) == CURLOPT_COOKIE || \ + (option) == CURLOPT_COOKIEFILE || \ + (option) == CURLOPT_COOKIEJAR || \ + (option) == CURLOPT_COOKIELIST || \ + (option) == CURLOPT_CRLFILE || \ + (option) == CURLOPT_CUSTOMREQUEST || \ + (option) == CURLOPT_DEFAULT_PROTOCOL || \ + (option) == CURLOPT_DNS_INTERFACE || \ + (option) == CURLOPT_DNS_LOCAL_IP4 || \ + (option) == CURLOPT_DNS_LOCAL_IP6 || \ + (option) == CURLOPT_DNS_SERVERS || \ + (option) == CURLOPT_EGDSOCKET || \ + (option) == CURLOPT_FTPPORT || \ + (option) == CURLOPT_FTP_ACCOUNT || \ + (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ + (option) == CURLOPT_INTERFACE || \ + (option) == CURLOPT_ISSUERCERT || \ + (option) == CURLOPT_KEYPASSWD || \ + (option) == CURLOPT_KRBLEVEL || \ + (option) == CURLOPT_LOGIN_OPTIONS || \ + (option) == CURLOPT_MAIL_AUTH || \ + (option) == CURLOPT_MAIL_FROM || \ + (option) == CURLOPT_NETRC_FILE || \ + (option) == CURLOPT_NOPROXY || \ + (option) == CURLOPT_PASSWORD || \ + (option) == CURLOPT_PINNEDPUBLICKEY || \ + (option) == CURLOPT_PROXY || \ + (option) == CURLOPT_PROXYPASSWORD || \ + (option) == CURLOPT_PROXYUSERNAME || \ + (option) == CURLOPT_PROXYUSERPWD || \ + (option) == CURLOPT_PROXY_SERVICE_NAME || \ + (option) == CURLOPT_RANDOM_FILE || \ + (option) == CURLOPT_RANGE || \ + (option) == CURLOPT_REFERER || \ + (option) == CURLOPT_RTSP_SESSION_ID || \ + (option) == CURLOPT_RTSP_STREAM_URI || \ + (option) == CURLOPT_RTSP_TRANSPORT || \ + (option) == CURLOPT_SERVICE_NAME || \ + (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ + (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ + (option) == CURLOPT_SSH_KNOWNHOSTS || \ + (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ + (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ + (option) == CURLOPT_SSLCERT || \ + (option) == CURLOPT_SSLCERTTYPE || \ + (option) == CURLOPT_SSLENGINE || \ + (option) == CURLOPT_SSLKEY || \ + (option) == CURLOPT_SSLKEYTYPE || \ + (option) == CURLOPT_SSL_CIPHER_LIST || \ + (option) == CURLOPT_TLSAUTH_PASSWORD || \ + (option) == CURLOPT_TLSAUTH_TYPE || \ + (option) == CURLOPT_TLSAUTH_USERNAME || \ + (option) == CURLOPT_UNIX_SOCKET_PATH || \ + (option) == CURLOPT_URL || \ + (option) == CURLOPT_USERAGENT || \ + (option) == CURLOPT_USERNAME || \ + (option) == CURLOPT_USERPWD || \ + (option) == CURLOPT_XOAUTH2_BEARER || \ + 0) + +/* evaluates to true if option takes a curl_write_callback argument */ +#define _curl_is_write_cb_option(option) \ + ((option) == CURLOPT_HEADERFUNCTION || \ + (option) == CURLOPT_WRITEFUNCTION) + +/* evaluates to true if option takes a curl_conv_callback argument */ +#define _curl_is_conv_cb_option(option) \ + ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) + +/* evaluates to true if option takes a data argument to pass to a callback */ +#define _curl_is_cb_data_option(option) \ + ((option) == CURLOPT_CHUNK_DATA || \ + (option) == CURLOPT_CLOSESOCKETDATA || \ + (option) == CURLOPT_DEBUGDATA || \ + (option) == CURLOPT_FNMATCH_DATA || \ + (option) == CURLOPT_HEADERDATA || \ + (option) == CURLOPT_INTERLEAVEDATA || \ + (option) == CURLOPT_IOCTLDATA || \ + (option) == CURLOPT_OPENSOCKETDATA || \ + (option) == CURLOPT_PRIVATE || \ + (option) == CURLOPT_PROGRESSDATA || \ + (option) == CURLOPT_READDATA || \ + (option) == CURLOPT_SEEKDATA || \ + (option) == CURLOPT_SOCKOPTDATA || \ + (option) == CURLOPT_SSH_KEYDATA || \ + (option) == CURLOPT_SSL_CTX_DATA || \ + (option) == CURLOPT_WRITEDATA || \ + 0) + +/* evaluates to true if option takes a POST data argument (void* or char*) */ +#define _curl_is_postfields_option(option) \ + ((option) == CURLOPT_POSTFIELDS || \ + (option) == CURLOPT_COPYPOSTFIELDS || \ + 0) + +/* evaluates to true if option takes a struct curl_slist * argument */ +#define _curl_is_slist_option(option) \ + ((option) == CURLOPT_HTTP200ALIASES || \ + (option) == CURLOPT_HTTPHEADER || \ + (option) == CURLOPT_MAIL_RCPT || \ + (option) == CURLOPT_POSTQUOTE || \ + (option) == CURLOPT_PREQUOTE || \ + (option) == CURLOPT_PROXYHEADER || \ + (option) == CURLOPT_QUOTE || \ + (option) == CURLOPT_RESOLVE || \ + (option) == CURLOPT_TELNETOPTIONS || \ + 0) + +/* groups of curl_easy_getinfo infos that take the same type of argument */ + +/* evaluates to true if info expects a pointer to char * argument */ +#define _curl_is_string_info(info) \ + (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG) + +/* evaluates to true if info expects a pointer to long argument */ +#define _curl_is_long_info(info) \ + (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) + +/* evaluates to true if info expects a pointer to double argument */ +#define _curl_is_double_info(info) \ + (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) + +/* true if info expects a pointer to struct curl_slist * argument */ +#define _curl_is_slist_info(info) \ + (CURLINFO_SLIST < (info)) + + +/* typecheck helpers -- check whether given expression has requested type*/ + +/* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros, + * otherwise define a new macro. Search for __builtin_types_compatible_p + * in the GCC manual. + * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is + * the actual expression passed to the curl_easy_setopt macro. This + * means that you can only apply the sizeof and __typeof__ operators, no + * == or whatsoever. + */ + +/* XXX: should evaluate to true iff expr is a pointer */ +#define _curl_is_any_ptr(expr) \ + (sizeof(expr) == sizeof(void *)) + +/* evaluates to true if expr is NULL */ +/* XXX: must not evaluate expr, so this check is not accurate */ +#define _curl_is_NULL(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) + +/* evaluates to true if expr is type*, const type* or NULL */ +#define _curl_is_ptr(expr, type) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), type *) || \ + __builtin_types_compatible_p(__typeof__(expr), const type *)) + +/* evaluates to true if expr is one of type[], type*, NULL or const type* */ +#define _curl_is_arr(expr, type) \ + (_curl_is_ptr((expr), type) || \ + __builtin_types_compatible_p(__typeof__(expr), type [])) + +/* evaluates to true if expr is a string */ +#define _curl_is_string(expr) \ + (_curl_is_arr((expr), char) || \ + _curl_is_arr((expr), signed char) || \ + _curl_is_arr((expr), unsigned char)) + +/* evaluates to true if expr is a long (no matter the signedness) + * XXX: for now, int is also accepted (and therefore short and char, which + * are promoted to int when passed to a variadic function) */ +#define _curl_is_long(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), long) || \ + __builtin_types_compatible_p(__typeof__(expr), signed long) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ + __builtin_types_compatible_p(__typeof__(expr), int) || \ + __builtin_types_compatible_p(__typeof__(expr), signed int) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ + __builtin_types_compatible_p(__typeof__(expr), short) || \ + __builtin_types_compatible_p(__typeof__(expr), signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), char) || \ + __builtin_types_compatible_p(__typeof__(expr), signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned char)) + +/* evaluates to true if expr is of type curl_off_t */ +#define _curl_is_off_t(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) + +/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ +/* XXX: also check size of an char[] array? */ +#define _curl_is_error_buffer(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), char *) || \ + __builtin_types_compatible_p(__typeof__(expr), char[])) + +/* evaluates to true if expr is of type (const) void* or (const) FILE* */ +#if 0 +#define _curl_is_cb_data(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_ptr((expr), FILE)) +#else /* be less strict */ +#define _curl_is_cb_data(expr) \ + _curl_is_any_ptr(expr) +#endif + +/* evaluates to true if expr is of type FILE* */ +#define _curl_is_FILE(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), FILE *)) + +/* evaluates to true if expr can be passed as POST data (void* or char*) */ +#define _curl_is_postfields(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_arr((expr), char)) + +/* FIXME: the whole callback checking is messy... + * The idea is to tolerate char vs. void and const vs. not const + * pointers in arguments at least + */ +/* helper: __builtin_types_compatible_p distinguishes between functions and + * function pointers, hide it */ +#define _curl_callback_compatible(func, type) \ + (__builtin_types_compatible_p(__typeof__(func), type) || \ + __builtin_types_compatible_p(__typeof__(func), type*)) + +/* evaluates to true if expr is of type curl_read_callback or "similar" */ +#define _curl_is_read_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fread)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_read_callback) || \ + _curl_callback_compatible((expr), _curl_read_callback1) || \ + _curl_callback_compatible((expr), _curl_read_callback2) || \ + _curl_callback_compatible((expr), _curl_read_callback3) || \ + _curl_callback_compatible((expr), _curl_read_callback4) || \ + _curl_callback_compatible((expr), _curl_read_callback5) || \ + _curl_callback_compatible((expr), _curl_read_callback6)) +typedef size_t (_curl_read_callback1)(char *, size_t, size_t, void *); +typedef size_t (_curl_read_callback2)(char *, size_t, size_t, const void *); +typedef size_t (_curl_read_callback3)(char *, size_t, size_t, FILE *); +typedef size_t (_curl_read_callback4)(void *, size_t, size_t, void *); +typedef size_t (_curl_read_callback5)(void *, size_t, size_t, const void *); +typedef size_t (_curl_read_callback6)(void *, size_t, size_t, FILE *); + +/* evaluates to true if expr is of type curl_write_callback or "similar" */ +#define _curl_is_write_cb(expr) \ + (_curl_is_read_cb(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fwrite)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_write_callback) || \ + _curl_callback_compatible((expr), _curl_write_callback1) || \ + _curl_callback_compatible((expr), _curl_write_callback2) || \ + _curl_callback_compatible((expr), _curl_write_callback3) || \ + _curl_callback_compatible((expr), _curl_write_callback4) || \ + _curl_callback_compatible((expr), _curl_write_callback5) || \ + _curl_callback_compatible((expr), _curl_write_callback6)) +typedef size_t (_curl_write_callback1)(const char *, size_t, size_t, void *); +typedef size_t (_curl_write_callback2)(const char *, size_t, size_t, + const void *); +typedef size_t (_curl_write_callback3)(const char *, size_t, size_t, FILE *); +typedef size_t (_curl_write_callback4)(const void *, size_t, size_t, void *); +typedef size_t (_curl_write_callback5)(const void *, size_t, size_t, + const void *); +typedef size_t (_curl_write_callback6)(const void *, size_t, size_t, FILE *); + +/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ +#define _curl_is_ioctl_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ioctl_callback) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback1) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback2) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback3) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback4)) +typedef curlioerr (_curl_ioctl_callback1)(CURL *, int, void *); +typedef curlioerr (_curl_ioctl_callback2)(CURL *, int, const void *); +typedef curlioerr (_curl_ioctl_callback3)(CURL *, curliocmd, void *); +typedef curlioerr (_curl_ioctl_callback4)(CURL *, curliocmd, const void *); + +/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ +#define _curl_is_sockopt_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_sockopt_callback) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback1) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback2)) +typedef int (_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); +typedef int (_curl_sockopt_callback2)(const void *, curl_socket_t, + curlsocktype); + +/* evaluates to true if expr is of type curl_opensocket_callback or + "similar" */ +#define _curl_is_opensocket_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_opensocket_callback) ||\ + _curl_callback_compatible((expr), _curl_opensocket_callback1) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback2) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback3) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback4)) +typedef curl_socket_t (_curl_opensocket_callback1) + (void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback2) + (void *, curlsocktype, const struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback3) + (const void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback4) + (const void *, curlsocktype, const struct curl_sockaddr *); + +/* evaluates to true if expr is of type curl_progress_callback or "similar" */ +#define _curl_is_progress_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_progress_callback) || \ + _curl_callback_compatible((expr), _curl_progress_callback1) || \ + _curl_callback_compatible((expr), _curl_progress_callback2)) +typedef int (_curl_progress_callback1)(void *, + double, double, double, double); +typedef int (_curl_progress_callback2)(const void *, + double, double, double, double); + +/* evaluates to true if expr is of type curl_debug_callback or "similar" */ +#define _curl_is_debug_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_debug_callback) || \ + _curl_callback_compatible((expr), _curl_debug_callback1) || \ + _curl_callback_compatible((expr), _curl_debug_callback2) || \ + _curl_callback_compatible((expr), _curl_debug_callback3) || \ + _curl_callback_compatible((expr), _curl_debug_callback4) || \ + _curl_callback_compatible((expr), _curl_debug_callback5) || \ + _curl_callback_compatible((expr), _curl_debug_callback6) || \ + _curl_callback_compatible((expr), _curl_debug_callback7) || \ + _curl_callback_compatible((expr), _curl_debug_callback8)) +typedef int (_curl_debug_callback1) (CURL *, + curl_infotype, char *, size_t, void *); +typedef int (_curl_debug_callback2) (CURL *, + curl_infotype, char *, size_t, const void *); +typedef int (_curl_debug_callback3) (CURL *, + curl_infotype, const char *, size_t, void *); +typedef int (_curl_debug_callback4) (CURL *, + curl_infotype, const char *, size_t, const void *); +typedef int (_curl_debug_callback5) (CURL *, + curl_infotype, unsigned char *, size_t, void *); +typedef int (_curl_debug_callback6) (CURL *, + curl_infotype, unsigned char *, size_t, const void *); +typedef int (_curl_debug_callback7) (CURL *, + curl_infotype, const unsigned char *, size_t, void *); +typedef int (_curl_debug_callback8) (CURL *, + curl_infotype, const unsigned char *, size_t, const void *); + +/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ +/* this is getting even messier... */ +#define _curl_is_ssl_ctx_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ssl_ctx_callback) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback8)) +typedef CURLcode (_curl_ssl_ctx_callback1)(CURL *, void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback2)(CURL *, void *, const void *); +typedef CURLcode (_curl_ssl_ctx_callback3)(CURL *, const void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback4)(CURL *, const void *, const void *); +#ifdef HEADER_SSL_H +/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX + * this will of course break if we're included before OpenSSL headers... + */ +typedef CURLcode (_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *); +typedef CURLcode (_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX, + const void *); +#else +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; +#endif + +/* evaluates to true if expr is of type curl_conv_callback or "similar" */ +#define _curl_is_conv_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_conv_callback) || \ + _curl_callback_compatible((expr), _curl_conv_callback1) || \ + _curl_callback_compatible((expr), _curl_conv_callback2) || \ + _curl_callback_compatible((expr), _curl_conv_callback3) || \ + _curl_callback_compatible((expr), _curl_conv_callback4)) +typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); +typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); +typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); +typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); + +/* evaluates to true if expr is of type curl_seek_callback or "similar" */ +#define _curl_is_seek_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_seek_callback) || \ + _curl_callback_compatible((expr), _curl_seek_callback1) || \ + _curl_callback_compatible((expr), _curl_seek_callback2)) +typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); +typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); + + +#endif /* __CURL_TYPECHECK_GCC_H */ diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 4a6787406..861e71444 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -13,6 +13,12 @@ * * ******************************************************************************/ +#ifdef _IGUANA_APIDEC_H_ +emit compiler error if recursively being included +#endif +#ifndef _IGUANA_APIDEC_H_ +#define _IGUANA_APIDEC_H_ + STRING_ARG(dpow,pending,fiat); ZERO_ARGS(dpow,notarychains); STRING_ARG(dpow,active,maskhex); @@ -49,6 +55,8 @@ HASH_AND_STRING_AND_INT(dex,gettxin,txid,symbol,vout); TWO_STRINGS(dex,listspent,symbol,address); TWO_STRINGS(dex,getbalance,symbol,address); STRING_ARG(dex,explorer,symbol); +STRING_ARG(dex,getmessage,argstr); +STRING_ARG(dex,psock,argstr); HASH_ARRAY_STRING(basilisk,genesis_opreturn,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr); @@ -57,6 +65,7 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr); 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,getmessage,hash,vals,hexstr); @@ -186,6 +195,9 @@ STRING_AND_INT(iguana,bundlehashes,activecoin,height); STRING_AND_INT(iguana,PoSweights,activecoin,height); STRING_ARG(iguana,stakers,activecoin); +STRING_ARG(jumblr,setpassphrase,passphrase); +ZERO_ARGS(jumblr,status); + ZERO_ARGS(InstantDEX,allcoins); STRING_ARG(InstantDEX,available,source); HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr); @@ -211,6 +223,8 @@ STRING_AND_INT(InstantDEX,pollgap,exchange,pollgap); ZERO_ARGS(InstantDEX,allexchanges); STRING_ARG(InstantDEX,allpairs,exchange); THREE_STRINGS(InstantDEX,supports,exchange,base,rel); +ZERO_ARGS(InstantDEX,init); +ZERO_ARGS(InstantDEX,getswaplist); //THREE_STRINGS(atomic,approve,myorderid,otherid,txname); //THREE_STRINGS(atomic,claim,myorderid,otherid,txname); @@ -322,6 +336,8 @@ STRING_ARG(hash,base64_decode,message); STRING_ARG(hash,rmd160_sha256,message); STRING_ARG(hash,sha256_sha256,message); +#ifndef WIN32 + STRING_ARG(hash,sha224,message); STRING_ARG(hash,sha256,message); STRING_ARG(hash,sha384,message); @@ -351,3 +367,7 @@ TWO_STRINGS(hmac,md4,message,passphrase); TWO_STRINGS(hmac,md5,message,passphrase); TWO_STRINGS(hmac,tiger192_3,message,passphrase); TWO_STRINGS(hmac,whirlpool,message,passphrase); + +#endif + +#endif diff --git a/includes/iguana_apideclares2.h b/includes/iguana_apideclares2.h new file mode 100644 index 000000000..952301d89 --- /dev/null +++ b/includes/iguana_apideclares2.h @@ -0,0 +1,31 @@ +#ifdef WIN32 +STRING_ARG(hash, sha224, message); +STRING_ARG(hash, sha256, message); +STRING_ARG(hash, sha384, message); +STRING_ARG(hash, sha512, message); +STRING_ARG(hash, rmd128, message); +STRING_ARG(hash, rmd160, message); +STRING_ARG(hash, rmd256, message); +STRING_ARG(hash, rmd320, message); +STRING_ARG(hash, sha1, message); +STRING_ARG(hash, md2, message); +STRING_ARG(hash, md4, message); +STRING_ARG(hash, md5, message); +STRING_ARG(hash, tiger192_3, message); +STRING_ARG(hash, whirlpool, message); + +TWO_STRINGS(hmac, sha224, message, passphrase); +TWO_STRINGS(hmac, sha256, message, passphrase); +TWO_STRINGS(hmac, sha384, message, passphrase); +TWO_STRINGS(hmac, sha512, message, passphrase); +TWO_STRINGS(hmac, rmd128, message, passphrase); +TWO_STRINGS(hmac, rmd160, message, passphrase); +TWO_STRINGS(hmac, rmd256, message, passphrase); +TWO_STRINGS(hmac, rmd320, message, passphrase); +TWO_STRINGS(hmac, sha1, message, passphrase); +TWO_STRINGS(hmac, md2, message, passphrase); +TWO_STRINGS(hmac, md4, message, passphrase); +TWO_STRINGS(hmac, md5, message, passphrase); +TWO_STRINGS(hmac, tiger192_3, message, passphrase); +TWO_STRINGS(hmac, whirlpool, message, passphrase); +#endif \ No newline at end of file diff --git a/includes/iguana_apiundefs.h b/includes/iguana_apiundefs.h index 0b793ee2d..88156175d 100755 --- a/includes/iguana_apiundefs.h +++ b/includes/iguana_apiundefs.h @@ -49,3 +49,5 @@ #undef IGUANA_ARGS #undef IGUANA_CALLARGS +#undef _IGUANA_APIDEC_H_ + diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 8e048b21f..ac4487c49 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -15,6 +15,10 @@ #ifndef H_IGUANAFUNCS_H #define H_IGUANAFUNCS_H +#define SIGHASH_ALL 1 + +cJSON *SuperNET_helpjson(); + // peers int32_t iguana_verifypeer(struct iguana_info *coin,void *key,void *value,int32_t itemind,int32_t itemsize); int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin); @@ -316,6 +320,10 @@ int32_t bitcoin_changescript(struct iguana_info *coin,uint8_t *changescript,int3 //cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys); int32_t bitcoin_verifytx(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,char *rawtxstr,struct vin_info *V,int32_t numinputs); int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uint8_t *pubkey,int32_t plen); +cJSON *SuperNET_decryptedjson(char *destfname,char *passphrase,int32_t passsize,bits256 wallethash,char *fname2fa,int32_t fnamesize,bits256 wallet2priv); +int32_t bitcoin_txaddspend(struct iguana_info *coin,cJSON *txobj,char *destaddress,uint64_t satoshis); +char *_setVsigner(struct iguana_info *coin,struct vin_info *V,int32_t ind,char *pubstr,char *wifstr); + char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,cJSON *txjson,struct vin_info *V); int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); char *issue_startForging(struct supernet_info *myinfo,char *secret); @@ -518,6 +526,7 @@ int32_t iguana_unspentind2txid(struct supernet_info *myinfo,struct iguana_info * int32_t iguana_RTunspent_check(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_outpoint outpt); 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); int32_t iguana_markedunspents_find(struct iguana_info *coin,int32_t *firstslotp,bits256 txid,int32_t vout); +void jumblr_opidsupdate(struct supernet_info *myinfo,struct iguana_info *coin); char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey,struct vin_info *V); bits256 scrypt_blockhash(const void *input); @@ -596,6 +605,11 @@ void basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notar 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]); void 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); void iguana_RTreset(struct iguana_info *coin); void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight); @@ -614,6 +628,11 @@ uint64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *co int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *refrmd160,struct iguana_pkhash *refP,uint64_t *weights,int32_t numweights,bits256 *sortbuf); bits256 mpz_div64(bits256 hash,uint64_t divval); void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coin); +void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int32_t selector,int32_t modval); +void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coinkmd,char *BTCaddr,char *KMDaddr,bits256 privkey); +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 diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index ea665ef85..813bd77a7 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -531,6 +531,7 @@ struct iguana_info uint32_t utxoaddrlastcount,*utxoaddroffsets,lastunspentsupdate; uint8_t *utxoaddrtable; bits256 utxoaddrhash; FILE *utxofp; bits256 markedunspents[1024]; + uint64_t estimatedfee; char seedipaddr[64]; uint32_t lastbesthashtime; bits256 lastbesthash; int32_t lastbestheight; struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536];