From 898b0e829c5b8b1d8214f1384acc4655deb67d5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 11:03:35 +0300 Subject: [PATCH] Uuid --- iguana/exchanges/LP_include.h | 8 ++++---- iguana/exchanges/LP_ordermatch.c | 24 +++++++++++++++++++----- iguana/exchanges/LP_remember.c | 18 ++++++++++++------ iguana/exchanges/LP_signatures.c | 2 ++ 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 644644871..2f7530982 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -35,7 +35,7 @@ voind dontprintf(char *formatstr,...) {} #define LP_MAJOR_VERSION "0" #define LP_MINOR_VERSION "1" -#define LP_BUILD_NUMBER "27773" +#define LP_BUILD_NUMBER "27774" #define LP_BARTERDEX_VERSION 1 #define LP_MAGICBITS 1 @@ -276,7 +276,7 @@ struct LP_swap_remember uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate; int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)]; uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33]; - char Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75],alicePaymentEthTx[75]; + char uuidstr[65],Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75],alicePaymentEthTx[75]; }; struct LP_outpoint @@ -379,7 +379,7 @@ struct LP_quoteinfo uint64_t satoshis,txfee,destsatoshis,desttxfee,aliceid; uint32_t timestamp,quotetime,tradeid; int32_t vout,vout2,destvout,feevout,pair; - char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64],etomicsrc[65],etomicdest[65]; + char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64],etomicsrc[65],etomicdest[65],uuidstr[65]; }; struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; @@ -397,7 +397,7 @@ struct basilisk_swap struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim; bits256 privkeys[INSTANTDEX_DECKSIZE]; //struct basilisk_swapmessage *messages; int32_t nummessages,sentflag; - char Bdeposit[64],Bpayment[64]; + char Bdeposit[64],Bpayment[64],uuidstr[65]; uint64_t aliceid,otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; uint8_t persistent_pubkey33[33],persistent_other33[33],changermd160[20],pad[15],verifybuf[100000]; }; diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d87a35335..c38b4ae7d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -566,7 +566,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double return(retval); } -char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration,uint32_t tradeid,bits256 destpubkey) +char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration,uint32_t tradeid,bits256 destpubkey,char *uuidstr) { double price; price = 0.; @@ -576,10 +576,11 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q if ( (qp->tradeid= tradeid) == 0 ) qp->tradeid = LP_rand(); qp->srchash = destpubkey; + strncpy(qp->uuidstr,uuidstr,sizeof(qp->uuidstr)-1); LP_query(ctx,myipaddr,mypubsock,"request",qp); LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey; - char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s)\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice,qp->etomicdest); - return(LP_recent_swaps(0,qp->R.requestid)); + char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s) uuid.%s\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice,qp->etomicdest,qp->uuidstr); + return(LP_recent_swaps(0,uuidstr)); } int32_t LP_quotecmp(int32_t strictflag,struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) @@ -1446,7 +1447,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration,char *gui,uint32_t nonce,bits256 destpubkey,uint32_t tradeid) { - uint64_t desttxfee,txfee,balance; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,A; struct LP_quoteinfo Q; bits256 pubkeys[100]; struct LP_address_utxo *utxos[4096]; int32_t num=0,maxiters=100,i,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + uint64_t desttxfee,txfee,balance; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,A; struct LP_quoteinfo Q; bits256 pubkeys[100]; struct LP_address_utxo *utxos[4096]; int32_t num=0,maxiters=100,i,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); char _uuidstr[65],*uuidstr; basecoin = LP_coinfind(base); relcoin = LP_coinfind(rel); if ( gui == 0 ) @@ -1584,7 +1585,20 @@ char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,cha int32_t changed; LP_mypriceset(&changed,rel,base,1. / maxprice); LP_mypriceset(&changed,base,rel,0.); - return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); + if ( (uuidstr= jsr(argjson,"uuid")) == 0 ) + { + uint8_t uuidhash[256]; bits256 hash; uint64_t millis; int32_t len = 0; + memcpy(uuidhash,G.LP_mypub25519,sizeof(bits256)), len += sizeof(bits256); + millis = OS_milliseconds(); + memcpy(&uuidhash[len],&millis,sizeof(millis)), len += sizeof(millis); + memcpy(&uuidhash[len],base,(int32_t)strlen(base)), len += (int32_t)strlen(base); + memcpy(&uuidhash[len],rel,(int32_t)strlen(rel)), len += (int32_t)strlen(rel); + vcalc_sha256(0,hash.bytes,uuidhash,len); + uuidstr = _uuidstr; + bits256_str(uuidstr,hash); + printf("%s %llu %s %s -> uuid.%s\n",bits256_str(str,G.LP_mypub25519),(long long)millis,base,rel,uuidstr); + } + return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey,uuidstr)); } diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index b5ded66ec..85d1fc9db 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -63,6 +63,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx if ( swap->Bpayment[0] != 0 ) fprintf(fp,",\"%s\":\"%s\"","Bpayment",swap->Bpayment); fprintf(fp,",\"expiration\":%u",swap->I.expiration); + fprintf(fp,",\"uuid\":\"%s\"",swap->uuidstr); fprintf(fp,",\"iambob\":%d",swap->I.iambob); fprintf(fp,",\"bobcoin\":\"%s\"",swap->I.bobstr); if ( swap->I.bobtomic[0] != 0 ) @@ -117,6 +118,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx fprintf(fp,",\"Agui\":\"%s\"",G.gui); else fprintf(fp,",\"Bgui\":\"%s\"",G.gui); fprintf(fp,",\"gui\":\"%s\"",G.gui); + fprintf(fp,",\"uuid\":\"%s\"",swap->uuidstr); if ( memcmp(zeroes,swap->I.secretAm,20) != 0 ) { init_hexbytes_noT(secretAmstr,swap->I.secretAm,20); @@ -629,6 +631,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) jaddnum(item,"critical",LP_swap_critical); jaddnum(item,"endcritical",LP_swap_endcritical); } + jaddstr(item,"uuid",rswap->uuidstr); jaddnum(item,"expiration",rswap->expiration);// - INSTANTDEX_LOCKTIME*2); jaddnum(item,"tradeid",rswap->tradeid); jaddnum(item,"requestid",rswap->requestid); @@ -693,6 +696,7 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t if ( (item= cJSON_Parse(fstr)) != 0 ) { rswap->iambob = jint(item,"iambob"); + safecopy(rswap->uuidstr,jstr(item,"uuid"),sizeof(rswap->uuidstr)); safecopy(rswap->Bgui,jstr(item,"Bgui"),sizeof(rswap->Bgui)); safecopy(rswap->Agui,jstr(item,"Agui"),sizeof(rswap->Agui)); safecopy(rswap->gui,jstr(item,"gui"),sizeof(rswap->gui)); @@ -1103,6 +1107,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals, //printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest); cJSON *retjson = cJSON_CreateObject(); jaddstr(retjson,"error","swap never started"); + jaddstr(retjson,"uuid",rswap.uuidstr); jaddstr(retjson,"status","finished"); jaddstr(retjson,"bob",rswap.bobcoin); jaddstr(retjson,"src",rswap.src); @@ -1127,6 +1132,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals, printf("this isnt my swap! alice.(%s vs %s)\n",alice->smartaddr,rswap.Adestaddr); cJSON *retjson = cJSON_CreateObject(); jaddstr(retjson,"error","swap for different account"); + jaddstr(retjson,"uuid",rswap.uuidstr); jaddstr(retjson,"alice",alice->symbol); jaddstr(retjson,"aliceaddr",alice->smartaddr); jaddstr(retjson,"dest",rswap.dest); @@ -1139,6 +1145,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals, printf("need to scan %s first\n",alice->symbol); cJSON *retjson = cJSON_CreateObject(); jaddstr(retjson,"error","need to scan coin first"); + jaddstr(retjson,"uuid",rswap.uuidstr); jaddstr(retjson,"coin",alice->symbol); jaddnum(retjson,"scanned",alice->lastscanht); jaddnum(retjson,"longest",alice->longestchain); @@ -1166,6 +1173,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals, printf("this isnt my swap! bob.(%s vs %s)\n",bob->smartaddr,rswap.destaddr); cJSON *retjson = cJSON_CreateObject(); jaddstr(retjson,"error","swap for different account"); + jaddstr(retjson,"uuid",rswap.uuidstr); jaddstr(retjson,"bob",bob->symbol); jaddstr(retjson,"bobaddr",bob->smartaddr); jaddstr(retjson,"src",rswap.src); @@ -1178,6 +1186,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals, printf("need to scan %s first\n",bob->symbol); cJSON *retjson = cJSON_CreateObject(); jaddstr(retjson,"error","need to scan coin first"); + jaddstr(retjson,"uuid",rswap.uuidstr); jaddstr(retjson,"coin",bob->symbol); jaddnum(retjson,"scanned",bob->lastscanht); jaddnum(retjson,"longest",bob->longestchain); @@ -1681,7 +1690,7 @@ char *basilisk_swapentry(int32_t fastflag,uint32_t requestid,uint32_t quoteid,in extern struct LP_quoteinfo LP_Alicequery; extern uint32_t Alice_expiration; -char *LP_recent_swaps(int32_t limit,uint32_t origrequestid) +char *LP_recent_swaps(int32_t limit,char *uuidstr) { char fname[512],*retstr,*base,*rel,*statusstr; long fsize,offset; FILE *fp; int32_t baseind,relind,i=0; uint32_t requestid,quoteid; cJSON *array,*item,*retjson,*subitem,*swapjson; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS]; double srcamount,destamount,netamounts[LP_MAXPRICEINFOS]; memset(KMDtotals,0,sizeof(KMDtotals)); @@ -1776,11 +1785,8 @@ char *LP_recent_swaps(int32_t limit,uint32_t origrequestid) jadd64bits(item,"aliceid",LP_aliceid_calc(LP_Alicequery.desttxid,LP_Alicequery.destvout,LP_Alicequery.feetxid,LP_Alicequery.feevout)); jadd(retjson,"pending",item); } else Alice_expiration = 0; - if ( origrequestid != 0 ) - { - jaddnum(retjson,"requestid",origrequestid); - jaddbits256(retjson,"desthash",G.LP_mypub25519); - } + if ( uuidstr != 0 ) + jaddstr(retjson,"uuid",uuidstr); return(jprint(retjson,1)); } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 329172271..de93baef9 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -44,6 +44,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp) double price; char etomic[64],activesymbol[65]; cJSON *retjson = cJSON_CreateObject(); if ( jobj(retjson,"gui") == 0 ) jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui); + jaddstr(retjson,"uuid",qp->uuidstr); jadd64bits(retjson,"aliceid",qp->aliceid); jaddnum(retjson,"tradeid",qp->tradeid); jaddstr(retjson,"base",qp->srccoin); @@ -114,6 +115,7 @@ int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson) memset(qp,0,sizeof(*qp)); safecopy(qp->gui,LP_gui,sizeof(qp->gui)); safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin)); + safecopy(qp->uuidstr,jstr(argjson,"uuid"),sizeof(qp->uuidstr)); if ( LP_etomicsymbol(activesymbol,etomic,qp->srccoin) != 0 ) { if ( (etomicstr= jstr(argjson,"bobtomic")) == 0 || strcmp(etomicstr,etomic) != 0 )