From c9a93218f9348f54b0d12974d6d2da3f1fcd3723 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jan 2017 22:06:26 +0200 Subject: [PATCH] redundant dex* queries, iguana lock time --- basilisk/basilisk_MSG.c | 2 +- basilisk/basilisk_bitcoin.c | 4 +- basilisk/basilisk_swap.c | 2 +- gecko/gecko_miner.c | 2 +- iguana/dPoW.h | 2 +- iguana/dpow/dpow_network.c | 99 ++++++++++++++++++++++--------------- iguana/iguana_notary.c | 2 +- iguana/iguana_payments.c | 2 +- iguana/iguana_sign.c | 6 ++- iguana/tests/dexgetH | 2 +- iguana/tests/dexlistunspent | 2 +- includes/iguana_funcs.h | 2 +- 12 files changed, 75 insertions(+), 52 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index c6cb0afa9..86d0eda80 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -309,7 +309,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) memcpy(space2,key,BASILISK_KEYSIZE); if ( data != 0 && datalen != 0 ) memcpy(&space2[BASILISK_KEYSIZE],data,datalen); - dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE,1); + dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE,1,""); } else printf("sendmessage space too small error for %d\n",datalen); free(space); free(space2); diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index b3bf8a9da..321ba0c50 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -550,7 +550,7 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi if ( signedtxidp != 0 ) memset(signedtxidp,0,sizeof(*signedtxidp)); bitcoin_address(changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33); - if ( (txobj= bitcoin_txcreate(coin->chain->isPoS,0,1,0)) != 0 ) + if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,0,1,0)) != 0 ) { if ( duplicates <= 0 ) duplicates = 1; @@ -609,7 +609,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}")); if ( coin != 0 ) { - if ( (txobj= bitcoin_txcreate(coin->chain->isPoS,locktime,locktime==0?coin->chain->normal_txversion:coin->chain->locktime_txversion,juint(valsobj,"timestamp"))) != 0 ) + if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,locktime,locktime==0?coin->chain->normal_txversion:coin->chain->locktime_txversion,juint(valsobj,"timestamp"))) != 0 ) { spendlen = (int32_t)strlen(spendscriptstr) >> 1; decode_hex(buf,spendlen,spendscriptstr); diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index b340b81ac..bced7218b 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -325,7 +325,7 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b V[0].ignore_cltverr = ignore_cltverr; if ( dest->I.redeemlen != 0 ) memcpy(V[0].p2shscript,dest->redeemscript,dest->I.redeemlen), V[0].p2shlen = dest->I.redeemlen; - txobj = bitcoin_txcreate(rawtx->coin->chain->isPoS,locktime,userdata == 0 ? 1 : 1,timestamp);//rawtx->coin->chain->locktime_txversion); + txobj = bitcoin_txcreate(rawtx->coin->symbol,rawtx->coin->chain->isPoS,locktime,userdata == 0 ? 1 : 1,timestamp);//rawtx->coin->chain->locktime_txversion); vins = cJSON_CreateArray(); item = cJSON_CreateObject(); if ( userdata != 0 && userdatalen > 0 ) diff --git a/gecko/gecko_miner.c b/gecko/gecko_miner.c index 77b592467..6a7bdee31 100755 --- a/gecko/gecko_miner.c +++ b/gecko/gecko_miner.c @@ -302,7 +302,7 @@ cJSON *gecko_paymentsobj(struct supernet_info *myinfo,cJSON *txjson,cJSON *valso if ( (txversion= juint(valsobj,"txversion")) == 0 ) txversion = (locktime == 0) ? IGUANA_NORMAL_TXVERSION : IGUANA_LOCKTIME_TXVERSION; if ( txjson == 0 ) - txjson = bitcoin_txcreate(1,locktime,txversion,juint(valsobj,"timestamp")); + txjson = bitcoin_txcreate("gecko",1,locktime,txversion,juint(valsobj,"timestamp")); if ( (array= jarray(&n,valsobj,"payments")) != 0 && n > 0 ) { for (i=0; i (%s)\n",dexreq.intarg,bits256_str(buf,hash2)); bits256_str(buf,hash2); - if ( (retstr= clonestr(buf)) != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) - { - dpow_randipbits(myinfo,coin,retjson); - free(retstr); - retstr = jprint(retjson,1); - } + retstr = clonestr(buf); } else if ( dexreq.func == 'B' ) { @@ -306,22 +302,11 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d { hash2 = dpow_getbestblockhash(myinfo,coin); bits256_str(buf,hash2); - if ( (retstr= clonestr(buf)) != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) - { - dpow_randipbits(myinfo,coin,retjson); - free(retstr); - retstr = jprint(retjson,1); - } + retstr = clonestr(buf); } else if ( dexreq.func == 'S' ) { retstr = dpow_sendrawtransaction(myinfo,coin,(char *)&dexp->packet[datalen]); - if ( retstr != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) - { - dpow_randipbits(myinfo,coin,retjson); - free(retstr); - retstr = jprint(retjson,1); - } } else if ( dexreq.func == '*' ) { @@ -372,15 +357,16 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d return(retstr); } -char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M) +char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M,char *field) { - char *retstrs[64]; int32_t i,j,max = myinfo->numdexipbits; + char *retstrs[64],*origretstr0 = 0; cJSON *retjson; int32_t err,i,j,max = myinfo->numdexipbits; memset(retstrs,0,sizeof(retstrs)); for (i=j=0; i<=max; i++) { if ( (retstrs[j]= _dex_reqsend(myinfo,handler,data,datalen)) != 0 ) { - if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 ) + printf("j.%d of max.%d (%s)\n",j,max,retstrs[j]); + if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 && strcmp("0",retstrs[j]) != 0 ) { if ( ++j == M ) break; @@ -394,23 +380,58 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 return(retstrs[0]); else { - for (i=0; iname) >= 0 ) { datalen = dex_rwrequest(1,packet,dexreq); - return(dex_reqsend(myinfo,"request",packet,datalen,M)); + return(dex_reqsend(myinfo,"request",packet,datalen,M,field)); } else return(clonestr("{\"error\":\"not notarychain\"}")); } -char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str,int32_t M) +char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str,int32_t M,char *field) { uint8_t *packet; int32_t datalen,slen; char *retstr; if ( iguana_isnotarychain(dexreq->name) >= 0 ) @@ -420,7 +441,7 @@ char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexre datalen = dex_rwrequest(1,packet,dexreq); strcpy((char *)&packet[datalen],str); datalen += slen; - retstr = dex_reqsend(myinfo,"request",packet,datalen,M); + retstr = dex_reqsend(myinfo,"request",packet,datalen,M,field); free(packet); return(retstr); } else return(clonestr("{\"error\":\"not notarychain\"}")); @@ -433,7 +454,7 @@ char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 t safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.hash = txid; dexreq.func = 'T'; - return(_dex_sendrequest(myinfo,&dexreq,1)); + return(_dex_sendrequest(myinfo,&dexreq,1,"")); } char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout) @@ -445,7 +466,7 @@ char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32 dexreq.hash = txid; dexreq.shortarg = vout; dexreq.func = 'O'; - return(_dex_sendrequest(myinfo,&dexreq,3)); + return(_dex_sendrequest(myinfo,&dexreq,3,"value")); } char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) @@ -454,7 +475,7 @@ char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = 'I'; - return(_dex_sendrequest(myinfo,&dexreq,1)); + return(_dex_sendrequest(myinfo,&dexreq,1,"")); } char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) @@ -463,7 +484,7 @@ char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = '*'; - return(_dex_sendrequest(myinfo,&dexreq,1)); + return(_dex_sendrequest(myinfo,&dexreq,1,"")); } char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) @@ -473,7 +494,7 @@ char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.hash = hash2; dexreq.func = 'B'; - return(_dex_sendrequest(myinfo,&dexreq,1)); + return(_dex_sendrequest(myinfo,&dexreq,1,"")); } char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height) @@ -483,7 +504,7 @@ char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.intarg = height; dexreq.func = 'H'; - return(_dex_sendrequest(myinfo,&dexreq,1)); + return(_dex_sendrequest(myinfo,&dexreq,3,"*")); } char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol) @@ -492,7 +513,7 @@ char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol) memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = 'P'; - return(_dex_sendrequest(myinfo,&dexreq,3)); + return(_dex_sendrequest(myinfo,&dexreq,1,"")); } char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx) @@ -501,7 +522,7 @@ char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *si memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = 'S'; - return(_dex_sendrequeststr(myinfo,&dexreq,signedtx,3)); + return(_dex_sendrequeststr(myinfo,&dexreq,signedtx,3,"*")); } char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address) @@ -510,7 +531,7 @@ char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = 'A'; - return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); } char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address) @@ -519,7 +540,7 @@ char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *addre memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = 'V'; - return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); } char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address) @@ -528,7 +549,7 @@ char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address) memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = 'U'; - return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); } char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip) @@ -539,7 +560,7 @@ char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *addr dexreq.intarg = skip; dexreq.shortarg = count; dexreq.func = 'L'; - return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); } int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 4eaff6fe7..8ea940781 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -381,7 +381,7 @@ TWO_STRINGS(dex,send,hex,handler) decode_hex(data,datalen,hex); if ( handler == 0 || handler[0] == 0 ) handler = "DEX"; - if ( (retstr= dex_reqsend(myinfo,handler,data,datalen,1)) == 0 ) + if ( (retstr= dex_reqsend(myinfo,handler,data,datalen,1,"")) == 0 ) return(clonestr("{\"result\":\"success\"}")); else return(retstr); } else return(clonestr("{\"error\":\"dex send: invalid hex\"}")); diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index eaccdb2a0..b28442b15 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -1236,7 +1236,7 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime) bits256 txid; int32_t offset,spendlen=0,n; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint64_t satoshis; char *hexstr,*field,*txstr; cJSON *txobj,*item,*obj,*retjson = cJSON_CreateObject(); if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); - if ( coin != 0 && (txobj= bitcoin_txcreate(coin->chain->isPoS,locktime,1,0)) != 0 ) + if ( coin != 0 && (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,locktime,1,0)) != 0 ) { iguana_createvins(myinfo,coin,txobj,vins); if ( (n= cJSON_GetArraySize(vouts)) > 0 ) diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index f8790f003..ca59d58c8 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -1245,10 +1245,12 @@ cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_ return(txobj); } -cJSON *bitcoin_txcreate(int32_t isPoS,int64_t locktime,uint32_t txversion,uint32_t timestamp) +cJSON *bitcoin_txcreate(char *symbol,int32_t isPoS,int64_t locktime,uint32_t txversion,uint32_t timestamp) { cJSON *json = cJSON_CreateObject(); jaddnum(json,"version",txversion); + if ( locktime == 0 && strcmp(symbol,"KMD") == 0 ) + locktime = (uint32_t)time(NULL); jaddnum(json,"locktime",locktime); if ( isPoS != 0 ) jaddnum(json,"timestamp",timestamp == 0 ? time(NULL) : timestamp); @@ -1356,7 +1358,7 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount if ( M > N || N > 3 ) return(clonestr("{\"error\":\"illegal M or N\"}")); memset(&V,0,sizeof(V)); - txobj = bitcoin_txcreate(active->chain->isPoS,0,coin->chain->normal_txversion,0); + txobj = bitcoin_txcreate(active->symbol,active->chain->isPoS,0,coin->chain->normal_txversion,0); if ( destaddress[0] != 0 && destamount > 0. ) bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN); if ( destaddress2[0] != 0 && destamount2 > 0. ) diff --git a/iguana/tests/dexgetH b/iguana/tests/dexgetH index 8b1963442..5e87d32a0 100755 --- a/iguana/tests/dexgetH +++ b/iguana/tests/dexgetH @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getblockhash\",\"height\":400000,\"symbol\":\"BTC\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getblockhash\",\"height\":100000,\"symbol\":\"KMD\"}" diff --git a/iguana/tests/dexlistunspent b/iguana/tests/dexlistunspent index 4e353d69b..7347339da 100755 --- a/iguana/tests/dexlistunspent +++ b/iguana/tests/dexlistunspent @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"1Hgzt5xsnbfc8UTWqWKSTLRm5bEYHYBoCE\",\"symbol\":\"BTC\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\",\"symbol\":\"KMD\"}" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index efba8cba3..8a106ca3a 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -308,7 +308,7 @@ cJSON *iguana_signtx(struct supernet_info *myinfo,struct iguana_info *coin,bits2 void iguana_addscript(struct iguana_info *coin,cJSON *dest,uint8_t *script,int32_t scriptlen,char *fieldname); bits256 iguana_genesis(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_chain *chain); -cJSON *bitcoin_txcreate(int32_t isPoS,int64_t locktime,uint32_t txversion,uint32_t timestamp); +cJSON *bitcoin_txcreate(char *symbol,int32_t isPoS,int64_t locktime,uint32_t txversion,uint32_t timestamp); cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis); cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys,uint8_t *sigscript,int32_t siglen);