diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index f79f23175..faa0ba9a6 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -62,7 +62,7 @@ cJSON *LP_cache_transaction(struct iguana_info *coin,bits256 txid,uint8_t *seria void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t height) { - struct LP_transaction TX; struct LP_transaction *tx = 0; + struct LP_transaction TX; int32_t n; struct LP_transaction *tx = 0; if ( coin->cachefp != 0 && (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 && tx->len > 0 ) //strcmp(coin->smartaddr,coinaddr) == 0 && { char str[65]; printf("store %s %s.[%d]\n",coin->symbol,bits256_str(str,txid),tx->len); @@ -74,6 +74,9 @@ void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t h if ( tx->numvouts > 0 ) fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),coin->cachefp); fwrite(tx->serialized,1,tx->len,coin->cachefp); + n = tx->len; + while ( (n & 7) != 0 ) + fputc(0,coin->cachefp), n++; fflush(coin->cachefp); } } @@ -89,11 +92,17 @@ void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t h int32_t LP_cacheitem(struct iguana_info *coin,struct LP_transaction *tx,long remains) { - int32_t offset; + int32_t offset; bits256 hash; char str[65],str2[65]; offset = sizeof(*tx) + tx->numvouts*sizeof(*tx->outpoints); if ( offset+tx->len <= remains ) { - return(0); + hash = bits256_doublesha256(0,&((uint8_t *)tx)[offset],tx->len); + if ( bits256_cmp(hash,tx->txid) == 0 ) + { + printf("%s validated in cache\n",bits256_str(str,hash)); + return(0); + } + printf("%s vs %s did not validated in cache\n",bits256_str(str,hash),bits256_str(str2,tx->txid)); } return(-1); } diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index c87c181ba..ec308800d 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -37,6 +37,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_BARTERDEX_VERSION 1 #define LP_MAGICBITS 8 +#define LP_MAXVINS 64 #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) #define LP_AUTOTRADE_TIMEOUT 30 #define ELECTRUM_TIMEOUT 7 diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 6fe266200..91bdb2f2d 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -481,12 +481,11 @@ int64_t iguana_lockval(int32_t finalized,int64_t locktime) int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson,int32_t zcash) { - uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 100000; char *privkeystr,*signedtx = 0; bits256 *privkeys,privkey,txid; cJSON *item; cJSON *txobj = 0; + uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 100000; char *privkeystr,*signedtx = 0; bits256 privkeys[LP_MAXVINS],privkey,txid; cJSON *item; cJSON *txobj = 0; maxsize = 1000000; memset(privkey.bytes,0,sizeof(privkey)); if ( rawtx != 0 && rawtx[0] != 0 && (len= (int32_t)strlen(rawtx)>>1) < maxsize ) { - privkeys = calloc(numinputs+1024,sizeof(*privkeys)); serialized = malloc(maxsize); serialized2 = malloc(maxsize); serialized3 = malloc(maxsize); @@ -506,7 +505,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ if ( iguana_rwmsgtx(taddr,pubtype,p2shtype,isPoS,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,extralen,vins,V->suppress_pubkeys,zcash) > 0 && numinputs == msgtx->tx_in ) { memset(pubkeys,0,sizeof(pubkeys)); - memset(privkeys,0,sizeof(*privkeys)*numinputs); + memset(privkeys,0,sizeof(privkeys)); if ( (n= cJSON_GetArraySize(privkeysjson)) > 0 ) { for (i=0; ismartaddr,sizeof(changeaddr)); safecopy(vinaddr,coin->smartaddr,sizeof(vinaddr)); privkey = LP_privkey(vinaddr,coin->taddr); - maxV = 1024; + maxV = LP_MAXVINS; V = malloc(maxV * sizeof(*V)); for (iter=0; iter<2; iter++) {