Browse Source

Test

etomic
jl777 8 years ago
parent
commit
fe5b65e269
  1. 3
      iguana/exchanges/LP_commands.c
  2. 5
      iguana/exchanges/LP_include.h
  3. 37
      iguana/exchanges/LP_quotes.c
  4. 2
      iguana/exchanges/LP_rpc.c
  5. 32
      iguana/exchanges/LP_utxos.c

3
iguana/exchanges/LP_commands.c

@ -118,7 +118,6 @@ int32_t LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uin
utxo->mypub = LP_pubkey(privkey);
if ( bits256_nonz(privkey) != 0 && Q.quotetime >= Q.timestamp-3 && Q.quotetime < utxo->swappending && bits256_cmp(utxo->mypub,Q.srchash) == 0 && (destvalue= LP_txvalue(rel,Q.desttxid,Q.destvout)) >= price*Q.satoshis+Q.desttxfee && destvalue >= Q.destsatoshis+Q.desttxfee )
{
Q.change = destvalue - (Q.destsatoshis+Q.desttxfee);
nanomsg_tcpname(pairstr,mypeer->ipaddr,10000+(rand() % 10000));
if ( (utxo->pair= nn_socket(AF_SP,NN_PAIR)) < 0 )
printf("error creating utxo->pair\n");
@ -294,7 +293,7 @@ char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
else if ( IAMCLIENT == 0 && strcmp(method,"notifyutxo") == 0 )
{
printf("utxonotify.(%s)\n",jprint(argjson,0));
LP_addutxo(amclient,LP_mypeer,LP_mypubsock,jstr(argjson,"coin"),jbits256(argjson,"txid"),jint(argjson,"vout"),SATOSHIDEN * jdouble(argjson,"value"),jbits256(argjson,"txid2"),jint(argjson,"vout2"),SATOSHIDEN * jdouble(argjson,"value2"),jstr(argjson,"script"),jstr(argjson,"address"),jstr(argjson,"ipaddr"),juint(argjson,"port"),jdouble(argjson,"profit"));
LP_addutxo(amclient,LP_mypeer,LP_mypubsock,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"),jstr(argjson,"ipaddr"),juint(argjson,"port"),jdouble(argjson,"profit"));
retstr = clonestr("{\"result\":\"success\",\"notifyutxo\":\"received\"}");
}
if ( retstr != 0 )

5
iguana/exchanges/LP_include.h

@ -164,8 +164,7 @@ struct LP_utxoinfo
UT_hash_handle hh;
bits256 txid,txid2,feetxid,otherpubkey,mypub;
void *swap;
double value;
uint64_t satoshis,satoshis2;
uint64_t value,satoshis,value2;
uint8_t key[sizeof(bits256) + sizeof(int32_t)];
int32_t vout,vout2,pair;
uint32_t lasttime,errors,swappending,published;
@ -189,7 +188,7 @@ struct LP_quoteinfo
{
struct basilisk_request R;
bits256 srchash,desthash,txid,txid2,desttxid,feetxid,privkey;
uint64_t satoshis,satoshis2,txfee,destsatoshis,desttxfee,change;
uint64_t value,satoshis,satoshis2,txfee,destsatoshis,desttxfee;
uint32_t timestamp,quotetime; int32_t vout,vout2,destvout,feevout,pair;
char srccoin[16],coinaddr[64],destcoin[16],destaddr[64];
};

37
iguana/exchanges/LP_quotes.c

@ -59,11 +59,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp)
if ( qp->quotetime != 0 )
jaddnum(retjson,"quotetime",qp->quotetime);
if ( qp->satoshis != 0 )
{
jadd64bits(retjson,"satoshis",qp->satoshis);
price = (double)(qp->destsatoshis+qp->desttxfee) / qp->satoshis;
jaddnum(retjson,"price",price);
}
if ( bits256_nonz(qp->desthash) != 0 )
jaddbits256(retjson,"desthash",qp->desthash);
if ( bits256_nonz(qp->txid2) != 0 )
@ -84,13 +80,19 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp)
{
jaddbits256(retjson,"feetxid",qp->feetxid);
jaddnum(retjson,"feevout",qp->feevout);
//jadd64bits(retjson,"feesatoshis",qp->feesatoshis);
}
if ( qp->destsatoshis != 0 )
jadd64bits(retjson,"destsatoshis",qp->destsatoshis);
if ( qp->desttxfee != 0 )
jadd64bits(retjson,"desttxfee",qp->desttxfee);
if ( qp->change != 0 )
jaddnum(retjson,"change",dstr(qp->change));
if ( qp->destsatoshis != 0 )
{
jadd64bits(retjson,"destsatoshis",qp->destsatoshis);
if ( qp->satoshis != 0 )
{
price = (double)(qp->destsatoshis + qp->desttxfee) / qp->satoshis;
jaddnum(retjson,"price",price);
}
}
return(retjson);
}
@ -112,11 +114,11 @@ int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson)
qp->feetxid = jbits256(argjson,"feetxid");
qp->destvout = jint(argjson,"destvout");
qp->desthash = jbits256(argjson,"desthash");
if ( (qp->satoshis= j64bits(argjson,"satoshis")) == 0 )
qp->satoshis = SATOSHIDEN * jdouble(argjson,"value");
if ( (qp->destsatoshis= j64bits(argjson,"destsatoshis")) == 0 )
qp->destsatoshis = qp->satoshis * jdouble(argjson,"price");
qp->change = SATOSHIDEN * jdouble(argjson,"change");
//qp->feesatoshis = j64bits(argjson,"feesatoshis");
qp->satoshis = j64bits(argjson,"satoshis");
qp->satoshis2 = j64bits(argjson,"satoshis2");
qp->value = j64bits(argjson,"value");
qp->destsatoshis = j64bits(argjson,"destsatoshis");
qp->txfee = j64bits(argjson,"txfee");
qp->desttxfee = j64bits(argjson,"desttxfee");
return(0);
@ -129,15 +131,16 @@ int32_t LP_quoteinfoinit(struct LP_quoteinfo *qp,struct LP_utxoinfo *utxo,char *
safecopy(qp->destcoin,destcoin,sizeof(qp->destcoin));
if ( (qp->txfee= LP_getestimatedrate(utxo->coin)*LP_AVETXSIZE) < 10000 )
qp->txfee = 10000;
if ( qp->txfee >= utxo->satoshis || qp->txfee >= utxo->satoshis2 )
if ( qp->txfee >= utxo->value || qp->txfee >= utxo->value2 || utxo->value2 < utxo->satoshis+(utxo->satoshis>>3) )
return(-1);
qp->txid = utxo->txid;
qp->vout = utxo->vout;
qp->txid2 = utxo->txid2;
qp->vout2 = utxo->vout2;
qp->satoshis2 = utxo->satoshis2 - qp->txfee;
qp->satoshis = utxo->satoshis - qp->txfee;
qp->satoshis = utxo->satoshis;
qp->satoshis2 = utxo->satoshis + (utxo->satoshis >> 3);
qp->destsatoshis = qp->satoshis * price;
//qp->feesatoshis = qp->destsatoshis / INSTANTDEX_INSURANCEDIV;
if ( (qp->desttxfee= LP_getestimatedrate(qp->destcoin) * LP_AVETXSIZE) < 10000 )
qp->desttxfee = 10000;
if ( qp->desttxfee >= qp->destsatoshis )
@ -161,6 +164,7 @@ int32_t LP_quoteinfoset(struct LP_quoteinfo *qp,uint32_t timestamp,uint32_t quot
qp->timestamp = timestamp;
qp->quotetime = quotetime;
qp->destsatoshis = destsatoshis;
//qp->feesatoshis = qp->destsatoshis / INSTANTDEX_INSURANCEDIV;
qp->desttxfee = desttxfee;
qp->desttxid = desttxid;
qp->destvout = destvout;
@ -181,7 +185,6 @@ char *LP_quotereceived(cJSON *argjson)
} else return(clonestr("{\"error\":\"nullptr\"}"));
}
int32_t LP_sizematch(uint64_t mysatoshis,uint64_t othersatoshis)
{
if ( mysatoshis >= othersatoshis )

2
iguana/exchanges/LP_rpc.c

@ -52,7 +52,7 @@ char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port,
char *issue_LP_notifyutxo(char *destip,uint16_t destport,struct LP_utxoinfo *utxo)
{
char url[4096],str[65],str2[65];
sprintf(url,"http://%s:%u/api/stats/notifyutxo?ipaddr=%s&port=%u&profit=%.6f&coin=%s&txid=%s&vout=%d&value=%.8f&txid2=%s&vout2=%d&value2=%.8f&script=%s&address=%s",destip,destport,utxo->ipaddr,utxo->port,utxo->profitmargin,utxo->coin,bits256_str(str,utxo->txid),utxo->vout,dstr(utxo->satoshis),bits256_str(str2,utxo->txid2),utxo->vout2,dstr(utxo->satoshis2),utxo->spendscript,utxo->coinaddr);
sprintf(url,"http://%s:%u/api/stats/notifyutxo?ipaddr=%s&port=%u&profit=%.6f&coin=%s&txid=%s&vout=%d&value=%.8f&txid2=%s&vout2=%d&value2=%.8f&script=%s&address=%s",destip,destport,utxo->ipaddr,utxo->port,utxo->profitmargin,utxo->coin,bits256_str(str,utxo->txid),utxo->vout,dstr(utxo->value),bits256_str(str2,utxo->txid2),utxo->vout2,dstr(utxo->value2),utxo->spendscript,utxo->coinaddr);
if ( strlen(url) > 1024 )
printf("WARNING long url.(%s)\n",url);
return(issue_curl(url));

32
iguana/exchanges/LP_utxos.c

@ -35,11 +35,11 @@ cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo)
jaddstr(item,"address",utxo->coinaddr);
jaddbits256(item,"txid",utxo->txid);
jaddnum(item,"vout",utxo->vout);
jaddnum(item,"value",utxo->value);
jadd64bits(item,"value",utxo->value);
jadd64bits(item,"satoshis",utxo->satoshis);
jaddbits256(item,"txid2",utxo->txid2);
jaddnum(item,"vout2",utxo->vout2);
jaddnum(item,"value2",dstr(utxo->satoshis2));
jadd64bits(item,"value2",utxo->value2);
if ( utxo->swappending != 0 )
jaddnum(item,"pending",utxo->swappending);
if ( bits256_nonz(utxo->otherpubkey) != 0 )
@ -82,12 +82,12 @@ char *LP_utxos(struct LP_peerinfo *mypeer,char *coin,int32_t lastn)
return(jprint(utxosjson,1));
}
struct LP_utxoinfo *LP_addutxo(int32_t amclient,struct LP_peerinfo *mypeer,int32_t mypubsock,char *coin,bits256 txid,int32_t vout,int64_t satoshis,bits256 deposittxid,int32_t depositvout,int64_t depositsatoshis,char *spendscript,char *coinaddr,char *ipaddr,uint16_t port,double profitmargin)
struct LP_utxoinfo *LP_addutxo(int32_t amclient,struct LP_peerinfo *mypeer,int32_t mypubsock,char *coin,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *spendscript,char *coinaddr,char *ipaddr,uint16_t port,double profitmargin)
{
uint64_t tmpsatoshis; struct LP_utxoinfo *utxo = 0;
if ( coin == 0 || coin[0] == 0 || spendscript == 0 || spendscript[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(deposittxid) == 0 || vout < 0 || depositvout < 0 || satoshis <= 0 || depositsatoshis <= 0 )
if ( coin == 0 || coin[0] == 0 || spendscript == 0 || spendscript[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 )
{
printf("malformed addutxo %d %d %d %d %d %d %d %d %d\n", coin == 0,spendscript == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(deposittxid) == 0,vout < 0,depositvout < 0,satoshis <= 0,depositsatoshis <= 0);
printf("malformed addutxo %d %d %d %d %d %d %d %d %d\n", coin == 0,spendscript == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0);
return(0);
}
if ( IAMCLIENT == 0 && strcmp(ipaddr,"127.0.0.1") == 0 )
@ -95,15 +95,15 @@ struct LP_utxoinfo *LP_addutxo(int32_t amclient,struct LP_peerinfo *mypeer,int32
printf("LP node got localhost utxo\n");
return(0);
}
if ( IAMCLIENT == 0 || depositsatoshis < 9 * (satoshis >> 3) )
tmpsatoshis = (depositsatoshis / 9) << 3;
else tmpsatoshis = satoshis;
if ( IAMCLIENT == 0 || value2 < 9 * (value >> 3) )
tmpsatoshis = (value2 / 9) << 3;
else tmpsatoshis = value;
if ( (utxo= LP_utxofind(txid,vout)) != 0 )
{
if ( bits256_cmp(txid,utxo->txid) != 0 || bits256_cmp(deposittxid,utxo->txid2) != 0 || vout != utxo->vout || tmpsatoshis != utxo->satoshis || depositvout != utxo->vout2 || depositsatoshis != utxo->satoshis2 || strcmp(coin,utxo->coin) != 0 || strcmp(spendscript,utxo->spendscript) != 0 || strcmp(coinaddr,utxo->coinaddr) != 0 || strcmp(ipaddr,utxo->ipaddr) != 0 || port != utxo->port )
if ( bits256_cmp(txid,utxo->txid) != 0 || bits256_cmp(txid2,utxo->txid2) != 0 || vout != utxo->vout || value != utxo->value || tmpsatoshis != utxo->satoshis || vout2 != utxo->vout2 || value2 != utxo->value2 || strcmp(coin,utxo->coin) != 0 || strcmp(spendscript,utxo->spendscript) != 0 || strcmp(coinaddr,utxo->coinaddr) != 0 || strcmp(ipaddr,utxo->ipaddr) != 0 || port != utxo->port )
{
utxo->errors++;
char str[65],str2[65]; printf("error on subsequent utxo add.(%s v %s) %d %d %d %d %d %d %d %d %d %d %d\n",bits256_str(str,txid),bits256_str(str2,utxo->txid),bits256_cmp(txid,utxo->txid) != 0,bits256_cmp(deposittxid,utxo->txid2) != 0,vout != utxo->vout,satoshis != utxo->satoshis,depositvout != utxo->vout2,depositsatoshis != utxo->satoshis2,strcmp(coin,utxo->coin) != 0,strcmp(spendscript,utxo->spendscript) != 0,strcmp(coinaddr,utxo->coinaddr) != 0,strcmp(ipaddr,utxo->ipaddr) != 0,port != utxo->port);
char str[65],str2[65]; printf("error on subsequent utxo add.(%s v %s) %d %d %d %d %d %d %d %d %d %d %d %d\n",bits256_str(str,txid),bits256_str(str2,utxo->txid),bits256_cmp(txid,utxo->txid) != 0,bits256_cmp(txid2,utxo->txid2) != 0,vout != utxo->vout,tmpsatoshis != utxo->satoshis,vout2 != utxo->vout2,value2 != utxo->value2,strcmp(coin,utxo->coin) != 0,strcmp(spendscript,utxo->spendscript) != 0,strcmp(coinaddr,utxo->coinaddr) != 0,strcmp(ipaddr,utxo->ipaddr) != 0,port != utxo->port,value != utxo->value);
}
else if ( profitmargin != 0. )
utxo->profitmargin = profitmargin;
@ -120,11 +120,11 @@ struct LP_utxoinfo *LP_addutxo(int32_t amclient,struct LP_peerinfo *mypeer,int32
safecopy(utxo->spendscript,spendscript,sizeof(utxo->spendscript));
utxo->txid = txid;
utxo->vout = vout;
utxo->value = dstr(satoshis);
utxo->value = value;
utxo->satoshis = tmpsatoshis;
utxo->txid2 = deposittxid;
utxo->vout2 = depositvout;
utxo->satoshis2 = depositsatoshis;
utxo->txid2 = txid2;
utxo->vout2 = vout2;
utxo->value2 = value2;
memcpy(utxo->key,txid.bytes,sizeof(txid));
memcpy(&utxo->key[sizeof(txid)],&vout,sizeof(vout));
portable_mutex_lock(&LP_utxomutex);
@ -134,7 +134,7 @@ struct LP_utxoinfo *LP_addutxo(int32_t amclient,struct LP_peerinfo *mypeer,int32
portable_mutex_unlock(&LP_utxomutex);
if ( mypubsock >= 0 )
LP_send(mypubsock,jprint(LP_utxojson(utxo),1),1);
char str[65],str2[65]; printf("amclient.%d %s:%u %s LP_addutxo.(%.8f %.8f) numutxos.%d %s %s\n",IAMCLIENT,ipaddr,port,utxo->coin,dstr(satoshis),dstr(depositsatoshis),mypeer!=0?mypeer->numutxos:0,bits256_str(str,utxo->txid),bits256_str(str2,txid));
char str[65],str2[65]; printf("amclient.%d %s:%u %s LP_addutxo.(%.8f %.8f) numutxos.%d %s %s\n",IAMCLIENT,ipaddr,port,utxo->coin,dstr(value),dstr(value2),mypeer!=0?mypeer->numutxos:0,bits256_str(str,utxo->txid),bits256_str(str2,txid));
}
return(utxo);
}
@ -166,7 +166,7 @@ int32_t LP_utxosparse(int32_t amclient,struct LP_peerinfo *mypeer,int32_t mypubs
if ( jobj(item,"txid") != 0 )
{
txid = jbits256(item,"txid");
utxo = LP_addutxo(amclient,mypeer,mypubsock,jstr(item,"coin"),txid,jint(item,"vout"),SATOSHIDEN*jdouble(item,"value"),jbits256(item,"txid2"),jint(item,"vout2"),SATOSHIDEN * jdouble(item,"value2"),jstr(item,"script"),jstr(item,"address"),argipaddr,argport,jdouble(item,"profit"));
utxo = LP_addutxo(amclient,mypeer,mypubsock,jstr(item,"coin"),txid,jint(item,"vout"),j64bits(item,"value"),jbits256(item,"txid2"),jint(item,"vout2"),j64bits(item,"value2"),jstr(item,"script"),jstr(item,"address"),argipaddr,argport,jdouble(item,"profit"));
if ( utxo != 0 )
utxo->lasttime = now;
}

Loading…
Cancel
Save