jl777 7 years ago
parent
commit
b8a69ad98e
  1. 7
      iguana/exchanges/LP_ordermatch.c
  2. 30
      iguana/exchanges/LP_rpc.c
  3. 25
      iguana/exchanges/LP_socket.c

7
iguana/exchanges/LP_ordermatch.c

@ -880,7 +880,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q
struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui)
{
bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*array,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin;
bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin;
*ordermatchpricep = 0.;
*bestsatoshisp = *bestdestsatoshisp = 0;
basecoin = LP_coinfind(base);
@ -908,11 +908,12 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr
if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160));
if ( (array= electrum_address_listunspent(basecoin->symbol,basecoin->electrum,&array,coinaddr)) != 0 )
/*if ( (array= LP_listunspent(basecoin->symbol,coinaddr)) != 0 )
{
n = cJSON_GetArraySize(array);
free_json(array);
} else n = 0;
} else n = 0;*/
n = LP_listunspent_issue(basecoin->symbol,coinaddr);
if ( n > 1 )
{
//minvol = jdouble(item,"minvolume");

30
iguana/exchanges/LP_rpc.c

@ -313,7 +313,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid)
cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout)
{
char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value,val; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin;
char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin;
if ( symbol == 0 || symbol[0] == 0 )
return(cJSON_Parse("{\"error\":\"null symbol\"}"));
coin = LP_coinfind(symbol);
@ -351,7 +351,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout)
LP_swap_coinaddr(coin,coinaddr,&value,serialized,len,vout);
//printf("HEX.(%s) len.%d %s %.8f\n",hexstr+1,len,coinaddr,dstr(value));
free(hexstr);
if ( (array= LP_listunspent(coin->symbol,coinaddr)) != 0 )
if ( (array= electrum_address_listunspent(coin->symbol,0,&array,coinaddr)) != 0 )
{
//printf("array.(%s)\n",jprint(array,0));
if ( array != 0 && (n= cJSON_GetArraySize(array)) > 0 )
@ -359,20 +359,8 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout)
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( coin->electrum == 0 )
{
t = jbits256(item,"txid");
v = jint(item,"vout");
val = LP_value_extract(item,0);
}
else
{
t = jbits256(item,"tx_hash");
v = jint(item,"tx_pos");
val = j64bits(item,"value");
}
if ( value != val )
printf("LP_gettxout: value %llu != %llu\n",(long long)value,(long long)val);
t = jbits256(item,"tx_hash");
v = jint(item,"tx_pos");
if ( v == vout && bits256_cmp(t,txid) == 0 )
{
retjson = cJSON_CreateObject();
@ -392,6 +380,8 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout)
"version": 1,
"coinbase": false
}*/
if ( value != j64bits(item,"value") )
printf("LP_gettxout: value %llu != %llu\n",(long long)value,(long long)j64bits(item,"value"));
jaddnum(retjson,"value",dstr(value));
jaddbits256(retjson,"txid",t);
jaddnum(retjson,"vout",v);
@ -502,11 +492,11 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr)
} else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr));
}
void LP_listunspent_issue(char *symbol,char *coinaddr)
int32_t LP_listunspent_issue(char *symbol,char *coinaddr)
{
struct iguana_info *coin; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport;
struct iguana_info *coin; int32_t n = 0; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport;
if ( symbol == 0 || symbol[0] == 0 )
return;
return(0);
if ( (coin= LP_coinfind(symbol)) != 0 )
{
if ( coin->electrum != 0 )
@ -525,6 +515,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr)
}
if ( retjson != 0 )
{
n = cJSON_GetArraySize(retjson);
if ( electrum_process_array(coin,0,coinaddr,retjson) != 0 )
LP_postutxos(symbol,coinaddr); // might be good to not saturate
}
@ -534,6 +525,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr)
if ( retstr != 0 )
free(retstr);
}
return(n);
}
cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)

25
iguana/exchanges/LP_socket.c

@ -307,14 +307,29 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep)
int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep,char *coinaddr,cJSON *array)
{
int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx;
int32_t i,v,n,ht,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx;
if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
//printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n);
for (i=0; i<n; i++)
{
item = jitem(array,i);
txid = jbits256(item,"tx_hash");
if ( coin->electrum == 0 )
{
txid = jbits256(item,"txid");
v = jint(item,"vout");
value = LP_value_extract(item,0);
ht = LP_txheight(coin,txid);
}
else
{
txid = jbits256(item,"tx_hash");
v = jint(item,"tx_pos");
value = j64bits(item,"value");
ht = jint(item,"height");
}
if ( bits256_nonz(txid) == 0 )
continue;
if ( (tx= LP_transactionfind(coin,txid)) == 0 )
{
txobj = LP_transactioninit(coin,txid,0,0);
@ -325,12 +340,10 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep
{
if (tx->height <= 0 )
{
tx->height = jint(item,"height");
tx->height = ht;
//printf("%s %s >>>>>>>>>> set %s <- height %d\n",coin->symbol,coinaddr,bits256_str(str,txid),tx->height);
}
value = j64bits(item,"value");
v = jint(item,"tx_pos");
if ( jobj(item,"tx_pos") != 0 && jobj(item,"value") != 0 && v >= 0 && v < tx->numvouts )
if ( v >= 0 && v < tx->numvouts )
{
if ( tx->outpoints[v].value == 0 && value != tx->outpoints[v].value )
{

Loading…
Cancel
Save