diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 38c1169bb..37a18791c 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -532,6 +532,7 @@ void HashKeccak(uint8_t *hash,void *data,size_t len); void test_validate(struct iguana_info *coin,char *signedtx); void LP_instantdex_depositadd(char *coinaddr,bits256 txid); int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr,char *origcoinaddr); +char *LP_autofillbob(struct iguana_info *coin,uint64_t satoshis); void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid); int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3ac17cd92..a4ff4a9ba 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1000,7 +1000,7 @@ double LP_trades_pricevalidate(struct LP_quoteinfo *qp,struct iguana_info *coin, struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr) { int32_t voliters=10,priceiters=33; - double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[4096]; int32_t i,j,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos)); + double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; uint64_t satoshis; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[4096]; int32_t i,j,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos)); *newqp = *qp; qp = newqp; printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,qp->fill,qp->gtc); @@ -1135,6 +1135,15 @@ printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypu else if ( qp->fill != 0 || i == priceiters ) { printf("i.%d cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",i,(long long)qp->aliceid,qp->srccoin,qp->destcoin,dstr(LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee)),dstr(qp->destsatoshis)); + if ( qp->gtc != 0 && qp->fill != 0 && coin != 0 ) + { + satoshis = LP_basesatoshis(dstr(qp->destsatoshis),maxprice,qp->txfee,qp->desttxfee) + 3*txfee; + if ( (retstr= LP_autofillbob(coin,satoshis)) != 0 ) + { + printf("AUTOfill bob.(%s)\n",retstr); + free(retstr); + } + } return(0); } else diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 91e5f7f93..64ecc1540 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1990,6 +1990,43 @@ char *LP_autosplit(struct iguana_info *coin) return(clonestr("{\"error\":\"couldnt autosplit\"}")); } +char *LP_autofillbob(struct iguana_info *coin,uint64_t satoshis) +{ + char *retstr; cJSON *argjson,*withdrawjson,*outputs,*item; int64_t total,balance,txfee; + if ( coin->etomic[0] == 0 ) + { + if ( coin->electrum != 0 ) + balance = LP_unspents_load(coin->symbol,coin->smartaddr); + else balance = LP_RTsmartbalance(coin); + if ( (txfee= coin->txfee) == 0 ) // BTC + txfee = LP_txfeecalc(coin,0,500); + balance -= (txfee + 100000); + if ( balance < (satoshis<<2) ) + return(clonestr("{\"error\":\"couldnt autofill balance too small\"}")); + if ( balance > satoshis+3*txfee && balance >= (1000000 - (txfee + 100000)) ) + { + argjson = cJSON_CreateObject(); + outputs = cJSON_CreateArray(); + item = cJSON_CreateObject(); + jaddnum(item,coin->smartaddr,dstr(satoshis + txfee*3)); + jaddi(outputs,item); + item = cJSON_CreateObject(); + jaddnum(item,coin->smartaddr,dstr(LP_DEPOSITSATOSHIS(satoshis) + txfee*3)); + jaddi(outputs,item); + item = cJSON_CreateObject(); + jaddnum(item,coin->smartaddr,0.0001); + jaddi(outputs,item); + jadd(argjson,"outputs",outputs); + jaddnum(argjson,"broadcast",0); + jaddstr(argjson,"coin",coin->symbol); + retstr = LP_withdraw(coin,argjson); + free_json(argjson); + return(retstr); + } else return(clonestr("{\"error\":\"balance too small to autosplit, please make more deposits\"}")); + } + return(clonestr("{\"error\":\"couldnt autofill etomic needs separate support\"}")); +} + char *LP_movecoinbases(char *symbol) { static bits256 zero; bits256 utxotxid,txid; struct iguana_info *coin; cJSON *retjson,*outputs,*argjson,*txids,*unspents,*item,*gen,*output; int32_t i,n,utxovout; char *retstr,*hexstr;