From 1144093e810a7ebb45e2cc6adf1d0dc4cf9d28aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 29 Mar 2017 18:37:57 +0300 Subject: [PATCH 01/16] Remove test_schnorr_threshold --- .gitignore | 2 + basilisk/basilisk.c | 10 +-- basilisk/jumblr.c | 126 ++++++++++++++++++++++++++++++------ iguana/iguana_secp.c | 89 ------------------------- iguana/main.c | 15 ++--- iguana/tests/dexlistunspent | 2 +- includes/iguana_funcs.h | 4 +- includes/iguana_structs.h | 11 ++++ 8 files changed, 135 insertions(+), 124 deletions(-) diff --git a/.gitignore b/.gitignore index 1d70ba0e5..e689f7231 100755 --- a/.gitignore +++ b/.gitignore @@ -216,3 +216,5 @@ iguana/autoAPI.md iguana/confs/5228bcea7ae2515a29c3844673de6ee2acba53bf45724744a00ff4306f192912 iguana/confs/630929d976025fafde221c7358eb5805f4359bad3c6b8bd50ad3f6e0a9b5ce78 + +iguana/confs/5f3283a017c31e52443d61cb43944e2157f7c03eb12d701ebf4a35a695688e1f diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index ba880e2e6..eb2d7237c 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -1301,7 +1301,7 @@ STRING_ARG(jumblr,setpassphrase,passphrase) safecopy(myinfo->jumblr_passphrase,passphrase,sizeof(myinfo->jumblr_passphrase)); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); - privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + privkey = jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,JUMBLR_DEPOSITPREFIX); smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr); myinfo->jumblr_depositkey = curve25519(privkey,curve25519_basepoint9()); bitcoin_priv2wif(wifstr,privkey,coin->chain->wiftype); @@ -1316,7 +1316,7 @@ STRING_ARG(jumblr,setpassphrase,passphrase) jumblr_importprivkey(myinfo,coinbtc,wifstr); jaddnum(retjson,"BTCdeposits",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr))); } - privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,""); + privkey = jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,""); smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr); myinfo->jumblr_pubkey = curve25519(privkey,curve25519_basepoint9()); jaddstr(retjson,"KMDjumblr",KMDaddr); @@ -1335,14 +1335,14 @@ ZERO_ARGS(jumblr,status) jumblr_opidsupdate(myinfo,coin); retjson = cJSON_CreateObject(); step_t2z = step_z2z = step_z2t = deposited = finished = pending = 0; - jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + jumblr_privkey(myinfo,BTCaddr,0,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,""); + jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,""); jaddstr(retjson,"KMDjumblr",KMDaddr); jaddstr(retjson,"BTCjumblr",BTCaddr); if ( coinbtc != 0 ) @@ -1706,7 +1706,7 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) 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 : ""); + privkey = jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,jumblr == 1 ? JUMBLR_DEPOSITPREFIX : ""); else privkey = myinfo->persistent_priv; hash = curve25519(privkey,curve25519_basepoint9()); if ( jobj(vals,"srchash") == 0 ) diff --git a/basilisk/jumblr.c b/basilisk/jumblr.c index 0710007c6..5dea0d784 100755 --- a/basilisk/jumblr.c +++ b/basilisk/jumblr.c @@ -289,8 +289,8 @@ void jumblr_opidupdate(struct supernet_info *myinfo,struct iguana_info *coin,str if ( strcmp(status,"success") == 0 ) { ptr->status = jumblr_itemset(ptr,item,status); - jumblr_privkey(myinfo,BTCaddr,KMDdeposit,JUMBLR_DEPOSITPREFIX); - jumblr_privkey(myinfo,BTCaddr,KMDjumblr,""); + jumblr_privkey(myinfo,BTCaddr,0,KMDdeposit,JUMBLR_DEPOSITPREFIX); + jumblr_privkey(myinfo,BTCaddr,0,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"); @@ -364,37 +364,125 @@ void jumblr_opidsupdate(struct supernet_info *myinfo,struct iguana_info *coin) } } -bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,char *KMDaddr,char *prefix) +bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,uint8_t pubtype,char *KMDaddr,char *prefix) { bits256 privkey,pubkey; uint8_t pubkey33[33]; char passphrase[sizeof(myinfo->jumblr_passphrase) + 64]; sprintf(passphrase,"%s%s",prefix,myinfo->jumblr_passphrase); 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(BTCaddr,pubtype,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) +/*struct DEXcoin_info { - 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 ) + bits256 deposit_privkey,jumblr_privkey; + struct iguana_info *coin; + cJSON *utxos,*spentutxos,*bigutxos,*normalutxos,*smallutxos,*feeutxos,*otherutxos; + double btcprice,USD_average,DEXpending,maxbid,minask,avail,KMDavail; + uint32_t lasttime; + char CMCname[32],symbol[16],depositaddr[64],KMDdepositaddr[64],KMDjumblraddr[64],jumblraddr[64]; +};*/ + +int32_t jumblr_DEXsplit(struct supernet_info *myinfo,bits256 *splittxidp,bits256 txid,int32_t vout,uint64_t value,double bigprice,double middleprice,double smallprice,double feeprice) +{ + +} + +int32_t jumblr_DEXutxoupdate(struct supernet_info *myinfo,bits256 *splittxidp,bits256 txid,int32_t vout,uint64_t value,int32_t isbob) +{ + double targetpriceB,targetpriceM,targetpriceS,fee,depositfactor,dexfeeratio,margin = 1.1; + depositfactor = (isbob == 0) ? 1. : 1.2; + dexfeeratio = 500.; + memset(splittxidp,0,sizeof(*splittxidp)); + fee = JUMBLR_INCR * JUMBLR_FEE; + targetpriceB = depositfactor * ((JUMBLR_INCR + 3*fee)*100 + 3*JUMBLR_TXFEE); + targetpriceM = depositfactor * ((JUMBLR_INCR + 3*fee)*10 + 3*JUMBLR_TXFEE); + targetpriceS = depositfactor * ((JUMBLR_INCR + 3*fee) + 3*JUMBLR_TXFEE); + if ( value >= targetpriceB ) + { + if ( value > margin * (targetpriceB + targetpriceS) ) + jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,margin * targetpriceB,margin * targetpriceM,margin * targetpriceS,margin * targetpriceB/dexfeeratio); + return(0); + } + else + { + if ( value >= targetpriceM ) + { + if ( value > margin * (targetpriceM + targetpriceS) ) + return(jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,0.,margin * targetpriceM,margin * targetpriceS,margin * targetpriceM/dexfeeratio)); + else return(0); + } + else + { + if ( value >= targetpriceS ) + { + if ( value > margin * targetpriceS ) + return(jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,0.,0.,margin * targetpriceS,margin * targetpriceS/dexfeeratio)); + else return(0); + } + else if ( value > targetpriceS/dexfeeratio ) + return(jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,0.,0.,0.,margin * targetpriceS/dexfeeratio)); + else return(0); + } + } +} + +void jumblr_DEXupdate(struct supernet_info *myinfo,struct DEXcoin_info *ptr,char *symbol,char *CMCname,double BTC2KMD,double KMDavail) +{ + double avebid,aveask,highbid,lowask,CMC_average,changes[3]; struct iguana_info *kmdcoin = iguana_coinfind("KMD"); + if ( kmdcoin != 0 && time(NULL) > ptr->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 ( strcmp(symbol,ptr->symbol) != 0 || ptr->coin == 0 ) + { + safecopy(ptr->symbol,symbol,sizeof(ptr->symbol)); + safecopy(ptr->CMCname,CMCname,sizeof(ptr->CMCname)); + if ( ptr->coin == 0 ) + ptr->coin = iguana_coinfind(symbol); + } + if ( ptr->coin != 0 ) + { + if ( ptr->depositaddr[0] == 0 ) + ptr->deposit_privkey = jumblr_privkey(myinfo,ptr->depositaddr,ptr->coin->chain->pubtype,ptr->KMDdepositaddr,JUMBLR_DEPOSITPREFIX); + if ( ptr->jumblraddr[0] == 0 ) + ptr->jumblr_privkey = jumblr_privkey(myinfo,ptr->jumblraddr,ptr->coin->chain->pubtype,ptr->KMDjumblraddr,""); + ptr->avail = dstr(jumblr_balance(myinfo,ptr->coin,ptr->depositaddr)); + } + ptr->btcprice = get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,CMCname,symbol,"BTC",&ptr->USD_average); + if ( strcmp("KMD",symbol) == 0 ) + { + ptr->BTC2KMD = ptr->btcprice; + ptr->kmdprice = 1.; + ptr->KMDavail = ptr->avail; + } + else if ( (ptr->BTC2KMD= BTC2KMD) > SMALLVAL ) + { + ptr->kmdprice = ptr->btcprice / BTC2KMD; + ptr->KMDavail = KMDavail; + } + ptr->lasttime = (uint32_t)time(NULL); } - if ( kmdprice > SMALLVAL ) +} + +void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin) +{ + struct iguana_info *kmdcoin; + if ( (kmdcoin= iguana_coinfind("KMD")) == 0 ) + return; + jumblr_DEXupdate(myinfo,&kmdcoin->DEXinfo,"KMD","komodo",0.,0.); + if ( strcmp(coin->symbol,"KMD") != 0 && kmdcoin->DEXinfo.btcprice > 0. ) + jumblr_DEXupdate(myinfo,&coin->DEXinfo,"KMD","komodo",kmdcoin->DEXinfo.btcprice,kmdcoin->DEXinfo.avail); + /*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 ) + minbtc = (kmdprice * 1.2) * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE)); + btcavail = dstr(jumblr_balance(myinfo,coinbtc,BTCaddr)); + if ( coinbtc != 0 && btcavail > 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); @@ -408,7 +496,7 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coinkmd,ch } // 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); + } else printf("null kmdprice %.8f\n",kmdprice);*/ } void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int32_t selector,int32_t modval) @@ -424,7 +512,7 @@ void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int3 switch ( selector ) { case 0: // public -> z, need to importprivkey - jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,JUMBLR_DEPOSITPREFIX); if ( (total= jumblr_balance(myinfo,coin,KMDaddr)) >= (JUMBLR_INCR + 3*(fee+JUMBLR_TXFEE))*SATOSHIDEN ) { if ( (r & 1) == 0 ) @@ -477,7 +565,7 @@ void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int3 { if ( (r & 1) == 0 && ptr->spent == 0 && (total= jumblr_balance(myinfo,coin,ptr->dest)) >= (fee + JUMBLR_FEE)*SATOSHIDEN ) { - privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,""); + privkey = jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,""); if ( (retstr= jumblr_sendz_to_t(myinfo,coin,ptr->dest,KMDaddr,dstr(total))) != 0 ) { printf("sendz_to_t.(%s)\n",retstr); diff --git a/iguana/iguana_secp.c b/iguana/iguana_secp.c index 614f970e4..c53170908 100755 --- a/iguana/iguana_secp.c +++ b/iguana/iguana_secp.c @@ -451,95 +451,6 @@ int32_t bitcoin_rangeproof(void *ctx,uint8_t *proof,uint8_t *commit,bits256 blin return(retval); } -/* - * The intended procedure for creating a multiparty signature is: - * - Each signer S[i] with private key x[i] and public key Q[i] runs - * secp256k1_schnorr_generate_nonce_pair to produce a pair (k[i],R[i]) of private/public nonces. - * - All signers communicate their public nonces to each other (revealing your - * private nonce can lead to discovery of your private key, so it should be considered secret). - * - All signers combine all the public nonces they received (excluding their - * own) using secp256k1_ec_pubkey_combine to obtain an Rall[i] = sum(R[0..i-1,i+1..n]). - * - All signers produce a partial signature using - * secp256k1_schnorr_partial_sign, passing in their own private key x[i], - * their own private nonce k[i], and the sum of the others' public nonces Rall[i]. - * - All signers communicate their partial signatures to each other. - * - Someone combines all partial signatures using secp256k1_schnorr_partial_combine, to obtain a full signature. - * - The resulting signature is validatable using secp256k1_schnorr_verify, with - * public key equal to the result of secp256k1_ec_pubkey_combine of the signers' public keys (sum(Q[0..n])). - * - * Note that secp256k1_schnorr_partial_combine and secp256k1_ec_pubkey_combine - * function take their arguments in any order, and it is possible to - * pre-combine several inputs already with one call, and add more inputs later - * by calling the function again (they are commutative and associative). - */ - -#ifdef test_schnorr -#include "secp256k1/src/util.h" -#include "secp256k1/src/hash_impl.h" -#include "secp256k1/src/testrand_impl.h" - -void test_schnorr_threshold(void *ctx) { - unsigned char msg[32]; - unsigned char sec[5][32]; - secp256k1_pubkey pub[5]; - unsigned char nonce[5][32]; - secp256k1_pubkey pubnonce[5]; - unsigned char sig[5][64]; - const unsigned char* sigs[5]; - unsigned char allsig[64]; - const secp256k1_pubkey* pubs[5]; - secp256k1_pubkey allpub; - int n, i; - int damage; - int ret = 0; - - damage = secp256k1_rand_bits(1) ? (1 + secp256k1_rand_int(4)) : 0; - secp256k1_rand256_test(msg); - n = 2 + secp256k1_rand_int(4); - for (i = 0; i < n; i++) { - do { - secp256k1_rand256_test(sec[i]); - } while (!secp256k1_ec_seckey_verify(ctx, sec[i])); - CHECK(secp256k1_ec_pubkey_create(ctx, &pub[i], sec[i])); - CHECK(secp256k1_schnorr_generate_nonce_pair(ctx, &pubnonce[i], nonce[i], msg, sec[i], NULL, NULL)); - pubs[i] = &pub[i]; - } - if (damage == 1) { - nonce[secp256k1_rand_int(n)][secp256k1_rand_int(32)] ^= 1 + secp256k1_rand_int(255); - } else if (damage == 2) { - sec[secp256k1_rand_int(n)][secp256k1_rand_int(32)] ^= 1 + secp256k1_rand_int(255); - } - for (i = 0; i < n; i++) { - secp256k1_pubkey allpubnonce; - const secp256k1_pubkey *pubnonces[4]; - int j; - for (j = 0; j < i; j++) { - pubnonces[j] = &pubnonce[j]; - } - for (j = i + 1; j < n; j++) { - pubnonces[j - 1] = &pubnonce[j]; - } - CHECK(secp256k1_ec_pubkey_combine(ctx, &allpubnonce, pubnonces, n - 1)); - ret |= (secp256k1_schnorr_partial_sign(ctx, sig[i], msg, sec[i], &allpubnonce, nonce[i]) != 1) * 1; - sigs[i] = sig[i]; - } - if (damage == 3) { - sig[secp256k1_rand_int(n)][secp256k1_rand_bits(6)] ^= 1 + secp256k1_rand_int(255); - } - ret |= (secp256k1_ec_pubkey_combine(ctx, &allpub, pubs, n) != 1) * 2; - if ((ret & 1) == 0) { - ret |= (secp256k1_schnorr_partial_combine(ctx, allsig, sigs, n) != 1) * 4; - } - if (damage == 4) { - allsig[secp256k1_rand_int(32)] ^= 1 + secp256k1_rand_int(255); - } - if ((ret & 7) == 0) { - ret |= (secp256k1_schnorr_verify(ctx, allsig, msg, &allpub) != 1) * 8; - } - CHECK((ret == 0) == (damage == 0)); -} -#endif - int32_t iguana_pederson_test(void *ctx) { uint8_t commits[100][33],*commitptrs[100],proofs[100][5138]; uint16_t vouts[100]; int64_t min_value,values[100],totalpos,totalneg; bits256 txids[100],nonces[100],blinds[100],*blindptrs[100],blindsum; int32_t prooflens[100],i,r,pos,neg,numpos,exponent,min_bits,n,N = 100; diff --git a/iguana/main.c b/iguana/main.c index 8acec8c89..7b38676f9 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -749,19 +749,18 @@ void iguana_urlinit(struct supernet_info *myinfo,int32_t ismainnet,int32_t usess 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; + struct iguana_info *coin; 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 ) + if ( myinfo->jumblr_passphrase[0] != 0 && (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); + jumblr_DEXcheck(myinfo,coin); t = (uint32_t)time(NULL); - if ( myinfo->jumblr_passphrase[0] != 0 && (t % (120 * mult)) < 60 ) + if ( (t % (120 * mult)) < 60 ) { + // if BTC has arrived in deposit address, invoke DEX -> KMD 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); @@ -1909,10 +1908,10 @@ ZERO_ARGS(SuperNET,activehandle) } else jaddstr(retjson,"status","locked"); if ( myinfo->jumblr_passphrase[0] != 0 ) { - jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,JUMBLR_DEPOSITPREFIX); jaddstr(retjson,"BTCdeposit","notyet"); jaddstr(retjson,"KMDdeposit",KMDaddr); - jumblr_privkey(myinfo,BTCaddr,KMDaddr,""); + jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,""); jaddstr(retjson,"BTCjumblr","notyet"); jaddstr(retjson,"KMDjumblr",KMDaddr); } diff --git a/iguana/tests/dexlistunspent b/iguana/tests/dexlistunspent index 3c4870cc8..98f1490fa 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\":\"listunspent\",\"address\":\"\",\"symbol\":\"BTC\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"REMYL4s4zSiKeLEit5FawHFuGKZ4apm297\",\"symbol\":\"KMD\"}" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index ac4487c49..464fd2eab 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -629,8 +629,8 @@ int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *ref 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); +void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin); +bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,uint8_t pubtype,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); diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 813bd77a7..642748fa9 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -466,6 +466,16 @@ struct iguana_RTtxid struct hashstr_item { UT_hash_handle hh; char address[40]; }; +struct DEXcoin_info +{ + bits256 deposit_privkey,jumblr_privkey; + struct iguana_info *coin; + cJSON *utxos,*spentutxos,*bigutxos,*normalutxos,*smallutxos,*feeutxos,*otherutxos; + double btcprice,BTC2KMD,kmdprice,USD_average,DEXpending,maxbid,minask,avail,KMDavail; + uint32_t lasttime; + char CMCname[32],symbol[16],depositaddr[64],KMDdepositaddr[64],KMDjumblraddr[64],jumblraddr[64]; +}; + struct iguana_info { UT_hash_handle hh; @@ -534,6 +544,7 @@ struct iguana_info uint64_t estimatedfee; char seedipaddr[64]; uint32_t lastbesthashtime; bits256 lastbesthash; int32_t lastbestheight; + struct DEXcoin_info DEXinfo; struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536]; struct iguana_RTtxid *RTdataset; struct iguana_RTaddr *RTaddrs; struct hashstr_item *alladdresses; From a393381bf43f120476cd43e7079b5cadf591ce22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 02:19:02 +0300 Subject: [PATCH 02/16] Test --- basilisk/basilisk.c | 4 +- basilisk/basilisk_bitcoin.c | 10 +- basilisk/jumblr.c | 270 +++++++++++++++++++++++++++++------- crypto777/iguana_utils.c | 2 +- iguana/coins/genbtc | 2 +- iguana/iguana_payments.c | 6 +- iguana/tests/dexgetO | 2 +- includes/iguana_funcs.h | 2 +- includes/iguana_globals.h | 2 +- includes/iguana_structs.h | 8 +- 10 files changed, 245 insertions(+), 63 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index eb2d7237c..ddb1634a4 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -1603,7 +1603,7 @@ TWO_STRINGS(basilisk,refresh,symbol,address) STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore) { - char *destaddr,*changeaddr; uint64_t satoshis,txfee; int32_t completed,sendflag,timelock; + char *destaddr,*changeaddr; int64_t satoshis,txfee; int32_t completed,sendflag,timelock; timelock = jint(vals,"timelock"); sendflag = jint(vals,"sendflag"); satoshis = jdouble(vals,"amount") * SATOSHIDEN; @@ -1612,7 +1612,7 @@ STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore) if ( destaddr != 0 && changeaddr != 0 && symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 ) { txfee = jdouble(vals,"txfee") * SATOSHIDEN; - return(iguana_utxorawtx(myinfo,coin,timelock,destaddr,changeaddr,satoshis,txfee,&completed,sendflag,utxos)); + return(iguana_utxorawtx(myinfo,coin,timelock,destaddr,changeaddr,&satoshis,1,txfee,&completed,sendflag,utxos)); } return(clonestr("{\"error\":\"invalid coin or address specified\"}")); } diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 8dec9ae69..3e29d422f 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -658,9 +658,9 @@ int64_t iguana_verifytimelock(struct supernet_info *myinfo,struct iguana_info *c } return(-2); } -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) +char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t timelock,char *destaddr,char *changeaddr,int64_t *satoshis,int32_t numoutputs,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,iter,spendlen; cJSON *retjson,*txcopy,*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 i,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\"}")); @@ -687,11 +687,13 @@ char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int spendlen = bitcoin_p2shspend(script,0,rmd160); printf("timelock.%d spend timelocked %u\n",timelock,timelocked); } - bitcoin_txoutput(txobj,script,spendlen,satoshis); + for (i=0; i 0 ) + bitcoin_txoutput(txobj,script,spendlen,satoshis[i]); for (iter=0; iter<2; iter++) { txcopy = jduplicate(txobj); - if ( (rawtx= iguana_calcutxorawtx(myinfo,coin,&vins,txobj,satoshis,changeaddr,txfee,utxos,"",0,0)) != 0 ) + if ( (rawtx= iguana_calcutxorawtx(myinfo,coin,&vins,txobj,satoshis,numoutputs,changeaddr,txfee,utxos,"",0,0)) != 0 ) { if ( iter == 1 || txfee != 0 ) jaddstr(retjson,"rawtx",rawtx); diff --git a/basilisk/jumblr.c b/basilisk/jumblr.c index 5dea0d784..3a15322ac 100755 --- a/basilisk/jumblr.c +++ b/basilisk/jumblr.c @@ -375,104 +375,280 @@ bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,uint8_t pubtyp return(privkey); } -/*struct DEXcoin_info +int64_t jumblr_DEXsplit(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *splittxidp,char *coinaddr,bits256 txid,int32_t vout,int64_t remaining,double bigprice,double middleprice,double smallprice,double fees[4]) { - bits256 deposit_privkey,jumblr_privkey; - struct iguana_info *coin; - cJSON *utxos,*spentutxos,*bigutxos,*normalutxos,*smallutxos,*feeutxos,*otherutxos; - double btcprice,USD_average,DEXpending,maxbid,minask,avail,KMDavail; - uint32_t lasttime; - char CMCname[32],symbol[16],depositaddr[64],KMDdepositaddr[64],KMDjumblraddr[64],jumblraddr[64]; -};*/ + int64_t values[4],outputs[64],value,total,estfee = 50000; int32_t i,success=0,completed,sendflag,numoutputs = 0; char *retstr; cJSON *retjson,*utxo,*item; + total = 0; + memset(values,0,sizeof(values)); + memset(outputs,0,sizeof(outputs)); + if ( bigprice > SMALLVAL ) + values[0] = SATOSHIDEN * bigprice; + if ( middleprice > SMALLVAL ) + values[1] = SATOSHIDEN * middleprice; + if ( smallprice > SMALLVAL ) + values[2] = SATOSHIDEN * smallprice; + for (i=0; i<4; i++) + { + if ( fees[i] > SMALLVAL ) + values[3+i] = SATOSHIDEN * fees[i]; + } + for (i=0; i<7; i++) + { + if ( (value= values[i]) != 0 ) + { + while ( remaining > value+estfee && numoutputs < sizeof(outputs)/sizeof(*outputs) ) + { + outputs[numoutputs++] = value; + remaining -= value; + total += value; + printf("%.8f ",dstr(value)); + } + } + } + char str[65]; printf("numoutputs.%d total %.8f %s/v%d\n",numoutputs,dstr(total),bits256_str(str,txid),vout); + if ( numoutputs > 0 ) + { + if ( (retstr= _dex_gettxout(myinfo,coin->symbol,txid,vout)) != 0 ) + { + item = cJSON_Parse(retstr); + free(retstr); + if ( item != 0 ) + { + utxo = cJSON_CreateArray(); + jaddi(utxo,item); + sendflag = 0; + if ( (retstr= iguana_utxorawtx(myinfo,coin,0,coinaddr,coinaddr,outputs,numoutputs,0,&completed,sendflag,utxo)) != 0 ) + { + if ( completed != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(retjson,"error") == 0 && jobj(retjson,"sent") != 0 ) + { + *splittxidp = jbits256(retjson,"sent"); + success = 1; + printf("DEXsplit success %.8f\n",dstr(total)); + } + free_json(retjson); + } + } + free(retstr); + } + free_json(utxo); + } + } + } + return(success * total); +} -int32_t jumblr_DEXsplit(struct supernet_info *myinfo,bits256 *splittxidp,bits256 txid,int32_t vout,uint64_t value,double bigprice,double middleprice,double smallprice,double feeprice) +double jumblr_DEXutxosize(double *targetpriceBp,double *targetpriceMp,double *targetpriceSp,int32_t isbob) { - + double fee,depositfactor = (isbob == 0) ? 1. : 1.2; + fee = JUMBLR_INCR * JUMBLR_FEE; + *targetpriceBp = depositfactor * ((JUMBLR_INCR + 3*fee)*100 + 3*JUMBLR_TXFEE); + *targetpriceMp = depositfactor * ((JUMBLR_INCR + 3*fee)*10 + 3*JUMBLR_TXFEE); + *targetpriceSp = depositfactor * ((JUMBLR_INCR + 3*fee) + 3*JUMBLR_TXFEE); + return(depositfactor); } -int32_t jumblr_DEXutxoupdate(struct supernet_info *myinfo,bits256 *splittxidp,bits256 txid,int32_t vout,uint64_t value,int32_t isbob) +int32_t jumblr_DEXutxoind(int32_t *shouldsplitp,double targetpriceB,double targetpriceM,double targetpriceS,double amount,double margin,double dexfeeratio,double esttxfee) { - double targetpriceB,targetpriceM,targetpriceS,fee,depositfactor,dexfeeratio,margin = 1.1; - depositfactor = (isbob == 0) ? 1. : 1.2; - dexfeeratio = 500.; - memset(splittxidp,0,sizeof(*splittxidp)); - fee = JUMBLR_INCR * JUMBLR_FEE; - targetpriceB = depositfactor * ((JUMBLR_INCR + 3*fee)*100 + 3*JUMBLR_TXFEE); - targetpriceM = depositfactor * ((JUMBLR_INCR + 3*fee)*10 + 3*JUMBLR_TXFEE); - targetpriceS = depositfactor * ((JUMBLR_INCR + 3*fee) + 3*JUMBLR_TXFEE); - if ( value >= targetpriceB ) + *shouldsplitp = 0; + if ( amount >= targetpriceB ) { - if ( value > margin * (targetpriceB + targetpriceS) ) - jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,margin * targetpriceB,margin * targetpriceM,margin * targetpriceS,margin * targetpriceB/dexfeeratio); + if ( amount > margin * (targetpriceB + targetpriceS) ) + *shouldsplitp = 1; return(0); } else { - if ( value >= targetpriceM ) + if ( amount >= targetpriceM ) { - if ( value > margin * (targetpriceM + targetpriceS) ) - return(jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,0.,margin * targetpriceM,margin * targetpriceS,margin * targetpriceM/dexfeeratio)); - else return(0); + if ( amount > margin * (targetpriceM + targetpriceS) ) + *shouldsplitp = 1; + return(1); } else { - if ( value >= targetpriceS ) + if ( amount >= targetpriceS ) + { + if ( amount > margin * targetpriceS ) + *shouldsplitp = 1; + return(2); + } + else if ( amount >= targetpriceB/dexfeeratio ) + { + if ( amount > margin * targetpriceB/dexfeeratio ) + *shouldsplitp = 1; + return(3); + } + else if ( amount >= targetpriceM/dexfeeratio ) + { + if ( amount > margin * targetpriceM/dexfeeratio ) + *shouldsplitp = 1; + return(4); + } + else if ( amount >= targetpriceS/dexfeeratio ) { - if ( value > margin * targetpriceS ) - return(jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,0.,0.,margin * targetpriceS,margin * targetpriceS/dexfeeratio)); - else return(0); + if ( amount > margin * targetpriceS/dexfeeratio ) + *shouldsplitp = 1; + return(5); } - else if ( value > targetpriceS/dexfeeratio ) - return(jumblr_DEXsplit(myinfo,splittxidp,txid,vout,value,0.,0.,0.,margin * targetpriceS/dexfeeratio)); - else return(0); + else if ( amount >= esttxfee ) + { + if ( amount > esttxfee*4 ) + *shouldsplitp = 1; + return(6); + } + else return(-1); } } } -void jumblr_DEXupdate(struct supernet_info *myinfo,struct DEXcoin_info *ptr,char *symbol,char *CMCname,double BTC2KMD,double KMDavail) +int64_t jumblr_DEXutxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *splittxidp,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t isbob) { - double avebid,aveask,highbid,lowask,CMC_average,changes[3]; struct iguana_info *kmdcoin = iguana_coinfind("KMD"); - if ( kmdcoin != 0 && time(NULL) > ptr->lasttime+60 ) + double fees[4],targetpriceB,amount,targetpriceM,targetpriceS,depositfactor,dexfeeratio,margin; int32_t ind,shouldsplit; + margin = 1.1; + depositfactor = (isbob == 0) ? 1. : 1.2; + dexfeeratio = 500.; + amount = dstr(value); + memset(splittxidp,0,sizeof(*splittxidp)); + depositfactor = jumblr_DEXutxosize(&targetpriceB,&targetpriceM,&targetpriceS,isbob); + fees[0] = (margin * targetpriceB) / dexfeeratio; + fees[1] = (margin * targetpriceM) / dexfeeratio; + fees[2] = (margin * targetpriceS) / dexfeeratio; + fees[3] = (strcmp("BTC",coin->symbol) == 0) ? 50000 : 10000; + if ( (ind= jumblr_DEXutxoind(&shouldsplit,targetpriceB,targetpriceM,targetpriceS,amount,margin,dexfeeratio,fees[3])) >= 0 ) { - if ( strcmp(symbol,ptr->symbol) != 0 || ptr->coin == 0 ) + if ( shouldsplit != 0 ) + return(jumblr_DEXsplit(myinfo,coin,splittxidp,coinaddr,txid,vout,value,margin * targetpriceB,margin * targetpriceM,margin * targetpriceS,fees)); + } + return(0); +} + +/*struct DEXcoin_info + { + bits256 deposit_privkey,jumblr_privkey; + struct iguana_info *coin; + cJSON *utxos,*spentutxos,*bigutxos,*normalutxos,*smallutxos,*feeutxos,*otherutxos; + double btcprice,USD_average,DEXpending,maxbid,minask,avail,KMDavail; + uint32_t lasttime; + char CMCname[32],symbol[16],depositaddr[64],KMDdepositaddr[64],KMDjumblraddr[64],jumblraddr[64]; + };*/ + +int32_t jumblr_utxotxidpending(struct supernet_info *myinfo,bits256 *splittxidp,struct iguana_info *coin,bits256 txid,int32_t vout) +{ + int32_t i; + memset(splittxidp,0,sizeof(*splittxidp)); + for (i=0; iDEXinfo.numpending; i++) + { + if ( coin->DEXinfo.pending[i].vout == vout && bits256_cmp(coin->DEXinfo.pending[i].txid,txid) == 0 ) + { + *splittxidp = coin->DEXinfo.pending[i].splittxid; + return(i); + } + } + return(-1); +} + +void jumblr_utxotxidpendingadd(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout,bits256 splittxid) +{ + struct jumblr_pending pend; + memset(&pend,0,sizeof(pend)); + pend.splittxid = splittxid; + pend.txid = txid; + pend.vout = vout; + coin->DEXinfo.pending = realloc(coin->DEXinfo.pending,sizeof(*coin->DEXinfo.pending) * (1 + coin->DEXinfo.numpending)); + coin->DEXinfo.pending[coin->DEXinfo.numpending++] = pend; +} + +void jumblr_utxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,double price,char *coinaddr) +{ + char *retstr; cJSON *array,*item; int32_t i,n,vout; bits256 txid,splittxid; uint64_t value; + if ( (retstr= _dex_listunspent(myinfo,coin->symbol,coinaddr)) != 0 ) + { + if ( (array= cJSON_Parse(retstr)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; iIAMLP); + jumblr_utxotxidpendingadd(myinfo,coin,txid,vout,splittxid); + } + } + } + free_json(array); + } + free(retstr); + } +} + +void jumblr_DEXupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *CMCname,double BTC2KMD,double KMDavail) +{ + double avebid,aveask,highbid,lowask,CMC_average,changes[3]; struct iguana_info *btccoin,*kmdcoin; struct DEXcoin_info *ptr = &coin->DEXinfo; + if ( coin != 0 && (kmdcoin= iguana_coinfind("KMD")) != 0 && time(NULL) > ptr->lasttime+60 ) + { + ptr->coin = coin; + if ( strcmp(symbol,ptr->symbol) != 0 ) { safecopy(ptr->symbol,symbol,sizeof(ptr->symbol)); safecopy(ptr->CMCname,CMCname,sizeof(ptr->CMCname)); - if ( ptr->coin == 0 ) - ptr->coin = iguana_coinfind(symbol); } - if ( ptr->coin != 0 ) + if ( ptr->depositaddr[0] == 0 ) { - if ( ptr->depositaddr[0] == 0 ) - ptr->deposit_privkey = jumblr_privkey(myinfo,ptr->depositaddr,ptr->coin->chain->pubtype,ptr->KMDdepositaddr,JUMBLR_DEPOSITPREFIX); - if ( ptr->jumblraddr[0] == 0 ) - ptr->jumblr_privkey = jumblr_privkey(myinfo,ptr->jumblraddr,ptr->coin->chain->pubtype,ptr->KMDjumblraddr,""); - ptr->avail = dstr(jumblr_balance(myinfo,ptr->coin,ptr->depositaddr)); + if ( strcmp("KMD",symbol) == 0 ) + ptr->deposit_privkey = jumblr_privkey(myinfo,ptr->depositaddr,0,ptr->KMDdepositaddr,JUMBLR_DEPOSITPREFIX); + else ptr->deposit_privkey = jumblr_privkey(myinfo,ptr->depositaddr,ptr->coin->chain->pubtype,ptr->KMDdepositaddr,JUMBLR_DEPOSITPREFIX); } + if ( ptr->jumblraddr[0] == 0 ) + ptr->jumblr_privkey = jumblr_privkey(myinfo,ptr->jumblraddr,ptr->coin->chain->pubtype,ptr->KMDjumblraddr,""); + ptr->avail = dstr(jumblr_balance(myinfo,ptr->coin,ptr->depositaddr)); ptr->btcprice = get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,CMCname,symbol,"BTC",&ptr->USD_average); if ( strcmp("KMD",symbol) == 0 ) { ptr->BTC2KMD = ptr->btcprice; ptr->kmdprice = 1.; ptr->KMDavail = ptr->avail; + if ( (btccoin= iguana_coinfind("BTC")) != 0 ) + jumblr_utxoupdate(myinfo,btccoin,ptr->btcprice,ptr->depositaddr); + jumblr_utxoupdate(myinfo,kmdcoin,1.,ptr->KMDdepositaddr); } else if ( (ptr->BTC2KMD= BTC2KMD) > SMALLVAL ) { ptr->kmdprice = ptr->btcprice / BTC2KMD; ptr->KMDavail = KMDavail; + jumblr_utxoupdate(myinfo,ptr->coin,ptr->kmdprice,ptr->depositaddr); } ptr->lasttime = (uint32_t)time(NULL); } } +void jumblr_CMCname(char *CMCname,char *symbol) +{ + if ( strcmp(symbol,"KMD") == 0 ) + strcpy(CMCname,"komodo"); +} + void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin) { struct iguana_info *kmdcoin; if ( (kmdcoin= iguana_coinfind("KMD")) == 0 ) return; - jumblr_DEXupdate(myinfo,&kmdcoin->DEXinfo,"KMD","komodo",0.,0.); + jumblr_DEXupdate(myinfo,kmdcoin,"KMD","komodo",0.,0.); if ( strcmp(coin->symbol,"KMD") != 0 && kmdcoin->DEXinfo.btcprice > 0. ) - jumblr_DEXupdate(myinfo,&coin->DEXinfo,"KMD","komodo",kmdcoin->DEXinfo.btcprice,kmdcoin->DEXinfo.avail); + { + if ( coin->CMCname[0] == 0 ) + jumblr_CMCname(coin->CMCname,coin->symbol); + if ( coin->CMCname[0] != 0 ) + jumblr_DEXupdate(myinfo,coin,coin->symbol,coin->CMCname,kmdcoin->DEXinfo.btcprice,kmdcoin->DEXinfo.avail); + } /*if ( kmdprice > SMALLVAL ) { minbtc = (kmdprice * 1.2) * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE)); diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index 80988fa5f..115e90a98 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -1279,7 +1279,7 @@ double get_theoretical(double *avebidp,double *aveaskp,double *highbidp,double * weighted = weighted_orderbook(avebidp,aveaskp,highbidp,lowaskp,bittrex_orderbook(base,rel,25),1./(*CMC_averagep)); if ( *CMC_averagep > SMALLVAL && weighted > SMALLVAL ) theoretical = calc_theoretical(weighted,*CMC_averagep,changes); - if ( counter++ == 0 ) + if ( counter++ < 100 ) printf("HBLA.[%.8f %.8f] AVE.[%.8f %.8f] (%s) CMC %f %f %f %f\n",*highbidp,*lowaskp,*avebidp,*aveaskp,jprint(item,0),*CMC_averagep,changes[0],changes[1],changes[2]); free_json(cmcjson); } diff --git a/iguana/coins/genbtc b/iguana/coins/genbtc index 839825619..407783045 100755 --- a/iguana/coins/genbtc +++ b/iguana/coins/genbtc @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333,\"minconfirms\":1}" +curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":16,\"endpend\":4,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333,\"minconfirms\":1}" diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 43760ebd7..cfe164a8a 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -545,12 +545,14 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS return(rawtx); } -char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *utxos,char *remoteaddr,struct vin_info *V,int32_t maxmode) +char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t *outputs,int32_t numoutputs,char *changeaddr,int64_t txfee,cJSON *utxos,char *remoteaddr,struct vin_info *V,int32_t maxmode) { - uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; int32_t allocflag=0,max,i,n,num,spendlen; char *spendscriptstr,*rawtx=0; bits256 txid; cJSON *sobj,*vins=0,*item; uint64_t value,avail=0,total,change,interests; struct iguana_outpoint *unspents = 0; + uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; int32_t allocflag=0,max,i,n,num,spendlen; char *spendscriptstr,*rawtx=0; uint64_t satoshis = 0; bits256 txid; cJSON *sobj,*vins=0,*item; uint64_t value,avail=0,total,change,interests; struct iguana_outpoint *unspents = 0; *vinsp = 0; max = 0; interests = 0; + for (i=0; i Date: Thu, 30 Mar 2017 02:22:25 +0300 Subject: [PATCH 03/16] Test --- basilisk/jumblr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basilisk/jumblr.c b/basilisk/jumblr.c index 3a15322ac..0ba6e311b 100755 --- a/basilisk/jumblr.c +++ b/basilisk/jumblr.c @@ -639,8 +639,9 @@ void jumblr_CMCname(char *CMCname,char *symbol) void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin) { struct iguana_info *kmdcoin; - if ( (kmdcoin= iguana_coinfind("KMD")) == 0 ) + if ( (kmdcoin= iguana_coinfind("KMD")) == 0 || iguana_coinfind("BTC") == 0 ) return; + printf("jumblr_DEXcheck\n"); jumblr_DEXupdate(myinfo,kmdcoin,"KMD","komodo",0.,0.); if ( strcmp(coin->symbol,"KMD") != 0 && kmdcoin->DEXinfo.btcprice > 0. ) { From 625cdd982aba865a493127c24f9fd9b430a25167 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 02:36:52 +0300 Subject: [PATCH 04/16] Test --- iguana/iguana_tx.c | 2 +- iguana/m_LP | 6 +++--- iguana/m_osx | 2 +- iguana/m_test | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index e096ab1bb..2385fa6e8 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -307,7 +307,7 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info char str[65],str2[65]; if ( counter++ < 100 ) { - for (i=0; ihdrsi,bundlei,bits256_str(str,checktxid),bits256_str(str2,T.txid)); } diff --git a/iguana/m_LP b/iguana/m_LP index d09ee9373..999ba620c 100755 --- a/iguana/m_LP +++ b/iguana/m_LP @@ -4,6 +4,6 @@ rm -f ../agents/iguana *.o git pull cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -clang -g -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -clang -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c -clang -g -o ../agents/iguana *.o ../agents/libcrypto777.a /usr/local/lib/libnanomsg.so -lcurl -lssl -lcrypto -lpthread -lz -lm +gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c +gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a /usr/local/lib/libnanomsg.so -lcurl -lssl -lcrypto -lpthread -lz -lm diff --git a/iguana/m_osx b/iguana/m_osx index 500053d38..e752b11cc 100755 --- a/iguana/m_osx +++ b/iguana/m_osx @@ -4,5 +4,5 @@ rm ../agents/iguana *.o git pull cd secp256k1; ./m_unix; cd .. gcc -g -Wno-address-of-packed-member -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -gcc -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c +gcc -g -Wno-address-of-packed-member -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lnanomsg -lcurl -lssl -lcrypto -lpthread -lz -lm diff --git a/iguana/m_test b/iguana/m_test index 702cbb33e..27c8be43a 100755 --- a/iguana/m_test +++ b/iguana/m_test @@ -5,7 +5,7 @@ git pull cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -O2 -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c +gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lnanomsg -lcurl -lssl -lcrypto -lpthread -lz -lm ../agents/iguana notary & #> iguana.log 2> error.log & From cab64f08e4e90baef733046924303ed5fc3cda65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 02:47:55 +0300 Subject: [PATCH 05/16] Test --- iguana/m_LP | 6 +++--- iguana/m_osx_release | 6 +++--- iguana/pangea777.h | 2 +- includes/iguana_structs.h | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/iguana/m_LP b/iguana/m_LP index 999ba620c..ff173b759 100755 --- a/iguana/m_LP +++ b/iguana/m_LP @@ -4,6 +4,6 @@ rm -f ../agents/iguana *.o git pull cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c -gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a /usr/local/lib/libnanomsg.so -lcurl -lssl -lcrypto -lpthread -lz -lm +clang -g -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +clang -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c +clang -g -o ../agents/iguana *.o ../agents/libcrypto777.a /usr/local/lib/libnanomsg.so -lcurl -lssl -lcrypto -lpthread -lz -lm diff --git a/iguana/m_osx_release b/iguana/m_osx_release index 19c94d74b..5f74885e7 100755 --- a/iguana/m_osx_release +++ b/iguana/m_osx_release @@ -3,6 +3,6 @@ rm ../agents/iguana *.o git pull cd secp256k1; ./m_osx_release; cd .. -gcc -g -mmacosx-version-min=10.6 -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -gcc -g -mmacosx-version-min=10.6 -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c -gcc -g -mmacosx-version-min=10.6 /usr/local/lib/libnanomsg.5.0.0.dylib -o ../agents/iguana *.o ../agents/libcrypto777.a -lcurl -lssl -lcrypto -lpthread -lz -lm +clang -g -mmacosx-version-min=10.6 -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +clang -g -mmacosx-version-min=10.6 -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c +clang -g -mmacosx-version-min=10.6 /usr/local/lib/libnanomsg.5.0.0.dylib -o ../agents/iguana *.o ../agents/libcrypto777.a -lcurl -lssl -lcrypto -lpthread -lz -lm diff --git a/iguana/pangea777.h b/iguana/pangea777.h index 731531f84..1ff471e3a 100755 --- a/iguana/pangea777.h +++ b/iguana/pangea777.h @@ -128,7 +128,7 @@ struct pangea_msghdr char cmd[8]; int8_t turni,cardi,destplayer,myind; // ALL DATA MUST BE SERIALIZED!!! uint8_t serialized[]; -} PACKED; +};// PACKED; #define PANGEA_ARGS struct supernet_info *myinfo,struct table_info *tp,cJSON *json #define PANGEA_CALLARGS myinfo,tp,json diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index e52b6c037..27ea9af8f 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -141,7 +141,7 @@ struct iguana_msgmerkle uint32_t branch_length; bits256 branch_hash[4096]; uint32_t branch_side_mask; -}PACKEDSTRUCT; +}; //PACKEDSTRUCT; struct iguana_msgblock { @@ -155,9 +155,9 @@ struct iguana_msgzblock uint32_t txn_count; } PACKEDSTRUCT; -struct iguana_msgvin { bits256 prev_hash; uint8_t *vinscript,*userdata,*spendscript,*redeemscript; uint32_t prev_vout,sequence; uint16_t scriptlen,p2shlen,userdatalen,spendlen; }PACKEDSTRUCT; +struct iguana_msgvin { bits256 prev_hash; uint8_t *vinscript,*userdata,*spendscript,*redeemscript; uint32_t prev_vout,sequence; uint16_t scriptlen,p2shlen,userdatalen,spendlen; }; //PACKEDSTRUCT; -struct iguana_msgvout { uint64_t value; uint32_t pk_scriptlen; uint8_t *pk_script; }PACKEDSTRUCT; +struct iguana_msgvout { uint64_t value; uint32_t pk_scriptlen; uint8_t *pk_script; }; //PACKEDSTRUCT; struct iguana_msgtx { @@ -168,7 +168,7 @@ struct iguana_msgtx int32_t allocsize,timestamp,numinputs,numoutputs; int64_t inputsum,outputsum,txfee; uint8_t *serialized; -} PACKEDSTRUCT; +};// PACKEDSTRUCT; struct iguana_msgjoinsplit { From fc53dc61a93d8b1f3e885db55aeebf2cdfe2f445 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 02:55:50 +0300 Subject: [PATCH 06/16] Test --- iguana/iguana_ramchain.c | 1 + iguana/m_LP | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index a2cb07fdc..fab094e61 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -2176,6 +2176,7 @@ int32_t iguana_bundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **ptrs void iguana_bundlemapfree(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *hashmem,uint32_t *ipbits,void **ptrs,long *filesizes,int32_t num,struct iguana_ramchain *R,int32_t starti,int32_t endi) { int32_t j,n = (endi - starti + 1); + sleep(3); for (j=0; j Date: Thu, 30 Mar 2017 03:06:43 +0300 Subject: [PATCH 07/16] Test --- iguana/iguana_ramchain.c | 1 - iguana/iguana_tx.c | 7 +++++-- iguana/m_LP | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index fab094e61..a2cb07fdc 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -2176,7 +2176,6 @@ int32_t iguana_bundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **ptrs void iguana_bundlemapfree(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *hashmem,uint32_t *ipbits,void **ptrs,long *filesizes,int32_t num,struct iguana_ramchain *R,int32_t starti,int32_t endi) { int32_t j,n = (endi - starti + 1); - sleep(3); for (j=0; j Date: Thu, 30 Mar 2017 03:12:46 +0300 Subject: [PATCH 08/16] Test --- iguana/iguana_ramchain.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index a2cb07fdc..2926906b9 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -258,7 +258,9 @@ uint32_t iguana_ramchain_addpkhash(struct iguana_info *coin,RAMCHAIN_FUNC,uint8_ P[pkind].firstunspentind = unspentind; printf("%p P[%d] <- firstunspent.%d\n",&P[pkind],pkind,unspentind); }*/ - memcpy(P[pkind].rmd160,rmd160,sizeof(P[pkind].rmd160)); + //memcpy(P[pkind].rmd160,rmd160,sizeof(P[pkind].rmd160)); + for (i=0; i<20; i++) + P[pkind].rmd160[i] = rmd160[i]; //for (i=0; i<20; i++) // printf("%02x",rmd160[i]); //printf(" -> rmd160 pkind.%d \n",pkind); @@ -276,7 +278,7 @@ uint32_t iguana_ramchain_addpkhash(struct iguana_info *coin,RAMCHAIN_FUNC,uint8_ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_peer *addr,RAMCHAIN_FUNC,uint64_t value,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vout,int8_t type,struct iguana_bundle *bp,uint8_t rmd160[20]) { - uint32_t unspentind; struct iguana_unspent20 *u; long scriptpos; struct vin_info V; char asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; + uint32_t unspentind,i; struct iguana_unspent20 *u; long scriptpos; struct vin_info V; char asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; unspentind = ramchain->H.unspentind++; u = &U[unspentind]; if ( scriptlen > 0 ) @@ -287,14 +289,16 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee type = iguana_calcrmd160(coin,asmstr,&V,script,scriptlen,txid,vout,0xffffffff); if ( (type == 12 && scriptlen == 0) || (type == 1 && bitcoin_pubkeylen(script+1) <= 0) ) { - int32_t i; for (i=0; iH.ROflag != 0 ) @@ -309,7 +313,9 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee { u->value = value; u->type = type; - memcpy(u->rmd160,rmd160,sizeof(u->rmd160)); + //memcpy(u->rmd160,rmd160,sizeof(u->rmd160)); + for (i=0; i<20; i++) + u->rmd160[i] = rmd160[i]; if ( type == IGUANA_SCRIPT_76AC ) { static uint64_t totalsize; @@ -693,7 +699,7 @@ void *iguana_ramchain_offset(char *fname,void *dest,uint8_t *lhash,FILE *fp,uint int32_t iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t flag) { RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; - struct iguana_pkhash p; struct iguana_unspent u; struct iguana_txid txid; uint32_t i,numpkinds,numtxids,numunspents,numexternal,tlen,plen,nonz=0; uint8_t *ptr; struct iguana_ramchaindata *rdata; + struct iguana_pkhash p; struct iguana_unspent u; struct iguana_txid txid; uint32_t i,j,numpkinds,numtxids,numunspents,numexternal,tlen,plen,nonz=0; uint8_t *ptr; struct iguana_ramchaindata *rdata; //return(0); if ( (rdata= ramchain->H.data) != 0 ) { @@ -716,7 +722,9 @@ int32_t iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain tlen = (rdata->numtxsparse * rdata->txsparsebits) >> 3; for (i=0; i Date: Thu, 30 Mar 2017 03:17:56 +0300 Subject: [PATCH 09/16] Test --- crypto777/iguana_OS.c | 1 + iguana/iguana_ramchain.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crypto777/iguana_OS.c b/crypto777/iguana_OS.c index 8bd55e0d1..504905ee1 100755 --- a/crypto777/iguana_OS.c +++ b/crypto777/iguana_OS.c @@ -422,6 +422,7 @@ void *iguana_meminit(struct OS_memspace *mem,char *name,void *ptr,int64_t totals mem->totalsize = totalsize; } mem->threadsafe = threadsafe; + mem->alignflag = 4; iguana_memreset(mem); if ( mem->totalsize == 0 ) printf("meminit.%s ILLEGAL STATE null size\n",mem->name), getchar(); diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 2926906b9..91b388a46 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -71,7 +71,7 @@ struct iguana_kvitem *iguana_hashsetPT(struct iguana_ramchain *ramchain,int32_t printf("negative itemind\n"); iguana_exit(0,0); } - if ( (0) ) + if ( (1) ) { if ( selector == 'T' ) HASH_FIND(hh,ramchain->txids,key,keylen,tmp); From 36b602a3ab7dd2742acd14eba2f007a7f467dce2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 03:20:06 +0300 Subject: [PATCH 10/16] Test --- iguana/m_LP | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/m_LP b/iguana/m_LP index 229b1936d..c93d5cf6b 100755 --- a/iguana/m_LP +++ b/iguana/m_LP @@ -4,6 +4,6 @@ rm -f ../agents/iguana *.o git pull cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -#gcc -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c +gcc -g -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +gcc -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a /usr/local/lib/libnanomsg.so -lcurl -lssl -lcrypto -lpthread -lz -lm From edc1adf132ff9a4cdc7b241bc392cfa70c93d928 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 03:26:38 +0300 Subject: [PATCH 11/16] Test --- includes/iguana_globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/iguana_globals.h b/includes/iguana_globals.h index 07170e132..f4fda978c 100755 --- a/includes/iguana_globals.h +++ b/includes/iguana_globals.h @@ -42,7 +42,7 @@ char GLOBAL_GENESISDIR[512] = "genesis"; char GLOBAL_VALIDATEDIR[512] = "DB/purgeable"; char GLOBAL_CONFSDIR[512] = "confs"; #ifdef __linux -int32_t IGUANA_NUMHELPERS = 4; +int32_t IGUANA_NUMHELPERS = 1; #else int32_t IGUANA_NUMHELPERS = 1; #endif From 32d19a6d2685463267e9a8946a88a94e13656a54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 03:48:17 +0300 Subject: [PATCH 12/16] Test --- iguana/iguana_ramchain.c | 2 ++ includes/iguana_globals.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 91b388a46..64ca06287 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -2197,6 +2197,8 @@ void iguana_bundlemapfree(struct iguana_info *coin,struct OS_memspace *mem,struc { for (j=starti; j<=endi; j++) { + R[j].fileptr = 0; + R[j].filesize = 0; iguana_ramchain_free(coin,&R[j],1); } myfree(R,n * sizeof(*R)); diff --git a/includes/iguana_globals.h b/includes/iguana_globals.h index f4fda978c..31a91a073 100755 --- a/includes/iguana_globals.h +++ b/includes/iguana_globals.h @@ -42,7 +42,7 @@ char GLOBAL_GENESISDIR[512] = "genesis"; char GLOBAL_VALIDATEDIR[512] = "DB/purgeable"; char GLOBAL_CONFSDIR[512] = "confs"; #ifdef __linux -int32_t IGUANA_NUMHELPERS = 1; +int32_t IGUANA_NUMHELPERS = 8; #else int32_t IGUANA_NUMHELPERS = 1; #endif From b5286807344c62de67e1868e1ba6943b9601af49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 03:52:36 +0300 Subject: [PATCH 13/16] Test --- iguana/m_LP | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/m_LP b/iguana/m_LP index c93d5cf6b..8a00d3caa 100755 --- a/iguana/m_LP +++ b/iguana/m_LP @@ -4,6 +4,6 @@ rm -f ../agents/iguana *.o git pull cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -gcc -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c +gcc -g -Waggressive-loop-optimizations -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +gcc -g -Waggressive-loop-optimizations -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a /usr/local/lib/libnanomsg.so -lcurl -lssl -lcrypto -lpthread -lz -lm From 61432a9a91e870b3c9476397228381ed239a2330 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 03:54:16 +0300 Subject: [PATCH 14/16] Test --- iguana/m_LP | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/m_LP b/iguana/m_LP index 8a00d3caa..0e1135b48 100755 --- a/iguana/m_LP +++ b/iguana/m_LP @@ -4,6 +4,6 @@ rm -f ../agents/iguana *.o git pull cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -Waggressive-loop-optimizations -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -gcc -g -Waggressive-loop-optimizations -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c +gcc -g -Wno-aggressive-loop-optimizations -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +gcc -g -Wno-aggressive-loop-optimizations -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a /usr/local/lib/libnanomsg.so -lcurl -lssl -lcrypto -lpthread -lz -lm From adcd5f956b3e002f7aa41e83eed85788f6509c95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 03:59:16 +0300 Subject: [PATCH 15/16] Test --- basilisk/basilisk_swap.c | 36 +++++++++++++++++++++--------------- iguana/iguana_unspents.c | 5 ++++- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index 9b3abc4d5..c810ea103 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -1120,20 +1120,22 @@ void basilisk_swaps_init(struct supernet_info *myinfo) 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 ( fread(M.data,1,M.datalen,fp) == M.datalen ) { - if ( iter == 1 ) + if ( calc_crc32(0,M.data,M.datalen) == M.crc32 ) { - if ( swap == 0 ) + if ( iter == 1 ) { - swap = basilisk_thread_start(myinfo,privkey,&R,statebits,optionduration,1); - swap->I.choosei = swap->I.otherchoosei = -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); } - 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); + } else printf("crc mismatch %x vs %x\n",calc_crc32(0,M.data,M.datalen),M.crc32); + } else printf("error reading M.datalen %d\n",M.datalen); free(M.data), M.data = 0; } } @@ -1456,14 +1458,15 @@ int32_t basilisk_swap_loadtx(struct basilisk_rawtx *rawtx,FILE *fp,char *bobcoin 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; + FILE *fp; char fname[512]; uint8_t *alicepub33=0,*bobpub33=0; int32_t errs=0,jumblrflag,x = -1; if ( reinit != 0 ) { 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 ( fread(&swap->I,1,sizeof(swap->I),fp) != sizeof(swap->I) ) + errs++; if ( swap->bobcoin == 0 ) swap->bobcoin = iguana_coinfind(swap->I.req.dest); if ( swap->alicecoin == 0 ) @@ -1482,9 +1485,12 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv 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); + if ( fread(swap->privkeys,1,sizeof(swap->privkeys),fp) != sizeof(swap->privkeys) ) + errs++; + if ( fread(swap->otherdeck,1,sizeof(swap->otherdeck),fp) != sizeof(swap->otherdeck) ) + errs++; + if ( fread(swap->deck,1,sizeof(swap->deck),fp) != sizeof(swap->deck) ) + errs++; fclose(fp); } else printf("cant find.(%s)\n",fname); } diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 6534c2431..2974c300f 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -1896,7 +1896,10 @@ INT_ARRAY_STRING(iguana,dividends,height,vals,symbol) { sprintf(buf,"%s %s %.8f %s",prefix,field,dstr(val),suffix); if ( execflag != 0 ) - system(buf); + { + if ( system(buf) != 0 ) + printf("error system.(%s)\n",buf); + } else printf("%s\n",buf); emit += val; } else dustsum += val; From ed2048ebc8009423f350e3139adbd1471c93fc92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Mar 2017 04:03:51 +0300 Subject: [PATCH 16/16] Test --- iguana/coins/genbtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/coins/genbtc b/iguana/coins/genbtc index 407783045..839825619 100755 --- a/iguana/coins/genbtc +++ b/iguana/coins/genbtc @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":16,\"endpend\":4,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333,\"minconfirms\":1}" +curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333,\"minconfirms\":1}"