From 69a4d334e4d99d093efe82409191125adca5bdf6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 8 Dec 2017 22:15:17 +0400 Subject: [PATCH 01/34] Test --- iguana/exchanges/LP_instantdex.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 273d1bcc3..e744a3c0b 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -480,15 +480,18 @@ int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue) credits = ap->instantdex_credits; if ( credits != 0 && (swaps_kmdvalue+kmdvalue) > credits ) { - DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp) - { - if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) - printf("unfinished bob %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis))); - } - DL_FOREACH_SAFE(pubp->aliceswaps,ptr,tmp) + if ( 0 ) { - if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) - printf("unfinished alice %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis))); + DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp) + { + if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) + printf("unfinished bob %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis))); + } + DL_FOREACH_SAFE(pubp->aliceswaps,ptr,tmp) + { + if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) + printf("unfinished alice %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis))); + } } printf("REJECT: %s instantdex_credits %.8f vs (%.8f + current %.8f)\n",coinaddr,dstr(credits),dstr(swaps_kmdvalue),dstr(kmdvalue)); } From d570ea7915227a1b2f637b1164eba57ca41fe2d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 8 Dec 2017 23:39:38 +0400 Subject: [PATCH 02/34] Test --- iguana/exchanges/LP_remember.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 9b162c363..389c0c8d9 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1004,7 +1004,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) { - if ( time(NULL) > rswap.expiration ) + if ( time(NULL) > rswap.expiration+777 ) { flag = 0; if ( bob->electrum == 0 ) @@ -1093,7 +1093,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti free_json(txoutobj), flag = 0; else flag = -1, rswap.paymentspent = deadtxid; } - if ( flag == 0 && time(NULL) > rswap.expiration ) + if ( flag == 0 && time(NULL) > rswap.expiration+777 ) { // bobreclaim redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,zero,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); @@ -1122,7 +1122,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti free_json(txoutobj), flag = 0; else flag = -1, rswap.depositspent = deadtxid; } - if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration) ) + if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777) ) { printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration); //if ( txbytes[BASILISK_BOBREFUND] == 0 ) From ef16110815c95e743f5738aaa03f083f3261d4c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 00:17:26 +0400 Subject: [PATCH 03/34] Test --- iguana/exchanges/LP_remember.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 389c0c8d9..46e0b0788 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -995,7 +995,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } for (j=0; j<32; j++) rev.bytes[j] = rswap.myprivs[0].bytes[31 - j]; - if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration+777,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]); } LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]); @@ -1025,7 +1025,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( bits256_nonz(rswap.privBn) != 0 ) { len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration+777,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICECLAIM]); } } @@ -1047,7 +1047,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn); if ( bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) { - if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration+777,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 ) printf("privBn.(%s) alicereclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICERECLAIM]); } LP_txbytes_update("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],&rswap.txids[BASILISK_ALICERECLAIM],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_ALICERECLAIM]); @@ -1077,7 +1077,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) { - if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration+777,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 ) printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]); } LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]); @@ -1100,7 +1100,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( redeemlen > 0 ) { len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration+777,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) { int32_t z; for (z=0; z<20; z++) @@ -1131,7 +1131,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti vcalc_sha256(0,rswap.secretBn256,rswap.privBn.bytes,sizeof(rswap.privBn)); redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration+777,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]); } LP_txbytes_update("bobrefund",rswap.bobcoin,rswap.txbytes[BASILISK_BOBREFUND],&rswap.txids[BASILISK_BOBREFUND],&rswap.depositspent,&rswap.sentflags[BASILISK_BOBREFUND]); From e984cc26db25459025b416e0fc308d4fae00930b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 00:19:31 +0400 Subject: [PATCH 04/34] Test --- iguana/exchanges/LP_remember.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 46e0b0788..389c0c8d9 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -995,7 +995,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } for (j=0; j<32; j++) rev.bytes[j] = rswap.myprivs[0].bytes[31 - j]; - if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration+777,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]); } LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]); @@ -1025,7 +1025,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( bits256_nonz(rswap.privBn) != 0 ) { len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration+777,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICECLAIM]); } } @@ -1047,7 +1047,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn); if ( bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) { - if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration+777,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 ) printf("privBn.(%s) alicereclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICERECLAIM]); } LP_txbytes_update("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],&rswap.txids[BASILISK_ALICERECLAIM],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_ALICERECLAIM]); @@ -1077,7 +1077,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) { - if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration+777,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 ) printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]); } LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]); @@ -1100,7 +1100,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( redeemlen > 0 ) { len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration+777,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) { int32_t z; for (z=0; z<20; z++) @@ -1131,7 +1131,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti vcalc_sha256(0,rswap.secretBn256,rswap.privBn.bytes,sizeof(rswap.privBn)); redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration+777,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]); } LP_txbytes_update("bobrefund",rswap.bobcoin,rswap.txbytes[BASILISK_BOBREFUND],&rswap.txids[BASILISK_BOBREFUND],&rswap.depositspent,&rswap.sentflags[BASILISK_BOBREFUND]); From 4b5abbb4bff5efc1c298ed241ffdfde179b2a3cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 00:44:28 +0400 Subject: [PATCH 05/34] Test --- iguana/exchanges/LP_remember.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 389c0c8d9..013b385a6 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1100,7 +1100,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( redeemlen > 0 ) { len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) + uint32_t claimtime = (uint32_t)(time(NULL) - 777); + printf("claimtime %u vs expiration.%u\n",claimtime,rswap.expiration); + if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) { int32_t z; for (z=0; z<20; z++) From dece9786f146df5c78d9c4ec6fecf51ec2a50462 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 09:30:52 +0400 Subject: [PATCH 06/34] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/LP_remember.c | 4 +--- iguana/exchanges/LP_transaction.c | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 52ba08f12..5e320beff 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,18 +19,18 @@ // // fundvalue -> autoprice, cmc +margin -> autoprice, signals -> autoprice // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG -// there is an issue about waiting for notarization for a swap that never starts -// use electrum in case of addr change in swap // // compress packets // portfolio to set prices from historical // portfolio value based on ask? // // else claim path -// swap memleak? // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs // improve critical section detection when parallel trades +// use electrum in case of addr change in swap +// locktime claiming on sporadic assetchains +// there is an issue about waiting for notarization for a swap that never starts #include diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 013b385a6..389c0c8d9 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1100,9 +1100,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( redeemlen > 0 ) { len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); - uint32_t claimtime = (uint32_t)(time(NULL) - 777); - printf("claimtime %u vs expiration.%u\n",claimtime,rswap.expiration); - if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) + if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) { int32_t z; for (z=0; z<20; z++) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 8461474ba..566d7b250 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1660,7 +1660,7 @@ bits256 LP_swap_spendtxid(char *symbol,char *destaddr,bits256 utxotxid,int32_t u memset(&spendtxid,0,sizeof(spendtxid)); if ( LP_spendsearch(destaddr,&spendtxid,&spendvin,symbol,utxotxid,utxovout) > 0 ) { - //printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),vout); + char str[65]; printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),utxovout); } else if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum == 0 ) { @@ -1675,7 +1675,7 @@ bits256 LP_swap_spendtxid(char *symbol,char *destaddr,bits256 utxotxid,int32_t u { if ( (vins= jarray(&m,txobj,"vin")) != 0 ) { - //printf("vins.(%s)\n",jprint(vins,0)); +printf("vins.(%s)\n",jprint(vins,0)); if ( utxovout < m ) { vin = jitem(vins,utxovout); From 1c0815ab1ab01210e49e75a52c53404debe6f437 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 09:37:11 +0400 Subject: [PATCH 07/34] Test --- iguana/exchanges/LP_remember.c | 2 ++ iguana/exchanges/LP_transaction.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 389c0c8d9..086528f03 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -375,6 +375,8 @@ int32_t basilisk_swap_isfinished(int32_t iambob,bits256 *txids,int32_t *sentflag } else if ( bits256_nonz(Apaymentspent) != 0 ) return(1); + else if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(depositspent) != 0 ) + return(1); } else { diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 566d7b250..4f458beff 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1660,7 +1660,7 @@ bits256 LP_swap_spendtxid(char *symbol,char *destaddr,bits256 utxotxid,int32_t u memset(&spendtxid,0,sizeof(spendtxid)); if ( LP_spendsearch(destaddr,&spendtxid,&spendvin,symbol,utxotxid,utxovout) > 0 ) { - char str[65]; printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),utxovout); + //char str[65]; printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),utxovout); } else if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum == 0 ) { @@ -1675,7 +1675,7 @@ bits256 LP_swap_spendtxid(char *symbol,char *destaddr,bits256 utxotxid,int32_t u { if ( (vins= jarray(&m,txobj,"vin")) != 0 ) { -printf("vins.(%s)\n",jprint(vins,0)); +//printf("vins.(%s)\n",jprint(vins,0)); if ( utxovout < m ) { vin = jitem(vins,utxovout); From d1f30b81e9e8ab9cb0c647a81f63dcabfb3b8554 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 09:40:43 +0400 Subject: [PATCH 08/34] Test --- iguana/exchanges/LP_remember.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 086528f03..447f577cb 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -900,7 +900,12 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,rswap.src) != 0 || strcmp(rswap.alicecoin,rswap.dest) != 0 ) { //printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest); - return(cJSON_Parse("{\"error\":\"mismatched bob/alice vs src/dest coins??\"}")); + cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"error","swap never started"); + jaddnum(retjson,"requestid",requestid); + jaddnum(retjson,"quoteid",quoteid); + return(retjson); + //return(cJSON_Parse("{\"error\":\"mismatched bob/alice vs src/dest coins??\"}")); } alice = LP_coinfind(rswap.alicecoin); bob = LP_coinfind(rswap.bobcoin); From 17e0e1b89e3e4a5d25e21b4ef07149af1eb7513b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 12:16:48 +0400 Subject: [PATCH 09/34] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_portfolio.c | 160 +++++++++++++++++++------------- iguana/exchanges/LP_remember.c | 2 +- 4 files changed, 98 insertions(+), 67 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index bdc0060f5..dd87341eb 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -321,7 +321,7 @@ instantdex_claim()\n\ double price,bid,ask; if ( strcmp(method,"autoprice") == 0 ) { - if ( LP_autoprice(base,rel,argjson) < 0 ) + if ( LP_autoprice(ctx,base,rel,argjson) < 0 ) return(clonestr("{\"error\":\"couldnt set autoprice\"}")); else return(clonestr("{\"result\":\"success\"}")); } diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 82b3a29ce..57616a77b 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -517,6 +517,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_numpeers(); +double LP_CMCbtcprice(double *price_usdp,char *symbol); char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid,int32_t forceflag); int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance); int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index cf11dbe17..68d5d82cd 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -18,6 +18,14 @@ // marketmaker // + +struct LP_autoprice_ref +{ + char refbase[65],refrel[65],base[65],rel[65]; + double margin; +} LP_autorefs[100]; + +int32_t LP_autoprices,num_LP_autorefs; char LP_portfolio_base[128],LP_portfolio_rel[128]; double LP_portfolio_relvolume; @@ -201,13 +209,6 @@ char *LP_portfolio_goal(char *symbol,double goal) } else return(clonestr("{\"error\":\"cant set goal for inactive coin\"}")); } -int32_t LP_autoprices,num_LP_autorefs; - -struct LP_autoprice_ref -{ - char refbase[65],refrel[65],base[65],rel[65]; -} LP_autorefs[100]; - /*int32_t LP_autofill(char *base,char *rel,double maxprice,double totalrelvolume) { struct LP_priceinfo *basepp,*relpp; @@ -221,58 +222,6 @@ struct LP_autoprice_ref return(-1); }*/ -int32_t LP_autoprice(char *base,char *rel,cJSON *argjson) -{ - //curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}" - struct LP_priceinfo *basepp,*relpp; int32_t i; char *refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; - //printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0)); - if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) - { - if ( jobj(argjson,"minprice") != 0 ) - minprice = jdouble(argjson,"minprice"); - else minprice = 0.; - margin = jdouble(argjson,"margin"); - offset = jdouble(argjson,"offset"); - factor = jdouble(argjson,"factor"); - fixedprice = jdouble(argjson,"fixed"); - basepp->fixedprices[relpp->ind] = fixedprice; - basepp->minprices[relpp->ind] = minprice; - basepp->margins[relpp->ind] = margin; - basepp->offsets[relpp->ind] = offset; - basepp->factors[relpp->ind] = factor; - if ( fixedprice > SMALLVAL || ((refbase= jstr(argjson,"refbase")) != 0 && (refrel= jstr(argjson,"refrel")) != 0) ) - { - if ( fixedprice > SMALLVAL ) - { - refbase = base; - refrel = rel; - } - for (i=0; ifixedprices[basepp->ind],basepp->fixedprices[relpp->ind]); - LP_autopriceset(ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel); + rel = LP_autorefs[i].rel; + base = LP_autorefs[i].base; + margin = LP_autorefs[i].margin; + printf("%s/%s for %s/%s margin %.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,margin); + if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL ) + { + if ( strcmp(rel,"KMD") == 0 ) + price = price_btc / kmd_btc; + else if ( strcmp(rel,"BTC") == 0 ) + price = price_btc; + else continue; + newprice = (price * (1. + margin)); + LP_mypriceset(&changed,rel,base,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); + printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin)); + newprice = (1. / price) * (1. + margin); + LP_mypriceset(&changed,base,rel,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); + } } + else + { + basepp = LP_priceinfofind(LP_autorefs[i].base); + relpp = LP_priceinfofind(LP_autorefs[i].rel); + if ( basepp != 0 && relpp != 0 ) + { + //printf("check ref-autoprice %s/%s %f %f\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel,relpp->fixedprices[basepp->ind],basepp->fixedprices[relpp->ind]); + LP_autopriceset(ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel); + } + } + } +} + +int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) +{ + //curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}" + struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; + //printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0)); + if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) + { + if ( jobj(argjson,"minprice") != 0 ) + minprice = jdouble(argjson,"minprice"); + else minprice = 0.; + margin = jdouble(argjson,"margin"); + offset = jdouble(argjson,"offset"); + factor = jdouble(argjson,"factor"); + fixedprice = jdouble(argjson,"fixed"); + basepp->fixedprices[relpp->ind] = fixedprice; + basepp->minprices[relpp->ind] = minprice; + basepp->margins[relpp->ind] = margin; + basepp->offsets[relpp->ind] = offset; + basepp->factors[relpp->ind] = factor; + if ( fixedprice > SMALLVAL || ((refbase= jstr(argjson,"refbase")) != 0 && (refrel= jstr(argjson,"refrel")) != 0) ) + { + if ( fixedprice > SMALLVAL ) + { + refbase = base; + refrel = rel; + } + for (i=0; i Date: Sat, 9 Dec 2017 12:21:24 +0400 Subject: [PATCH 10/34] Test --- iguana/exchanges/LP_portfolio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 68d5d82cd..2b8aae9d7 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -444,11 +444,11 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) else continue; newprice = (price * (1. + margin)); LP_mypriceset(&changed,rel,base,newprice); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin)); newprice = (1. / price) * (1. + margin); LP_mypriceset(&changed,base,rel,newprice); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); } } else From f3570cba116dacf68eaf307e24cb3b3bc1e78457 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 12:33:39 +0400 Subject: [PATCH 11/34] Test --- iguana/exchanges/LP_portfolio.c | 14 +++++++++++--- iguana/exchanges/LP_prices.c | 4 ++-- iguana/exchanges/auto_chipsbtc | 2 ++ iguana/exchanges/auto_chipskmd | 2 ++ iguana/exchanges/install | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) create mode 100755 iguana/exchanges/auto_chipsbtc create mode 100755 iguana/exchanges/auto_chipskmd diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 2b8aae9d7..cea19a4bb 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -22,7 +22,7 @@ struct LP_autoprice_ref { char refbase[65],refrel[65],base[65],rel[65]; - double margin; + double margin,factor,offset; } LP_autorefs[100]; int32_t LP_autoprices,num_LP_autorefs; @@ -367,7 +367,7 @@ double LP_pricesparse(void *ctx,int32_t trexflag,char *retstr,struct LP_priceinf void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) { - char *retstr,*base,*rel; cJSON *retjson,*bid,*ask; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double nxtkmd,price,newprice,margin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp; + char *retstr,*base,*rel; cJSON *retjson,*bid,*ask; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double nxtkmd,price,factor,offset,newprice,margin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp; if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 ) { printf("trex error getting marketsummaries\n"); @@ -434,6 +434,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) rel = LP_autorefs[i].rel; base = LP_autorefs[i].base; margin = LP_autorefs[i].margin; + offset = LP_autorefs[i].offset; + factor = LP_autorefs[i].factor; printf("%s/%s for %s/%s margin %.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,margin); if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL ) { @@ -442,6 +444,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) else if ( strcmp(rel,"BTC") == 0 ) price = price_btc; else continue; + if ( factor > 0. ) + price = (price * factor) + offset; newprice = (price * (1. + margin)); LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); @@ -495,6 +499,8 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) if ( strcmp(base,LP_autorefs[i].base) == 0 && strcmp(rel,LP_autorefs[i].rel) == 0 ) { LP_autorefs[i].margin = margin; + LP_autorefs[i].factor = factor; + LP_autorefs[i].offset = offset; safecopy(LP_autorefs[i].refbase,refbase,sizeof(LP_autorefs[i].refbase)); safecopy(LP_autorefs[i].refrel,refrel,sizeof(LP_autorefs[i].refrel)); printf("%d Update ref %s/%s for %s/%s factor %.8f offset %.8f\n",i,refbase,refrel,base,rel,factor,offset); @@ -504,6 +510,8 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) if ( i == num_LP_autorefs && num_LP_autorefs < sizeof(LP_autorefs)/sizeof(*LP_autorefs) ) { LP_autorefs[num_LP_autorefs].margin = margin; + LP_autorefs[num_LP_autorefs].factor = factor; + LP_autorefs[num_LP_autorefs].offset = offset; safecopy(LP_autorefs[num_LP_autorefs].refbase,refbase,sizeof(LP_autorefs[num_LP_autorefs].refbase)); safecopy(LP_autorefs[num_LP_autorefs].refrel,refrel,sizeof(LP_autorefs[num_LP_autorefs].refrel)); safecopy(LP_autorefs[num_LP_autorefs].base,base,sizeof(LP_autorefs[num_LP_autorefs].base)); @@ -515,7 +523,7 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) LP_autoprices++; retval = 0; } - LP_autoprice_iter(ctx,LP_priceinfofind("BTC")); + //LP_autoprice_iter(ctx,LP_priceinfofind("BTC")); return(retval); } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 9c8c7f204..7744ed1a6 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -915,8 +915,8 @@ int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance) KMDvalue = balance; else { - price = LP_price(coin->symbol,"KMD"); - KMDvalue = price * balance; + if ( (price= LP_price(coin->symbol,"KMD")) > SMALLVAL ) + KMDvalue = price * balance; } } return(KMDvalue); diff --git a/iguana/exchanges/auto_chipsbtc b/iguana/exchanges/auto_chipsbtc new file mode 100755 index 000000000..c45fffe5d --- /dev/null +++ b/iguana/exchanges/auto_chipsbtc @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"BTC\",\"margin\":0.01,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}" diff --git a/iguana/exchanges/auto_chipskmd b/iguana/exchanges/auto_chipskmd new file mode 100755 index 000000000..10f7874c0 --- /dev/null +++ b/iguana/exchanges/auto_chipskmd @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"KMD\",\"margin\":0.01,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}" diff --git a/iguana/exchanges/install b/iguana/exchanges/install index c891b0d7f..cbf46ca5f 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,5 +1,5 @@ #!/bin/bash -cp pendingswaps fundvalue balances dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts +cp auto_chipskmd auto_chipsbtc pendingswaps fundvalue balances dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts cp coins.json .. cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . From 578cff2c6eb74178f327f973ecbc568c11670115 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 12:41:53 +0400 Subject: [PATCH 12/34] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_portfolio.c | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5e320beff..f6fb7ded6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,7 @@ // LP_nativeDEX.c // marketmaker // -// fundvalue -> autoprice, cmc +margin -> autoprice, signals -> autoprice +// fundvalue -> autoprice, signals -> autoprice // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // // compress packets diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index cea19a4bb..3bbc44932 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -18,6 +18,7 @@ // marketmaker // +struct LP_portfoliotrade { double metric; char buycoin[65],sellcoin[65]; }; struct LP_autoprice_ref { @@ -436,11 +437,11 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) margin = LP_autorefs[i].margin; offset = LP_autorefs[i].offset; factor = LP_autorefs[i].factor; - printf("%s/%s for %s/%s margin %.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,margin); + //printf("%s/%s for %s/%s margin %.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,margin); if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL ) { if ( strcmp(rel,"KMD") == 0 ) - price = price_btc / kmd_btc; + price = kmd_btc / price_btc; else if ( strcmp(rel,"BTC") == 0 ) price = price_btc; else continue; @@ -449,7 +450,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) newprice = (price * (1. + margin)); LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); - printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin)); + //printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin)); newprice = (1. / price) * (1. + margin); LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); @@ -596,8 +597,6 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str else return(-1); } -struct LP_portfoliotrade { double metric; char buycoin[65],sellcoin[65]; }; - int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *array) { int32_t i,j,m,n = 0; cJSON *item; struct LP_portfoliotrade coins[256]; From d6d1cecf6a556b02600ca50f45b3a1daa6e2041b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 12:49:33 +0400 Subject: [PATCH 13/34] Test --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 3bbc44932..dd096cbe7 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -441,7 +441,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL ) { if ( strcmp(rel,"KMD") == 0 ) - price = kmd_btc / price_btc; + price = price_btc / kmd_btc; else if ( strcmp(rel,"BTC") == 0 ) price = price_btc; else continue; From 9ed61c997c8186bfa2b15b7d34bede0a44437b1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 12:53:51 +0400 Subject: [PATCH 14/34] Test --- iguana/exchanges/LP_portfolio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index dd096cbe7..a47148f01 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -441,7 +441,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL ) { if ( strcmp(rel,"KMD") == 0 ) - price = price_btc / kmd_btc; + price = kmd_btc / price_btc; else if ( strcmp(rel,"BTC") == 0 ) price = price_btc; else continue; @@ -450,7 +450,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) newprice = (price * (1. + margin)); LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); - //printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin)); + printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin)); newprice = (1. / price) * (1. + margin); LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); From 2a936045e05d57a33dda8dfdad07332b8573d9a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 12:56:52 +0400 Subject: [PATCH 15/34] Test --- iguana/exchanges/LP_portfolio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index a47148f01..09ce7e220 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -449,11 +449,11 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) price = (price * factor) + offset; newprice = (price * (1. + margin)); LP_mypriceset(&changed,rel,base,newprice); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin)); newprice = (1. / price) * (1. + margin); LP_mypriceset(&changed,base,rel,newprice); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); } } else From 6cb8256e21f94e0b90f84d1934593db510829c7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 13:01:01 +0400 Subject: [PATCH 16/34] Test --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 09ce7e220..63cd8d45d 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -443,7 +443,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( strcmp(rel,"KMD") == 0 ) price = kmd_btc / price_btc; else if ( strcmp(rel,"BTC") == 0 ) - price = price_btc; + price = 1. / price_btc; else continue; if ( factor > 0. ) price = (price * factor) + offset; From 08c0aabbc4f6b4e0a668d7bb4e9b4462db1b6815 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 16:06:57 +0400 Subject: [PATCH 17/34] Finished for alicepayment not sent and bob refund --- iguana/exchanges/LP_portfolio.c | 8 ++++++-- iguana/exchanges/LP_prices.c | 6 ++++-- iguana/exchanges/LP_remember.c | 9 +++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 63cd8d45d..f149a5e1c 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -24,6 +24,7 @@ struct LP_autoprice_ref { char refbase[65],refrel[65],base[65],rel[65]; double margin,factor,offset; + cJSON *fundvalue; } LP_autorefs[100]; int32_t LP_autoprices,num_LP_autorefs; @@ -472,7 +473,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) { //curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}" - struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; + struct LP_priceinfo *basepp,*relpp; int32_t i,isfundvalue,retval = -1; char *refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; //printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0)); if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) { @@ -488,7 +489,10 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) basepp->margins[relpp->ind] = margin; basepp->offsets[relpp->ind] = offset; basepp->factors[relpp->ind] = factor; - if ( fixedprice > SMALLVAL || ((refbase= jstr(argjson,"refbase")) != 0 && (refrel= jstr(argjson,"refrel")) != 0) ) + refbase = jstr(argjson,"refbase"); + refrel = jstr(argjson,"refrel"); + isfundvalue = jint(argjson,"fundvalue"); + if ( isfundvalue != 0 || fixedprice > SMALLVAL || (refbase != 0 && refrel != 0) ) { if ( fixedprice > SMALLVAL ) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 7744ed1a6..98d8ee157 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -1140,7 +1140,7 @@ double LP_CMCbtcprice(double *price_usdp,char *symbol) cJSON *LP_fundvalue(cJSON *argjson) { - cJSON *holdings,*item,*newitem,*array,*retjson; int32_t i,iter,n; double usdprice,divisor,btcprice,balance,btcsum,KMDholdings,numKMD; struct iguana_info *coin; char *symbol,*coinaddr; int64_t fundvalue,KMDvalue = 0; + cJSON *holdings,*item,*newitem,*array,*retjson; int32_t i,iter,n,missing=0; double usdprice,divisor,btcprice,balance,btcsum,KMDholdings,numKMD; struct iguana_info *coin; char *symbol,*coinaddr; int64_t fundvalue,KMDvalue = 0; fundvalue = 0; KMDholdings = btcsum = 0.; array = cJSON_CreateArray(); @@ -1180,11 +1180,13 @@ cJSON *LP_fundvalue(cJSON *argjson) } else jaddstr(newitem,"error","no price source"); jaddi(array,newitem); - } + } else missing++; } } } retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jaddnum(retjson,"missing",missing); jadd(retjson,"holdings",array); btcprice = LP_CMCbtcprice(&usdprice,"komodo"); divisor = jdouble(argjson,"divisor"); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 18f3310e5..f8aac6b49 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -380,8 +380,13 @@ int32_t basilisk_swap_isfinished(int32_t iambob,bits256 *txids,int32_t *sentflag } else { - if ( bits256_nonz(txids[BASILISK_ALICEPAYMENT]) == 0 && sentflags[BASILISK_ALICEPAYMENT] == 0 ) - return(1); + if ( sentflags[BASILISK_ALICEPAYMENT] == 0 ) + { + if ( bits256_nonz(txids[BASILISK_ALICEPAYMENT]) == 0 ) + return(1); + else if ( sentflags[BASILISK_BOBPAYMENT] != 0 && sentflags[BASILISK_BOBREFUND] != 0 ) + return(1); + } else { if ( sentflags[BASILISK_ALICERECLAIM] != 0 || sentflags[BASILISK_ALICESPEND] != 0 ) From 54ebf26d6dbb6e616312d4b54e22e81c8130fdce Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 16:52:28 +0400 Subject: [PATCH 18/34] Test --- iguana/exchanges/LP_instantdex.c | 1 + iguana/exchanges/LP_portfolio.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index e744a3c0b..76172fdfc 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -509,6 +509,7 @@ int64_t LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num) { bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr); bitcoin_address(othersmartaddr,0,60,rmd160,20); + printf("proofcheck addrtype.%d (%s) -> %s\n",addrtype,coinaddr,othersmartaddr); if ((ap= LP_address(coin,othersmartaddr)) != 0 ) { ap->instantdex_credits = 0; diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index f149a5e1c..d217a4116 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -473,7 +473,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) { //curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}" - struct LP_priceinfo *basepp,*relpp; int32_t i,isfundvalue,retval = -1; char *refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; + struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *fundvalue_bid,*fundvalue_ask,*refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; //printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0)); if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) { @@ -491,8 +491,9 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) basepp->factors[relpp->ind] = factor; refbase = jstr(argjson,"refbase"); refrel = jstr(argjson,"refrel"); - isfundvalue = jint(argjson,"fundvalue"); - if ( isfundvalue != 0 || fixedprice > SMALLVAL || (refbase != 0 && refrel != 0) ) + fundvalue_bid = jstr(argjson,"fundvalue_bid"); + fundvalue_ask = jstr(argjson,"fundvalue_ask"); + if ( fundvalue_bid != 0 || fundvalue_ask != 0 || fixedprice > SMALLVAL || (refbase != 0 && refrel != 0) ) { if ( fixedprice > SMALLVAL ) { From 3453615d70648ab25be9b5084f79281c528eaa26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 17:25:11 +0400 Subject: [PATCH 19/34] Test --- iguana/exchanges/LP_instantdex.c | 41 ++++++++++++++++++++------------ iguana/exchanges/LP_ordermatch.c | 5 ++-- iguana/exchanges/LP_portfolio.c | 13 ++++++++-- iguana/exchanges/LP_signatures.c | 7 ++++-- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 76172fdfc..2e41e26f7 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -19,16 +19,24 @@ // marketmaker // -void LP_instantdex_txidaddfname(char *fname,char *afname) +void LP_instantdex_txidaddfname(char *fname,char *afname,char *coinaddr) { - sprintf(fname,"%s/instantdex.json",GLOBAL_DBDIR); - sprintf(afname,"%s/instantdex_append.json",GLOBAL_DBDIR); + if ( coinaddr == 0 || coinaddr[0] == 0 ) + { + sprintf(fname,"%s/instantdex.json",GLOBAL_DBDIR); + sprintf(afname,"%s/instantdex_append.json",GLOBAL_DBDIR); + } + else + { + sprintf(fname,"%s/instantdex_%s.json",GLOBAL_DBDIR,coinaddr); + sprintf(afname,"%s/instantdex_%s_append.json",GLOBAL_DBDIR,coinaddr); + } } -cJSON *LP_instantdex_txids(int32_t appendonly) +cJSON *LP_instantdex_txids(int32_t appendonly,char *coinaddr) { char *filestr,fname[1024],afname[1024]; long fsize; cJSON *retjson=0; - LP_instantdex_txidaddfname(fname,afname); + LP_instantdex_txidaddfname(fname,afname,coinaddr); if ( (filestr= OS_filestr(&fsize,appendonly != 0 ? afname : fname)) != 0 ) { retjson = cJSON_Parse(filestr); @@ -37,10 +45,10 @@ cJSON *LP_instantdex_txids(int32_t appendonly) return(retjson); } -void LP_instantdex_filewrite(int32_t appendfile,cJSON *array) +void LP_instantdex_filewrite(int32_t appendfile,cJSON *array,char *coinaddr) { FILE *fp; char *filestr,fname[1024],afname[1024]; - LP_instantdex_txidaddfname(fname,afname); + LP_instantdex_txidaddfname(fname,afname,coinaddr); if ( (fp= fopen(appendfile == 0 ? fname : afname,"wb")) != 0 ) { filestr = jprint(array,0); @@ -96,9 +104,9 @@ void LP_instantdex_filescreate(char *coinaddr) jaddibits256(newarray,txid); } fclose(fp); - LP_instantdex_filewrite(0,newarray); + LP_instantdex_filewrite(0,newarray,coinaddr); free_json(newarray); - LP_instantdex_filewrite(1,array); + LP_instantdex_filewrite(1,array,coinaddr); free_json(array); } } @@ -106,16 +114,19 @@ void LP_instantdex_filescreate(char *coinaddr) void LP_instantdex_depositadd(char *coinaddr,bits256 txid) { static FILE *depositsfp; - char fname[512],str[65]; bits256 prevtxid; cJSON *array,*txobj; int32_t i,n,iter; + char fname[512],str[65],*addr; bits256 prevtxid; cJSON *array,*txobj; int32_t i,n,iter; if ( depositsfp == 0 ) { sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname); if ( (depositsfp= fopen(fname,"rb+")) == 0 ) { depositsfp = fopen(fname,"wb+"); - for (iter=0; iter<2; iter++) + for (iter=0; iter<4; iter++) { - if ( (array= LP_instantdex_txids(iter)) != 0 ) + if ( iter < 2 ) + addr = coinaddr; + else addr = ""; + if ( (array= LP_instantdex_txids(iter&1,addr)) != 0 ) { if ( (n= cJSON_GetArraySize(array)) > 0 ) { @@ -350,7 +361,7 @@ char *LP_instantdex_claim(struct iguana_info *coin) sum = 0; txids = cJSON_CreateArray(); newarray = cJSON_CreateArray(); - if ( (array= LP_instantdex_txids(firsttime)) != 0 ) + if ( (array= LP_instantdex_txids(firsttime,coin->smartaddr)) != 0 ) { printf("claiming from.(%s)\n",jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) @@ -367,7 +378,7 @@ char *LP_instantdex_claim(struct iguana_info *coin) } firsttime = 0; if ( cJSON_GetArraySize(newarray) > 0 ) - LP_instantdex_filewrite(0,newarray); + LP_instantdex_filewrite(0,newarray,coin->smartaddr); free_json(newarray); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); @@ -539,7 +550,7 @@ int64_t LP_myzcredits() cJSON *proof; struct iguana_info *coin; int64_t zcredits; if ( (coin= LP_coinfind("KMD")) != 0 ) { - if ( (proof= LP_instantdex_txids(0)) != 0 ) + if ( (proof= LP_instantdex_txids(0,coin->smartaddr)) != 0 ) { zcredits = LP_instantdex_proofcheck(coin->smartaddr,proof,cJSON_GetArraySize(proof)); free_json(proof); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5acc571a5..86cb812e4 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -444,7 +444,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double price,struct LP_quoteinfo *qp) { - char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin; + char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin,*kmdcoin; qp->quotetime = (uint32_t)time(NULL); if ( (coin= LP_coinfind(qp->srccoin)) == 0 ) { @@ -475,7 +475,8 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double reqjson = LP_quotejson(qp); jaddstr(reqjson,"method","connected"); jaddstr(reqjson,"pair",pairstr); - jadd(reqjson,"proof",LP_instantdex_txids(0)); + if ( (kmdcoin= LP_coinfind("KMD")) != 0 ) + jadd(reqjson,"proof",LP_instantdex_txids(0,kmdcoin->smartaddr)); char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,qp->desthash)); bits256 zero; memset(zero.bytes,0,sizeof(zero)); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index d217a4116..31511dc45 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -22,7 +22,7 @@ struct LP_portfoliotrade { double metric; char buycoin[65],sellcoin[65]; }; struct LP_autoprice_ref { - char refbase[65],refrel[65],base[65],rel[65]; + char refbase[65],refrel[65],base[65],rel[65],fundbid[16],fundask[16]; double margin,factor,offset; cJSON *fundvalue; } LP_autorefs[100]; @@ -473,7 +473,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) { //curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}" - struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *fundvalue_bid,*fundvalue_ask,*refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; + struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *fundvalue_bid,*fundvalue_ask,*refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; cJSON *fundvalue; //printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0)); if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) { @@ -504,6 +504,15 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) { if ( strcmp(base,LP_autorefs[i].base) == 0 && strcmp(rel,LP_autorefs[i].rel) == 0 ) { + if ( fundvalue_bid != 0 || fundvalue_ask != 0 ) + { + fundvalue = jduplicate(argjson); + jdelete(fundvalue,"method"); + jaddstr(fundvalue,"method","fundvalue"); + LP_autorefs[i].fundvalue = fundvalue; + safecopy(LP_autorefs[i].fundbid,fundvalue_bid,sizeof(LP_autorefs[i].fundbid)); + safecopy(LP_autorefs[i].fundask,fundvalue_ask,sizeof(LP_autorefs[i].fundask)); + } LP_autorefs[i].margin = margin; LP_autorefs[i].factor = factor; LP_autorefs[i].offset = offset; diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 74cf86fee..668551325 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -643,7 +643,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr) void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; + cJSON *reqjson; bits256 zero; char *msg; struct iguana_info *coin; int32_t flag = 0; if ( strcmp(method,"request") == 0 ) { if ( LP_allocated(qp->desttxid,qp->destvout) == 0 && LP_allocated(qp->feetxid,qp->feevout) == 0 ) @@ -665,7 +665,10 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ if ( jobj(reqjson,"timestamp") == 0 ) jaddnum(reqjson,"timestamp",time(NULL)); if ( strcmp(method,"connect") == 0 ) - jadd(reqjson,"proof",LP_instantdex_txids(0)); + { + if ( (coin= LP_coinfind("KMD")) != 0 ) + jadd(reqjson,"proof",LP_instantdex_txids(0,coin->smartaddr)); + } msg = jprint(reqjson,1); printf("QUERY.(%s)\n",msg); //if ( bits256_nonz(qp->srchash) == 0 || strcmp(method,"request") != 0 ) From ee4eb459a6632df2cc5e1742470d8500e04eeae4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 17:49:49 +0400 Subject: [PATCH 20/34] Test --- iguana/exchanges/LP_portfolio.c | 51 +++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 31511dc45..e57bd8371 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -369,7 +369,7 @@ double LP_pricesparse(void *ctx,int32_t trexflag,char *retstr,struct LP_priceinf void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) { - char *retstr,*base,*rel; cJSON *retjson,*bid,*ask; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double nxtkmd,price,factor,offset,newprice,margin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp; + char *retstr,*base,*rel; cJSON *retjson,*bid,*ask,*fundjson,*argjson; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double nxtkmd,price,factor,offset,newprice,margin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp; if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 ) { printf("trex error getting marketsummaries\n"); @@ -431,13 +431,37 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) kmd_btc = LP_CMCbtcprice(&kmd_usd,"komodo"); for (i=0; i SMALLVAL ) + { + newprice = (1. / price) * (1. + margin); + LP_mypriceset(&changed,base,rel,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); + printf("fundbid %.8f margin %.8f newprice %.8f\n",price,margin,newprice); + } + if ( LP_autorefs[i].fundask[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundask)) > SMALLVAL ) + { + newprice = (price * (1. + margin)); + LP_mypriceset(&changed,rel,base,price); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); + printf("fundask %.8f margin %.8f newprice %.8f\n",price,margin,newprice); + } + } + free_json(fundjson); + } + } + else if ( strcmp(LP_autorefs[i].refrel,"coinmarketcap") == 0 ) { - rel = LP_autorefs[i].rel; - base = LP_autorefs[i].base; - margin = LP_autorefs[i].margin; - offset = LP_autorefs[i].offset; - factor = LP_autorefs[i].factor; //printf("%s/%s for %s/%s margin %.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,margin); if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL ) { @@ -459,8 +483,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) } else { - basepp = LP_priceinfofind(LP_autorefs[i].base); - relpp = LP_priceinfofind(LP_autorefs[i].rel); + basepp = LP_priceinfofind(base); + relpp = LP_priceinfofind(rel); if ( basepp != 0 && relpp != 0 ) { //printf("check ref-autoprice %s/%s %f %f\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel,relpp->fixedprices[basepp->ind],basepp->fixedprices[relpp->ind]); @@ -524,6 +548,15 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) } if ( i == num_LP_autorefs && num_LP_autorefs < sizeof(LP_autorefs)/sizeof(*LP_autorefs) ) { + if ( fundvalue_bid != 0 || fundvalue_ask != 0 ) + { + fundvalue = jduplicate(argjson); + jdelete(fundvalue,"method"); + jaddstr(fundvalue,"method","fundvalue"); + LP_autorefs[num_LP_autorefs].fundvalue = fundvalue; + safecopy(LP_autorefs[num_LP_autorefs].fundbid,fundvalue_bid,sizeof(LP_autorefs[num_LP_autorefs].fundbid)); + safecopy(LP_autorefs[num_LP_autorefs].fundask,fundvalue_ask,sizeof(LP_autorefs[num_LP_autorefs].fundask)); + } LP_autorefs[num_LP_autorefs].margin = margin; LP_autorefs[num_LP_autorefs].factor = factor; LP_autorefs[num_LP_autorefs].offset = offset; From 60c9c512283df94a6060a832db8cf292b03d4a91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 17:57:18 +0400 Subject: [PATCH 21/34] Test --- iguana/exchanges/LP_privkey.c | 21 +-------------------- iguana/exchanges/LP_statemachine.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 0d5a515dd..7f519adfd 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -321,26 +321,6 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) printf("waiting for G.waiting\n"); sleep(5); } - /*for (iambob=0; iambob<2; iambob++) - { - if ( G.LP_utxoinfos[iambob] != 0 ) - { - HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) - { - HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo); - //free(utxo); - } - } - if ( G.LP_utxoinfos2[iambob] != 0 ) - { - G.LP_utxoinfos2[iambob] = 0; - //HASH_ITER(hh,G.LP_utxoinfos2[iambob],utxo,tmp) - //{ - // HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo); - // free(utxo); - //} - } - }*/ memset(&G,0,sizeof(G)); LP_privkey_updates(ctx,LP_mypubsock,passphrase); init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); @@ -350,6 +330,7 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) G.initializing = 0; bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20); memset(zero.bytes,0,sizeof(zero)); + printf("passphrase init: call depositadd.(%s)\n",coinaddr); LP_instantdex_depositadd(coinaddr,zero); return(0); } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index d467958ec..be1d7701d 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -490,6 +490,28 @@ void LP_instantdex_txidadd(bits256 txid) return((double)destsatoshis / satoshis); else return(0.); }*/ + +/*for (iambob=0; iambob<2; iambob++) + { + if ( G.LP_utxoinfos[iambob] != 0 ) + { + HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) + { + HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo); + //free(utxo); + } + } + if ( G.LP_utxoinfos2[iambob] != 0 ) + { + G.LP_utxoinfos2[iambob] = 0; + //HASH_ITER(hh,G.LP_utxoinfos2[iambob],utxo,tmp) + //{ + // HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo); + // free(utxo); + //} + } + }*/ + char *issue_LP_getprices(char *destip,uint16_t destport) { char url[512]; From 0a97eed5d739b00196d7da2574f9b6c0bb5c8601 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 18:17:06 +0400 Subject: [PATCH 22/34] Test --- iguana/exchanges/LP_portfolio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index e57bd8371..dd5c9de7c 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -445,15 +445,15 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( LP_autorefs[i].fundbid[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundbid)) > SMALLVAL ) { newprice = (1. / price) * (1. + margin); - LP_mypriceset(&changed,base,rel,newprice); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); + LP_mypriceset(&changed,rel,base,newprice); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); printf("fundbid %.8f margin %.8f newprice %.8f\n",price,margin,newprice); } if ( LP_autorefs[i].fundask[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundask)) > SMALLVAL ) { newprice = (price * (1. + margin)); - LP_mypriceset(&changed,rel,base,price); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); + LP_mypriceset(&changed,base,rel,price); + LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); printf("fundask %.8f margin %.8f newprice %.8f\n",price,margin,newprice); } } From 600def863fb9406db4879f06d52a2207cf3c0be4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 18:22:22 +0400 Subject: [PATCH 23/34] Test --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index dd5c9de7c..2f6ce9f37 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -452,7 +452,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( LP_autorefs[i].fundask[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundask)) > SMALLVAL ) { newprice = (price * (1. + margin)); - LP_mypriceset(&changed,base,rel,price); + LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); printf("fundask %.8f margin %.8f newprice %.8f\n",price,margin,newprice); } From 5e31422486fc90800caeb1b3e2924fd6999a8f14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 18:46:46 +0400 Subject: [PATCH 24/34] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_portfolio.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f6fb7ded6..c30d15ab9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,8 @@ // LP_nativeDEX.c // marketmaker // -// fundvalue -> autoprice, signals -> autoprice +// signals -> autoprice +// passphrase for deposits // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // // compress packets diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 2f6ce9f37..4c1a53ca2 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -447,14 +447,14 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) newprice = (1. / price) * (1. + margin); LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); - printf("fundbid %.8f margin %.8f newprice %.8f\n",price,margin,newprice); + //printf("fundbid %.8f margin %.8f newprice %.8f\n",price,margin,newprice); } if ( LP_autorefs[i].fundask[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundask)) > SMALLVAL ) { newprice = (price * (1. + margin)); LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); - printf("fundask %.8f margin %.8f newprice %.8f\n",price,margin,newprice); + //printf("fundask %.8f margin %.8f newprice %.8f\n",price,margin,newprice); } } free_json(fundjson); From 685f8240f09ae7185abb7dae44e5b96aa7d0c110 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 20:39:30 +0400 Subject: [PATCH 25/34] Test --- iguana/exchanges/LP_commands.c | 4 +++- iguana/exchanges/LP_nativeDEX.c | 7 ++++--- iguana/exchanges/LP_privkey.c | 6 +----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index dd87341eb..9c4b4fa2f 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -184,7 +184,7 @@ instantdex_claim()\n\ jdelete(argjson,"userpass"); if ( strcmp(method,"passphrase") == 0 ) { - char coinaddr[64]; + char coinaddr[64]; bits256 zero; G.USERPASS_COUNTER = 1; if ( LP_passphrase_init(jstr(argjson,"passphrase"),jstr(argjson,"gui")) < 0 ) return(clonestr("{\"error\":\"couldnt change passphrase\"}")); @@ -195,6 +195,8 @@ instantdex_claim()\n\ jaddbits256(retjson,"mypubkey",G.LP_mypub25519); bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20); jaddstr(retjson,"KMD",coinaddr); + memset(zero.bytes,0,sizeof(zero)); + LP_instantdex_depositadd(coinaddr,zero); bitcoin_address(coinaddr,0,0,G.LP_myrmd160,20); jaddstr(retjson,"BTC",coinaddr); jaddstr(retjson,"NXT",G.LP_NXTaddr); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c30d15ab9..214f953dc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,21 +17,22 @@ // LP_nativeDEX.c // marketmaker // +// ordermatch pricing error // signals -> autoprice // passphrase for deposits // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG -// // compress packets // portfolio to set prices from historical // portfolio value based on ask? -// // else claim path +// +// WONTFIX: // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs // improve critical section detection when parallel trades // use electrum in case of addr change in swap // locktime claiming on sporadic assetchains -// there is an issue about waiting for notarization for a swap that never starts +// there is an issue about waiting for notarization for a swap that never starts (expiration ok) #include diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 7f519adfd..baca4e6e4 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -307,7 +307,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) int32_t LP_passphrase_init(char *passphrase,char *gui) { - static void *ctx; char coinaddr[64]; bits256 zero; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp; + static void *ctx; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( G.LP_pendingswaps != 0 ) @@ -328,10 +328,6 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) safecopy(G.gui,gui,sizeof(G.gui)); G.USERPASS_COUNTER = counter; G.initializing = 0; - bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20); - memset(zero.bytes,0,sizeof(zero)); - printf("passphrase init: call depositadd.(%s)\n",coinaddr); - LP_instantdex_depositadd(coinaddr,zero); return(0); } From 1f610b501573d16c6b5f9c671698cd738ab38347 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 20:46:24 +0400 Subject: [PATCH 26/34] Test --- iguana/exchanges/LP_nativeDEX.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 214f953dc..e8c51fa0c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1160,9 +1160,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu exit(-1); } LP_initcoins(ctx,pubsock,coinsjson); - G.waiting = 1; LP_passphrase_init(passphrase,jstr(argjson,"gui")); + char coinaddr[64]; bits256 zero; + bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20); + memset(zero.bytes,0,sizeof(zero)); + LP_instantdex_depositadd(coinaddr,zero); #ifndef FROM_JS if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) { From eefb5e2aa2cbe9901e4acb63b4174d25c694e5f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 21:01:56 +0400 Subject: [PATCH 27/34] Test --- iguana/exchanges/LP_coins.c | 4 +++- iguana/exchanges/LP_commands.c | 4 +--- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_instantdex.c | 4 ++-- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 211852c11..b62e2b7b1 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -214,7 +214,7 @@ uint16_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot, cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) { - struct electrum_info *ep; int32_t notarized; uint64_t balance; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); + struct electrum_info *ep; bits256 zero; int32_t notarized; uint64_t balance; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); jaddstr(item,"coin",coin->symbol); if ( showwif != 0 ) { @@ -261,6 +261,8 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) jaddnum(item,"txfee",strcmp(coin->symbol,"BTC") != 0 ? coin->txfee : LP_txfeecalc(coin,0,0)); if ( strcmp(coin->symbol,"KMD") == 0 ) { + memset(zero.bytes,0,sizeof(zero)); + LP_instantdex_depositadd(coin->smartaddr,zero); jaddnum(item,"zcredits",dstr(LP_myzcredits())); jadd(item,"zdebits",LP_myzdebits()); } diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9c4b4fa2f..dd87341eb 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -184,7 +184,7 @@ instantdex_claim()\n\ jdelete(argjson,"userpass"); if ( strcmp(method,"passphrase") == 0 ) { - char coinaddr[64]; bits256 zero; + char coinaddr[64]; G.USERPASS_COUNTER = 1; if ( LP_passphrase_init(jstr(argjson,"passphrase"),jstr(argjson,"gui")) < 0 ) return(clonestr("{\"error\":\"couldnt change passphrase\"}")); @@ -195,8 +195,6 @@ instantdex_claim()\n\ jaddbits256(retjson,"mypubkey",G.LP_mypub25519); bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20); jaddstr(retjson,"KMD",coinaddr); - memset(zero.bytes,0,sizeof(zero)); - LP_instantdex_depositadd(coinaddr,zero); bitcoin_address(coinaddr,0,0,G.LP_myrmd160,20); jaddstr(retjson,"BTC",coinaddr); jaddstr(retjson,"NXT",G.LP_NXTaddr); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 57616a77b..cf9beab63 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -506,6 +506,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ //void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo); struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout); int64_t LP_myzcredits(); +void LP_instantdex_depositadd(char *coinaddr,bits256 txid); int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel); diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 2e41e26f7..bbd84bd0e 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -68,7 +68,7 @@ void LP_instantdex_deposituniq(FILE *fp,bits256 txid) fread(&prevtxid,1,sizeof(prevtxid),fp); if ( bits256_cmp(prevtxid,txid) == 0 ) { - printf("%s duplicate of deposits[%d]\n",bits256_str(str,prevtxid),i); + //printf("%s duplicate of deposits[%d]\n",bits256_str(str,prevtxid),i); break; } } @@ -133,7 +133,7 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid) for (i=0; i Date: Sat, 9 Dec 2017 21:08:10 +0400 Subject: [PATCH 28/34] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_instantdex.c | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index cf9beab63..ccddae1a5 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -507,6 +507,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout); int64_t LP_myzcredits(); void LP_instantdex_depositadd(char *coinaddr,bits256 txid); +int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr); int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel); diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index bbd84bd0e..32694fd0f 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -114,7 +114,8 @@ void LP_instantdex_filescreate(char *coinaddr) void LP_instantdex_depositadd(char *coinaddr,bits256 txid) { static FILE *depositsfp; - char fname[512],str[65],*addr; bits256 prevtxid; cJSON *array,*txobj; int32_t i,n,iter; + struct iguana_info *coin; char fname[512],*addr; bits256 prevtxid; cJSON *array; int32_t i,n,iter; + coin = LP_coinfind("KMD"); if ( depositsfp == 0 ) { sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname); @@ -126,7 +127,7 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid) if ( iter < 2 ) addr = coinaddr; else addr = ""; - if ( (array= LP_instantdex_txids(iter&1,addr)) != 0 ) + if ( coin != 0 && (array= LP_instantdex_txids(iter&1,addr)) != 0 ) { if ( (n= cJSON_GetArraySize(array)) > 0 ) { @@ -134,15 +135,11 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid) { prevtxid = jbits256i(array,i); //printf("instantdex iter.%d i.%d check %s\n",iter,i,bits256_str(str,prevtxid)); - if ( (txobj= LP_gettxout("KMD",coinaddr,prevtxid,0)) != 0 ) - free_json(txobj); - else + if ( LP_instantdex_creditcalc(coin,0,prevtxid,coinaddr) > 0 ) { - printf("null gettxout %s %s\n",coinaddr,bits256_str(str,prevtxid)); - continue; + LP_instantdex_deposituniq(depositsfp,prevtxid); + fflush(depositsfp); } - LP_instantdex_deposituniq(depositsfp,prevtxid); - fflush(depositsfp); } } free_json(array); From fff619435a172bee02015b64c1fb471b90a89b11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 21:30:54 +0400 Subject: [PATCH 29/34] Test --- iguana/exchanges/LP_instantdex.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 32694fd0f..4d8002491 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -113,15 +113,13 @@ void LP_instantdex_filescreate(char *coinaddr) void LP_instantdex_depositadd(char *coinaddr,bits256 txid) { - static FILE *depositsfp; - struct iguana_info *coin; char fname[512],*addr; bits256 prevtxid; cJSON *array; int32_t i,n,iter; + FILE *fp; struct iguana_info *coin; char fname[512],*addr; bits256 prevtxid; cJSON *array; int32_t i,n,iter; coin = LP_coinfind("KMD"); - if ( depositsfp == 0 ) + sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname); + if ( (fp= fopen(fname,"rb+")) == 0 ) { - sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname); - if ( (depositsfp= fopen(fname,"rb+")) == 0 ) + if ( (fp= fopen(fname,"wb+")) != 0 ) { - depositsfp = fopen(fname,"wb+"); for (iter=0; iter<4; iter++) { if ( iter < 2 ) @@ -134,23 +132,23 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid) for (i=0; i 0 ) { - LP_instantdex_deposituniq(depositsfp,prevtxid); - fflush(depositsfp); + LP_instantdex_deposituniq(fp,prevtxid); + fflush(fp); } } } free_json(array); } } - } else fseek(depositsfp,0,SEEK_END); - } - if ( depositsfp != 0 && bits256_nonz(txid) != 0 ) + } + } else fseek(fp,0,SEEK_END); + if ( fp != 0 && bits256_nonz(txid) != 0 ) { - LP_instantdex_deposituniq(depositsfp,txid); - fflush(depositsfp); + LP_instantdex_deposituniq(fp,txid); + fclose(fp); } LP_instantdex_filescreate(coinaddr); } From 8cce3577420b37cfef310ab9a8b555e09a0ff3e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 9 Dec 2017 22:11:44 +0400 Subject: [PATCH 30/34] Test --- iguana/exchanges/LP_coins.c | 6 +++++- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index b62e2b7b1..ae66c3701 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -262,7 +262,11 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) if ( strcmp(coin->symbol,"KMD") == 0 ) { memset(zero.bytes,0,sizeof(zero)); - LP_instantdex_depositadd(coin->smartaddr,zero); + if ( strcmp(coin->smartaddr,coin->instantdex_address) != 0 ) + { + LP_instantdex_depositadd(coin->smartaddr,zero); + strcpy(coin->instantdex_address,coin->smartaddr); + } jaddnum(item,"zcredits",dstr(LP_myzcredits())); jadd(item,"zdebits",LP_myzdebits()); } diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index ccddae1a5..a82c40340 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -294,7 +294,7 @@ struct iguana_info int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; uint32_t dPoWtime,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms; - char symbol[128],smartaddr[64],userpass[1024],serverport[128]; + char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64]; // portfolio double price_kmd,force,perc,goal,goalperc,relvolume,rate; void *electrum; void *ctx; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1e67d4ac1..b3fe04ddf 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,7 +19,6 @@ // // ordermatch pricing error // signals -> autoprice -// passphrase for deposits // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // compress packets // portfolio to set prices from historical From b7b919216d0d953d7af12de9d6dd1f67f605c998 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 10 Dec 2017 09:18:58 +0400 Subject: [PATCH 31/34] Test --- iguana/exchanges/LP_instantdex.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 1 - iguana/exchanges/LP_remember.c | 4 ++++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 4d8002491..dae35bfb6 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -132,7 +132,7 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid) for (i=0; i 0 ) { LP_instantdex_deposituniq(fp,prevtxid); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b3fe04ddf..4fc1bacd4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -18,7 +18,6 @@ // marketmaker // // ordermatch pricing error -// signals -> autoprice // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // compress packets // portfolio to set prices from historical diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index f8aac6b49..24a04a6bf 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -923,6 +923,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti bitcoin_address(otheraddr,alice->taddr,alice->pubtype,rswap.other33,33); destBdest = otheraddr; destAdest = rswap.Adestaddr; + if ( strcmp(alice->smartaddr,rswap.Adestaddr) != 0 ) + printf("this isnt my swap! alice.(%s vs %s)\n",alice->smartaddr,rswap.Adestaddr); } if ( (bob= LP_coinfind(rswap.bobcoin)) != 0 ) { @@ -938,6 +940,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti bitcoin_address(otheraddr,bob->taddr,bob->pubtype,rswap.other33,33); srcAdest = otheraddr; srcBdest = rswap.destaddr; + if ( strcmp(bob->smartaddr,rswap.destaddr) != 0 ) + printf("this isnt my swap! bob.(%s vs %s)\n",bob->smartaddr,rswap.destaddr); } if ( (alice= LP_coinfind(rswap.alicecoin)) != 0 ) { From ae1a4a3c6aca7088f5ec782fb4ccb240db62ae5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 10 Dec 2017 09:19:27 +0400 Subject: [PATCH 32/34] Test --- iguana/exchanges/LP_instantdex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index dae35bfb6..4d8002491 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -132,7 +132,7 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid) for (i=0; i 0 ) { LP_instantdex_deposituniq(fp,prevtxid); From 1ba599c109aebaa2aa4ae76b31ab4ea6bf89af45 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 10 Dec 2017 09:22:29 +0400 Subject: [PATCH 33/34] Test --- iguana/exchanges/LP_remember.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 24a04a6bf..988d47ba8 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -924,7 +924,14 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti destBdest = otheraddr; destAdest = rswap.Adestaddr; if ( strcmp(alice->smartaddr,rswap.Adestaddr) != 0 ) + { printf("this isnt my swap! alice.(%s vs %s)\n",alice->smartaddr,rswap.Adestaddr); + cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"error","swap for different account"); + jaddnum(retjson,"requestid",requestid); + jaddnum(retjson,"quoteid",quoteid); + return(retjson); + } } if ( (bob= LP_coinfind(rswap.bobcoin)) != 0 ) { @@ -941,7 +948,14 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti srcAdest = otheraddr; srcBdest = rswap.destaddr; if ( strcmp(bob->smartaddr,rswap.destaddr) != 0 ) + { printf("this isnt my swap! bob.(%s vs %s)\n",bob->smartaddr,rswap.destaddr); + cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"error","swap for different account"); + jaddnum(retjson,"requestid",requestid); + jaddnum(retjson,"quoteid",quoteid); + return(retjson); + } } if ( (alice= LP_coinfind(rswap.alicecoin)) != 0 ) { From 5de6f432934dea58f5488823edf514c42d2e8dcc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 10 Dec 2017 10:44:12 +0400 Subject: [PATCH 34/34] LP_tradebot_pauseall(); LP_portfolio_reset(); LP_priceinfos_clear(); --- iguana/exchanges/LP_include.h | 2 ++ iguana/exchanges/LP_portfolio.c | 33 +++++++++++++++++++++++++++++++++ iguana/exchanges/LP_prices.c | 16 +++++++++++++++- iguana/exchanges/LP_privkey.c | 3 +++ iguana/exchanges/LP_tradebots.c | 9 +++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index a82c40340..5c009d2cd 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -530,6 +530,8 @@ cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout); void LP_postutxos(char *symbol,char *coinaddr); int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag); uint16_t LP_randpeer(char *destip); +void LP_tradebot_pauseall(); +void LP_portfolio_reset(); uint32_t LP_atomic_locktime(char *base,char *rel); struct LP_pubkey_info *LP_pubkeyfind(bits256 pubkey); char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 4c1a53ca2..9561bf1f3 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -31,6 +31,39 @@ int32_t LP_autoprices,num_LP_autorefs; char LP_portfolio_base[128],LP_portfolio_rel[128]; double LP_portfolio_relvolume; +void LP_portfolio_reset() +{ + struct iguana_info *coin,*tmp; cJSON *fundjson; int32_t i; struct LP_autoprice_ref *ptr; + for (i=0; ifundvalue) != 0 ) + { + ptr->fundvalue = 0; + free_json(fundjson); + } + } + memset(LP_autorefs,0,sizeof(LP_autorefs)); + LP_autoprices = 0; + num_LP_autorefs = 0; + strcpy(LP_portfolio_base,""); + strcpy(LP_portfolio_rel,""); + LP_portfolio_relvolume = 0.; + HASH_ITER(hh,LP_coins,coin,tmp) + { + coin->maxamount = 0; + coin->perc = 0; + coin->goal = 0; + coin->goalperc = 0; + coin->relvolume = 0; + coin->force = 0; + coin->balanceA = 0; + coin->valuesumA = 0; + coin->balanceB = 0; + coin->valuesumB = 0; + } +} + cJSON *LP_portfolio_entry(struct iguana_info *coin) { cJSON *item = cJSON_CreateObject(); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 98d8ee157..51597b46c 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -33,7 +33,7 @@ struct LP_priceinfo char symbol[68]; uint64_t coinbits; int32_t ind,pad; - double diagval,high[2],low[2],last[2],bid[2],ask[2]; //volume,btcvolume,prevday; // mostly bittrex info + double diagval,high[2],low[2],last[2],bid[2],ask[2]; double relvals[LP_MAXPRICEINFOS]; double myprices[LP_MAXPRICEINFOS]; double minprices[LP_MAXPRICEINFOS]; // autoprice @@ -53,6 +53,20 @@ struct LP_cacheinfo uint32_t timestamp; } *LP_cacheinfos; +void LP_priceinfos_clear() +{ + int32_t i; struct LP_priceinfo *pp; + for (i=0; imyprices,0,sizeof(pp->myprices)); + memset(pp->minprices,0,sizeof(pp->minprices)); + memset(pp->fixedprices,0,sizeof(pp->fixedprices)); + memset(pp->margins,0,sizeof(pp->margins)); + memset(pp->offsets,0,sizeof(pp->offsets)); + memset(pp->factors,0,sizeof(pp->factors)); + } +} float LP_pubkey_price(int32_t *numutxosp,int64_t *avesatoshisp,int64_t *maxsatoshisp,struct LP_pubkey_info *pubp,uint32_t baseind,uint32_t relind) { diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index baca4e6e4..db3659602 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -326,6 +326,9 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); G.LP_sessionid = (uint32_t)time(NULL); safecopy(G.gui,gui,sizeof(G.gui)); + LP_tradebot_pauseall(); + LP_portfolio_reset(); + LP_priceinfos_clear(); G.USERPASS_COUNTER = counter; G.initializing = 0; return(0); diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index c5f0d7d6f..39526c2be 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -40,6 +40,15 @@ struct LP_tradebot struct LP_tradebot_trade *trades[LP_TRADEBOTS_MAXTRADES]; } *LP_tradebots; +void LP_tradebot_pauseall() +{ + struct LP_tradebot *bot,*tmp; + DL_FOREACH_SAFE(LP_tradebots,bot,tmp) + { + bot->userpause = bot->pause = (uint32_t)time(NULL); + } +} + void LP_tradebot_updatestats(struct LP_tradebot *bot,struct LP_tradebot_trade *tp) { char *swapstr,*status; int32_t flag; cJSON *swapjson;