Browse Source

Test

etomic
jl777 8 years ago
parent
commit
1f3dd68af8
  1. 42
      iguana/exchanges/LP_commands.c
  2. 2
      iguana/exchanges/LP_include.h
  3. 153
      iguana/exchanges/LP_nativeDEX.c
  4. 2
      iguana/exchanges/LP_peers.c
  5. 146
      iguana/exchanges/LP_prices.c
  6. 8
      iguana/exchanges/LP_rpc.c
  7. 10
      iguana/exchanges/LP_utxos.c

42
iguana/exchanges/LP_commands.c

@ -167,8 +167,8 @@ char *LP_connected(cJSON *argjson) // alice
int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin)
{
char *method,*base,*rel,*retstr; cJSON *retjson; double price; bits256 txid,spendtxid; struct LP_utxoinfo *utxo; int32_t selector,spendvini,retval = -1; struct LP_quoteinfo Q;
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 || strcmp(method,"price") == 0 || strcmp(method,"connect") == 0) )
char *method,*base,*rel,*retstr; cJSON *retjson; double price,bid,ask; bits256 txid,spendtxid; struct LP_utxoinfo *utxo; int32_t selector,spendvini,retval = -1; struct LP_quoteinfo Q;
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) )
{
retval = 1;
txid = jbits256(argjson,"txid");
@ -183,12 +183,12 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d
}
if ( utxo->S.swap == 0 && time(NULL) > utxo->T.swappending )
utxo->T.swappending = 0;
if ( strcmp(method,"price") == 0 || strcmp(method,"request") == 0 ) // bob
if ( strcmp(method,"request") == 0 ) // bob
{
retval = 1;
if ( LP_isavailable(utxo) > 0 )
{
if ( (price= LP_price(base,rel)) > SMALLVAL )
if ( (price= LP_myprice(&bid,&ask,base,rel)) > SMALLVAL )
{
price *= (1. + profitmargin);
if ( LP_quoteinfoinit(&Q,utxo,rel,price) < 0 )
@ -198,20 +198,15 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d
printf("not eligible\n");
return(-1);
}
if ( strcmp(method,"price") == 0 )
Q.timestamp = (uint32_t)time(NULL);
Q.timestamp = (uint32_t)time(NULL);
retjson = LP_quotejson(&Q);
utxo->S.otherpubkey = jbits256(argjson,"desthash");
if ( strcmp(method,"request") == 0 )
{
retval |= 2;
LP_unavailableset(utxo,jbits256(argjson,"desthash"));
jaddnum(retjson,"quotetime",juint(argjson,"quotetime"));
jaddnum(retjson,"pending",utxo->T.swappending);
jaddbits256(retjson,"desthash",utxo->S.otherpubkey);
jaddstr(retjson,"method","reserved");
}
else jaddstr(retjson,"method","quote");
retval |= 2;
LP_unavailableset(utxo,jbits256(argjson,"desthash"));
jaddnum(retjson,"quotetime",juint(argjson,"quotetime"));
jaddnum(retjson,"pending",utxo->T.swappending);
jaddbits256(retjson,"desthash",utxo->S.otherpubkey);
jaddstr(retjson,"method","reserved");
retstr = jprint(retjson,1);
if ( pubsock >= 0 )
LP_send(pubsock,retstr,1);
@ -264,6 +259,7 @@ getutxos()\n\
getutxos(coin, lastn)\n\
orderbook(base, rel)\n\
getprice(base, rel)\n\
getprices(base, rel)\n\
register(pubkey,pushaddr)\n\
lookup(pubkey)\n\
forward(pubkey,method2,<argjson>)\n\
@ -271,6 +267,8 @@ forward(pubkey,method2=publish,<argjson>)\n\
forwardhex(pubkey,hex)\n\
\"}"));
//printf("CMD.(%s)\n",jprint(argjson,0));
base = jstr(argjson,"base");
rel = jstr(argjson,"rel");
if ( USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 )
{
if ( USERPASS_COUNTER == 0 )
@ -284,7 +282,7 @@ forwardhex(pubkey,hex)\n\
}
if ( (userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,USERPASS) != 0 )
return(clonestr("{\"error\":\"authentication error\"}"));
if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 )
if ( base != 0 && rel != 0 )
{
double price;
if ( LP_isdisabled(base,rel) != 0 )
@ -367,7 +365,7 @@ forwardhex(pubkey,hex)\n\
else return(basilisk_swaplist());
}
}
if ( LP_isdisabled(jstr(argjson,"base"),jstr(argjson,"base")) != 0 )
if ( LP_isdisabled(base,rel) != 0 )
return(clonestr("{\"error\":\"at least one of coins disabled\"}"));
if ( LP_isdisabled(jstr(argjson,"coin"),0) != 0 )
return(clonestr("{\"error\":\"coin is disabled\"}"));
@ -392,7 +390,7 @@ forwardhex(pubkey,hex)\n\
} else LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,argport,pushport,subport,jdouble(argjson,"profit"),jint(argjson,"numpeers"),jint(argjson,"numutxos"));
}
}
if ( strcmp(method,"quote") == 0 || strcmp(method,"reserved") == 0 )
if ( strcmp(method,"reserved") == 0 )
retstr = LP_quotereceived(argjson);
else if ( strcmp(method,"connected") == 0 )
retstr = LP_connected(argjson);
@ -405,9 +403,11 @@ forwardhex(pubkey,hex)\n\
else if ( strcmp(method,"broadcast") == 0 )
retstr = LP_broadcasted(argjson);
else if ( strcmp(method,"getprice") == 0 )
retstr = LP_pricestr(jstr(argjson,"base"),jstr(argjson,"rel"),0.);
retstr = LP_pricestr(base,rel,0.);
else if ( strcmp(method,"getprices") == 0 )
retstr = LP_prices();
else if ( strcmp(method,"orderbook") == 0 )
retstr = LP_orderbook(jstr(argjson,"base"),jstr(argjson,"rel"));
retstr = LP_orderbook(base,rel);
else if ( strcmp(method,"forward") == 0 )
{
cJSON *reqjson;

2
iguana/exchanges/LP_include.h

@ -177,7 +177,7 @@ struct LP_peerinfo
UT_hash_handle hh;
uint64_t ip_port;
double profitmargin;
uint32_t ipbits,errortime,errors,numpeers,numutxos,lasttime,connected,lastutxos,lastpeers;
uint32_t ipbits,errortime,errors,numpeers,numutxos,lasttime,connected,lastutxos,lastpeers,diduquery;
int32_t pushsock,subsock;
uint16_t port;
char ipaddr[64];

153
iguana/exchanges/LP_nativeDEX.c

@ -190,9 +190,9 @@ void LP_utxo_spentcheck(int32_t pubsock,struct LP_utxoinfo *utxo,double profitma
}
}
void LP_utxo_updates(int32_t pubsock,char *passphrase,double profitmargin)
void LP_myutxo_updates(int32_t pubsock,char *passphrase,double profitmargin)
{
//LP_utxopurge(0);
//LP_utxopurge(0); not good to disrupt existing pointers
LP_privkey_updates(pubsock,passphrase);
}
@ -212,9 +212,60 @@ void LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubso
} //else printf("LP_peer_utxosquery skip.(%s) %u\n",peer->ipaddr,peer->lastutxos);
}
int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin)
{
static uint32_t counter,lastforward,numpeers;
struct LP_utxoinfo *utxo,*utmp; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t n,nonz = 0;
now = (uint32_t)time(NULL);
//printf("start peers updates\n");
n = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
//printf("updatepeer.%s lag.%d\n",peer->ipaddr,now-peer->lastpeers);
if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) )
{
peer->lastpeers = now;
if ( peer->numpeers != numpeers )
printf("%s num.%d vs %d\n",peer->ipaddr,peer->numpeers,numpeers);
if ( strcmp(peer->ipaddr,mypeer->ipaddr) != 0 )
LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1",myport,profitmargin);
}
nonz += LP_subsock_check(peer);
if ( peer->diduquery == 0 )
{
LP_peer_utxosquery(LP_mypeer,myport,pubsock,peer,now,profitmargin,60);
LP_peer_pricesquery(peer->ipaddr,peer->port);
peer->diduquery = now;
}
}
numpeers = n;
if ( lastforward < now-3600 )
{
LP_forwarding_register(LP_mypubkey,pushaddr,10);
lastforward = now;
}
if ( (counter % 600) == 0 )
LP_myutxo_updates(pubsock,passphrase,profitmargin);
if ( (counter % 600) == 0 )
{
HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp)
{
LP_utxo_spentcheck(pubsock,utxo,profitmargin);
}
HASH_ITER(hh,LP_utxoinfos[1],utxo,utmp)
{
LP_utxo_spentcheck(pubsock,utxo,profitmargin);
}
}
if ( pullsock >= 0 )
nonz += LP_pullsock_check(myipaddr,pubsock,pullsock,profitmargin);
counter++;
return(nonz);
}
void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,char *pushaddr,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin,cJSON *coins,char *seednode)
{
char *retstr; uint8_t r; int32_t i,n,j,counter=0,nonz; struct LP_peerinfo *peer,*tmp; uint32_t now,lastforward = 0; cJSON *item; struct LP_utxoinfo *utxo,*utmp;
char *retstr; uint8_t r; int32_t i,n,j; cJSON *item;
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
@ -258,103 +309,13 @@ void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,in
LP_priceinfoadd(jstr(item,"coin"));
}
}
printf("update utxos\n");
LP_privkey_updates(pubsock,passphrase);
printf("update swaps\n");
if ( (retstr= basilisk_swaplist()) != 0 )
free(retstr);
printf("update peers\n");
printf("mainloop pushaddr.(%s)\n",pushaddr);
if ( IAMLP == 0 )
while ( 1 )
{
while ( 1 )
{
now = (uint32_t)time(NULL);
if ( lastforward < now-3600 )
{
//printf("LP_forwarding_register\n");
LP_forwarding_register(LP_mypubkey,pushaddr,10);
//printf("done LP_forwarding_register\n");
lastforward = now;
}
nonz = n = 0;
if ( (counter % 6000) == 0 )
{
//printf("LP_utxo_updates\n");
LP_utxo_updates(pubsock,passphrase,profitmargin);
}
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
nonz += LP_subsock_check(peer);
LP_peer_utxosquery(LP_mypeer,myport,pubsock,peer,now,profitmargin,600);
}
if ( pullsock >= 0 )
{
if ( (n= LP_pullsock_check(myipaddr,pubsock,pullsock,profitmargin)) > 0 )
{
nonz += n;
lastforward = now;
}
}
if ( nonz == 0 )
usleep(200000);
counter++;
}
}
else
{
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( strcmp(peer->ipaddr,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1") != 0 )
{
//printf("query utxo from %s\n",peer->ipaddr);
LP_utxosquery(mypeer,pubsock,peer->ipaddr,peer->port,"",100,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1",myport,profitmargin);
}
}
while ( 1 )
{
nonz = 0;
if ( (counter % 600) == 0 )
LP_utxo_updates(pubsock,passphrase,profitmargin);
now = (uint32_t)time(NULL);
if ( lastforward < now-3600 )
{
LP_forwarding_register(LP_mypubkey,pushaddr,10);
lastforward = now;
}
//printf("start peers updates\n");
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
//printf("updatepeer.%s lag.%d\n",peer->ipaddr,now-peer->lastpeers);
if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != mypeer->numpeers || (rand() % 10000) == 0) )
{
peer->lastpeers = now;
if ( peer->numpeers != mypeer->numpeers )
printf("%s num.%d vs %d\n",peer->ipaddr,peer->numpeers,mypeer->numpeers);
if ( strcmp(peer->ipaddr,mypeer->ipaddr) != 0 )
LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,mypeer->ipaddr,myport,profitmargin);
}
nonz += LP_subsock_check(peer);
LP_peer_utxosquery(LP_mypeer,myport,pubsock,peer,now,profitmargin,60);
}
if ( (counter % 100) == 0 )
{
HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp)
{
LP_utxo_spentcheck(pubsock,utxo,profitmargin);
}
HASH_ITER(hh,LP_utxoinfos[1],utxo,utmp)
{
LP_utxo_spentcheck(pubsock,utxo,profitmargin);
}
}
if ( pullsock >= 0 )
nonz += LP_pullsock_check(myipaddr,pubsock,pullsock,profitmargin);
if ( nonz == 0 )
usleep(100000);
counter++;
//printf("nonz.%d in mainloop\n",nonz);
}
if ( LP_mainloop_iter(myipaddr,mypeer,pubsock,pushaddr,pullsock,myport,passphrase,profitmargin) == 0 )
usleep(100000);
}
}

2
iguana/exchanges/LP_peers.c

@ -57,7 +57,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
{
if ( (peer= LP_peerfind(ipbits,port)) != 0 )
{
if ( peer->profitmargin == 0. )
if ( profitmargin != 0. )
peer->profitmargin = profitmargin;
if ( numpeers > peer->numpeers )
peer->numpeers = numpeers;

146
iguana/exchanges/LP_prices.c

@ -46,8 +46,38 @@ struct LP_pubkeyinfo
UT_hash_handle hh;
bits256 pubkey;
double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS];
uint32_t timestamp;
} *LP_pubkeyinfos;
struct LP_priceinfo *LP_priceinfofind(char *symbol)
{
int32_t i; struct LP_priceinfo *pp; uint64_t coinbits;
if ( LP_numpriceinfos > 0 )
{
coinbits = stringbits(symbol);
pp = LP_priceinfos;
for (i=0; i<LP_numpriceinfos; i++,pp++)
if ( pp->coinbits == coinbits )
return(pp);
}
return(0);
}
struct LP_priceinfo *LP_priceinfoptr(int32_t *indp,char *base,char *rel)
{
struct LP_priceinfo *basepp,*relpp;
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
*indp = relpp->ind;
return(basepp);
}
else
{
*indp = -1;
return(0);
}
}
int32_t LP_cachekey(uint8_t *key,char *base,char *rel,bits256 txid,int32_t vout)
{
uint64_t basebits,relbits; int32_t offset = 0;
@ -104,52 +134,102 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey)
return(pubp);
}
double LP_pricecache(struct LP_quoteinfo *qp,char *base,char *rel,bits256 txid,int32_t vout)
cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp)
{
struct LP_cacheinfo *ptr;
if ( (ptr= LP_cachefind(base,rel,txid,vout)) != 0 )
int32_t baseid,relid; char *base; double price; cJSON *item,*array,*obj;
obj = cJSON_CreateObject();
array = cJSON_CreateArray();
for (baseid=0; baseid<LP_numpriceinfos; baseid++)
{
if ( qp != 0 )
(*qp) = ptr->Q;
if ( ptr->price == 0. && ptr->Q.satoshis != 0 )
base = LP_priceinfos[baseid].symbol;
for (relid=0; relid<LP_numpriceinfos; relid++)
{
printf("LP_pricecache: null ptr->price? ");
ptr->price = (double)ptr->Q.destsatoshis / ptr->Q.satoshis;
if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL )
{
item = cJSON_CreateArray();
jaddistr(item,base);
jaddistr(item,LP_priceinfos[relid].symbol);
jaddinum(item,price);
jaddi(array,item);
}
}
//printf("found %s/%s %.8f\n",base,rel,ptr->price);
return(ptr->price);
}
//char str[65]; printf("cachemiss %s/%s %s/v%d\n",base,rel,bits256_str(str,txid),vout);
return(0.);
jaddbits256(obj,"pubkey",pubp->pubkey);
jaddnum(obj,"timestamp",pubp->timestamp);
jadd(obj,"asks",array);
return(obj);
}
struct LP_priceinfo *LP_priceinfofind(char *symbol)
char *LP_prices()
{
int32_t i; struct LP_priceinfo *pp; uint64_t coinbits;
if ( LP_numpriceinfos > 0 )
struct LP_pubkeyinfo *pubp,*tmp; cJSON *array = cJSON_CreateArray();
HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp)
{
coinbits = stringbits(symbol);
pp = LP_priceinfos;
for (i=0; i<LP_numpriceinfos; i++,pp++)
if ( pp->coinbits == coinbits )
return(pp);
jaddi(array,LP_pubkeyjson(pubp));
}
return(0);
return(jprint(array,1));
}
struct LP_priceinfo *LP_priceinfoptr(int32_t *indp,char *base,char *rel)
void LP_prices_parse(cJSON *obj)
{
struct LP_priceinfo *basepp,*relpp;
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; int32_t i,n,relid; char *base,*rel; double askprice;
pubkey = jbits256(obj,"pubkey");
if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
*indp = relpp->ind;
return(basepp);
if ( (timestamp= juint(obj,"timestamp")) > pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 )
{
pubp->timestamp = timestamp;
for (i=0; i<n; i++)
{
item = jitem(asks,i);
base = jstri(item,0);
rel = jstri(item,1);
askprice = jdoublei(item,2);
if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 )
{
char str[65]; printf("%s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice);
pubp->matrix[basepp->ind][relid] = askprice;
}
}
}
}
else
}
void LP_peer_pricesquery(char *destipaddr,uint16_t destport)
{
char *retstr; cJSON *array; int32_t i,n;
if ( (retstr= issue_LP_getprices(destipaddr,destport)) != 0 )
{
*indp = -1;
return(0);
if ( (array= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(array) && (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
LP_prices_parse(jitem(array,i));
}
free_json(array);
}
free(retstr);
}
}
double LP_pricecache(struct LP_quoteinfo *qp,char *base,char *rel,bits256 txid,int32_t vout)
{
struct LP_cacheinfo *ptr;
if ( (ptr= LP_cachefind(base,rel,txid,vout)) != 0 )
{
if ( qp != 0 )
(*qp) = ptr->Q;
if ( ptr->price == 0. && ptr->Q.satoshis != 0 )
{
printf("LP_pricecache: null ptr->price? ");
ptr->price = (double)ptr->Q.destsatoshis / ptr->Q.satoshis;
}
//printf("found %s/%s %.8f\n",base,rel,ptr->price);
return(ptr->price);
}
//char str[65]; printf("cachemiss %s/%s %s/v%d\n",base,rel,bits256_str(str,txid),vout);
return(0.);
}
void LP_priceinfoupdate(char *base,char *rel,double price)
@ -193,7 +273,7 @@ double LP_myprice(double *bidp,double *askp,char *base,char *rel)
int32_t LP_mypriceset(char *base,char *rel,double price)
{
struct LP_priceinfo *basepp,*relpp;
if ( price > SMALLVAL && (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
if ( base != 0 && rel != 0 && price > SMALLVAL && (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
basepp->myprices[relpp->ind] = price; // ask
relpp->myprices[basepp->ind] = (1. / price); // bid
@ -282,6 +362,8 @@ struct LP_priceinfo *LP_priceinfoadd(char *symbol)
struct LP_cacheinfo *LP_cacheadd(char *base,char *rel,bits256 txid,int32_t vout,double price,struct LP_quoteinfo *qp)
{
char str[65]; struct LP_cacheinfo *ptr=0;
if ( base == 0 || rel == 0 )
return(0);
if ( (ptr= LP_cachefind(base,rel,txid,vout)) == 0 )
{
ptr = calloc(1,sizeof(*ptr));
@ -523,8 +605,10 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
{
printf("PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey));
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
pubp->matrix[basepp->ind][relpp->ind] = price;
else printf("error creating pubkey entry\n");
pubp->timestamp = (uint32_t)time(NULL);
} else printf("error creating pubkey entry\n");
} else printf("error finding %s/%s %.8f\n",base,rel,price);
}

8
iguana/exchanges/LP_rpc.c

@ -89,6 +89,14 @@ char *issue_LP_lookup(char *destip,uint16_t destport,bits256 pubkey)
return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
char *issue_LP_getprices(char *destip,uint16_t destport)
{
char url[512];
sprintf(url,"http://%s:%u/api/stats/getprices",destip,destport);
//printf("getutxo.(%s)\n",url);
return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params)
{
char *retstr; cJSON *retjson = 0;

10
iguana/exchanges/LP_utxos.c

@ -203,8 +203,6 @@ int32_t LP_utxopurge(int32_t allutxos)
cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo)
{
struct _LP_utxoinfo u;
jaddstr(item,"method","notified");
jaddstr(item,"method2","notified");
jaddstr(item,"coin",utxo->coin);
jaddnum(item,"now",time(NULL));
jaddstr(item,"address",utxo->coinaddr);
@ -433,7 +431,7 @@ struct LP_utxoinfo *LP_utxoaddjson(int32_t iambob,int32_t pubsock,cJSON *argjson
return(LP_utxoadd(iambob,pubsock,jstr(argjson,"coin"),jbits256(argjson,"txid"),jint(argjson,"vout"),j64bits(argjson,"value"),jbits256(argjson,"txid2"),jint(argjson,"vout2"),j64bits(argjson,"value2"),jstr(argjson,"script"),jstr(argjson,"address"),jbits256(argjson,"pubkey"),jdouble(argjson,"profit")));
}
int32_t LP_utxosparse(int32_t mypubsock,char *destipaddr,uint16_t destport,char *retstr,uint32_t now)
int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t now)
{
struct LP_peerinfo *destpeer,*peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0; bits256 txid; struct LP_utxoinfo *utxo;
//printf("parse.(%s)\n",retstr);
@ -452,13 +450,13 @@ int32_t LP_utxosparse(int32_t mypubsock,char *destipaddr,uint16_t destport,char
subport = argport + 2;
argipbits = (uint32_t)calc_ipbits(argipaddr);
if ( (peer= LP_peerfind(argipbits,argport)) == 0 )
peer = LP_addpeer(LP_mypeer,mypubsock,argipaddr,argport,pushport,subport,jdouble(item,"profit"),jint(item,"numpeers"),jint(item,"numutxos"));
peer = LP_addpeer(0,-1,argipaddr,argport,pushport,subport,jdouble(item,"profit"),jint(item,"numpeers"),jint(item,"numutxos"));
}
if ( jobj(item,"txid") != 0 )
{
txid = jbits256(item,"txid");
//printf("parse.(%s)\n",jprint(item,0));
if ( (utxo= LP_utxoaddjson(1,mypubsock,item)) != 0 )
if ( (utxo= LP_utxoaddjson(1,-1,item)) != 0 )
utxo->T.lasttime = now;
}
}
@ -485,7 +483,7 @@ void LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr
if ( retstr != 0 )
{
now = (uint32_t)time(NULL);
LP_utxosparse(mypubsock,destipaddr,destport,retstr,now);
LP_utxosparse(destipaddr,destport,retstr,now);
//printf("got.(%s)\n",retstr);
free(retstr);
/*i = 0;

Loading…
Cancel
Save