From 456ede8d700cee6cb02ed3bb2136061f5273bbe5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 20:01:40 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_cache.c | 62 +++++++++++++++---------------- iguana/exchanges/LP_transaction.c | 4 +- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index dcdbf777b..4423aa7e5 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -60,21 +60,39 @@ cJSON *LP_cache_transaction(struct iguana_info *coin,bits256 txid,uint8_t *seria return(txobj); } -/*struct LP_transaction +void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t height) { - UT_hash_handle hh; - bits256 txid; - int32_t height,numvouts,numvins,len,SPV; - uint8_t *serialized; - struct LP_outpoint outpoints[]; -};*/ + struct LP_transaction TX; 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); + TX = *tx; + memset(&TX.hh,0,sizeof(TX.hh)); + TX.serialized = 0; + TX.SPV = height; + fwrite(&TX,1,sizeof(TX),coin->cachefp); + if ( tx->numvouts > 0 ) + fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),coin->cachefp); + fwrite(tx->serialized,1,tx->len,coin->cachefp); + fflush(coin->cachefp); + } +} + +/*struct LP_transaction + { + UT_hash_handle hh; + bits256 txid; + int32_t height,numvouts,numvins,len,SPV; + uint8_t *serialized; + struct LP_outpoint outpoints[]; + };*/ int32_t LP_cacheitem(struct iguana_info *coin,uint8_t *ptr,long remains) { return(-1); } -void *LP_cacheptr(FILE **wfp,long *fsizep,struct iguana_info *coin) +void *LP_cacheptrs_init(FILE **wfp,long *fsizep,struct iguana_info *coin) { char fname[1024]; long n,len = 0; uint8_t *ptr = 0; sprintf(fname,"%s/UNSPENTS/%s.SPV",GLOBAL_DBDIR,coin->symbol), OS_portable_path(fname); @@ -95,30 +113,6 @@ void *LP_cacheptr(FILE **wfp,long *fsizep,struct iguana_info *coin) return(ptr); } -int32_t LP_SPV_load(struct iguana_info *coin,bits256 txid,int32_t height) -{ - // struct LP_transaction *tp; - return(-1); -} - - -void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t height) -{ - struct LP_transaction TX; 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); - TX = *tx; - memset(&TX.hh,0,sizeof(TX.hh)); - TX.serialized = 0; - fwrite(&TX,1,sizeof(TX),coin->cachefp); - if ( tx->numvouts > 0 ) - fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),coin->cachefp); - fwrite(tx->serialized,1,tx->len,coin->cachefp); - fflush(coin->cachefp); - } -} - bits256 iguana_merkle(bits256 *tree,int32_t txn_count) { int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2]; @@ -189,7 +183,7 @@ bits256 LP_merkleroot(struct iguana_info *coin,struct electrum_info *ep,int32_t int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height) { - struct LP_transaction *tx; cJSON *merkobj,*merkles; bits256 roothash,merkleroot; int32_t m,SPV = 0; + struct LP_transaction *tx=0; cJSON *merkobj,*merkles; bits256 roothash,merkleroot; int32_t m,SPV = 0; if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height == height && tx->SPV > 0 ) return(tx->SPV); if ( (merkobj= electrum_getmerkle(coin->symbol,ep,&merkobj,txid,height)) != 0 ) @@ -206,6 +200,8 @@ int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_i if ( bits256_cmp(merkleroot,roothash) == 0 ) { SPV = height; + if ( tx != 0 ) + tx->SPV = height; LP_SPV_store(coin,coinaddr,txid,height); //printf("validated MERK %s ht.%d -> %s root.(%s)\n",bits256_str(str,up->U.txid),up->U.height,jprint(merkobj,0),bits256_str(str2,roothash)); } diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 81a7e7b3b..50e8b2c69 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -475,11 +475,12 @@ 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[1024],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,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,sizeof(*privkeys)); serialized = malloc(maxsize); serialized2 = malloc(maxsize); serialized3 = malloc(maxsize); @@ -595,6 +596,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ } else printf("rwmsgtx error\n"); } else printf("no inputs in vins.(%s)\n",vins!=0?jprint(vins,0):"null"); free(extraspace); + free(privkeys); free(serialized), free(serialized2), free(serialized3), free(serialized4); } else return(-1); if ( txobj != 0 )