@ -73,7 +73,7 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen)
coin - > rate = LP_getestimatedrate ( coin ) ;
if ( ( txfee = SATOSHIDEN * coin - > rate * txlen ) < = 10000 )
{
coin - > rate = - 1. ;
//coin->rate = -1.;
coin - > rate = _LP_getestimatedrate ( coin ) ;
if ( ( txfee = SATOSHIDEN * coin - > rate * txlen ) < = 10000 )
txfee = 10000 ;
@ -187,7 +187,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str
desttxfee = qp - > desttxfee ;
if ( qp - > satoshis ! = 0 )
qprice = ( ( double ) qp - > destsatoshis / ( qp - > satoshis - qp - > txfee ) ) ;
printf ( " qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f) \n " , qprice , dstr ( qp - > destsatoshis ) , dstr ( qp - > satoshis ) , dstr ( qp - > txfee ) , dstr ( qp - > desttxfee ) , dstr ( txfee ) , dstr ( desttxfee ) ) ;
//printf(" qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee));
if ( qp - > txfee < LP_REQUIRED_TXFEE * txfee | | qp - > desttxfee < LP_REQUIRED_TXFEE * desttxfee )
{
printf ( " error -14: txfee %.8f >= %.8f or desttxfee %.8f >= %.8f \n " , dstr ( qp - > txfee ) , dstr ( LP_REQUIRED_TXFEE * txfee ) , dstr ( qp - > desttxfee ) , dstr ( LP_REQUIRED_TXFEE * desttxfee ) ) ;
@ -307,7 +307,7 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a
}
if ( replacei > = 0 )
{
printf ( " REPLACE bestdist %.8f height %d with dist %.8f height %d \n " , dstr ( bestdist ) , bestup - > U . height , dstr ( utxos [ replacei ] - > U . value - targetval ) , utxos [ replacei ] - > U . height ) ;
//printf(" REPLACE bestdist %.8f height %d with dist %.8f height %d\n",dstr(bestdist),bestup->U.height,dstr(utxos[replacei]->U.value - targetval),utxos[replacei]->U.height);
return ( replacei ) ;
}
}
@ -443,8 +443,9 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
if ( targetval = = 0 | | mini < 0 )
break ;
}
} else printf ( " no %s %s utxos pass LP_address_utxo_ptrs filter %.8f %.8f \n " , coin - > symbol , coinaddr , dstr ( targetval ) , dstr ( targetval2 ) ) ;
} else printf ( " address_myutxopair couldnt find %s %s \n " , coin - > symbol , coinaddr ) ;
} //else printf("no %s %s utxos pass LP_address_utxo_ptrs filter %.8f %.8f\n",coin->symbol,coinaddr,dstr(targetval),dstr(targetval2));
}
printf ( " address_myutxopair couldnt find %s %s targets %.8f %.8f \n " , coin - > symbol , coinaddr , dstr ( targetval ) , dstr ( targetval2 ) ) ;
return ( 0 ) ;
}
@ -841,7 +842,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
double price = 0. , p = 0. , qprice , myprice , bestprice , range , bid , ask ; struct iguana_info * coin ; struct LP_utxoinfo A , B , * autxo , * butxo ; cJSON * reqjson ; char str [ 65 ] ; struct LP_address_utxo * utxos [ 1000 ] ; int32_t i , r , counter , max = ( int32_t ) ( sizeof ( utxos ) / sizeof ( * utxos ) ) ;
* newqp = * qp ;
qp = newqp ;
printf ( " bob %s received REQUEST.(%llu) \n " , bits256_str ( str , G . LP_mypub25519 ) , ( long long ) qp - > aliceid ) ;
//printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
if ( ( coin = LP_coinfind ( qp - > srccoin ) ) = = 0 )
return ( 0 ) ;
if ( ( myprice = LP_trades_bobprice ( & bid , & ask , qp ) ) = = 0. )
@ -864,7 +865,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
} else return ( 0 ) ;
if ( qprice > = myprice )
{
r = ( LP_rand ( ) % 100 ) ;
r = ( LP_rand ( ) % 90 ) + 10 ;
range = ( qprice - myprice ) ;
price = myprice + ( ( r * range ) / 100. ) ;
bestprice = LP_bob_competition ( & counter , qp - > aliceid , price , 0 ) ;
@ -887,7 +888,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
//LP_address_utxo_reset(coin);
//printf("done LP_address_utxo_reset.%s\n",coin->symbol);
i = 0 ;
while ( i < 100 & & price > = myprice )
while ( i < 33 & & price > = myprice )
{
if ( ( butxo = LP_address_myutxopair ( butxo , 1 , utxos , max , LP_coinfind ( qp - > srccoin ) , qp - > coinaddr , qp - > txfee , dstr ( qp - > destsatoshis ) , price , qp - > desttxfee ) ) ! = 0 )
{
@ -913,12 +914,13 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
return ( 0 ) ;
if ( p > = qprice )
break ;
price * = 0.99777 ;
price / = 0.99 ;
i + + ;
}
printf ( " i.%d qprice %.8f myprice %.8f price %.8f [%.8f] \n " , i , qprice , myprice , price , p ) ;
if ( LP_allocated ( qp - > txid , qp - > vout ) = = 0 & & LP_allocated ( qp - > txid2 , qp - > vout2 ) = = 0 )
{
printf ( " found unallocated txids \n " ) ;
reqjson = LP_quotejson ( qp ) ;
LP_unavailableset ( qp - > txid , qp - > vout , qp - > timestamp + LP_RESERVETIME , qp - > desthash ) ;
LP_unavailableset ( qp - > txid2 , qp - > vout2 , qp - > timestamp + LP_RESERVETIME , qp - > desthash ) ;
@ -927,12 +929,12 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
jaddnum ( reqjson , " quotetime " , qp - > quotetime ) ;
jaddnum ( reqjson , " pending " , qp - > timestamp + LP_RESERVETIME ) ;
jaddstr ( reqjson , " method " , " reserved " ) ;
//LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
LP_reserved_msg ( 1 , qp - > srccoin , qp - > destcoin , qp - > desthash , jprint ( reqjson , 0 ) ) ;
bits256 zero ;
memset ( zero . bytes , 0 , sizeof ( zero ) ) ;
LP_reserved_msg ( 1 , qp - > srccoin , qp - > destcoin , zero , jprint ( reqjson , 0 ) ) ;
free_json ( reqjson ) ;
//printf("Send RESERVED id.%llu\n",(long long)qp->aliceid);
printf ( " Send RESERVED id.%llu \n " , ( long long ) qp - > aliceid ) ;
return ( qp ) ;
} else printf ( " request processing selected ineligible utxos? \n " ) ;
return ( 0 ) ;
@ -940,12 +942,13 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
struct LP_quoteinfo * LP_trades_gotreserved ( void * ctx , struct LP_quoteinfo * qp , struct LP_quoteinfo * newqp )
{
char * retstr ;
//char str[65]; printf("alice %s received RESERVED.(%llu) %.8f\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,(double)qp->destsatoshis/(qp->satoshis+1));
char * retstr ; double qprice ;
char str [ 65 ] ; printf ( " alice %s received RESERVED.(%llu) %.8f \n " , bits256_str ( str , G . LP_mypub25519 ) , ( long long ) qp - > aliceid , ( double ) qp - > destsatoshis / ( qp - > satoshis + 1 ) ) ;
* newqp = * qp ;
qp = newqp ;
if ( LP_trades_alicevalidate ( ctx , qp ) > 0. )
if ( ( qprice = LP_trades_alicevalidate ( ctx , qp ) ) > 0. )
{
printf ( " got qprice %.8f \n " , qprice ) ;
LP_aliceid ( qp - > tradeid , qp - > aliceid , " reserved " , 0 , 0 ) ;
if ( ( retstr = LP_quotereceived ( qp ) ) ! = 0 )
free ( retstr ) ;
@ -1401,7 +1404,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
if ( destsatoshis < ( autxo - > payment . value / LP_MINCLIENTVOL ) | | autxo - > payment . value < desttxfee * LP_MINSIZE_TXFEEMULT )
{
printf ( " destsatoshis %.8f vs utxo %.8f this would have triggered an quote error -13 \n " , dstr ( destsatoshis ) , dstr ( autxo - > payment . value ) ) ;
return ( clonestr ( " { \" error \" : \" cant find a deposit that is close enough in size. make another deposit that is just a bit larger than what you want to trade \" } " ) ) ;
return ( clonestr ( " { \" error \" : \" cant find a deposit that is close enough in size. make another deposit that is a bit larger than what you want to trade \" } " ) ) ;
}
bestsatoshis = 1.001 * LP_basesatoshis ( dstr ( destsatoshis ) , maxprice , txfee , desttxfee ) ;
memset ( & B , 0 , sizeof ( B ) ) ;