Browse Source

Test

etomic
jl777 7 years ago
parent
commit
4a5f034933
  1. 15
      iguana/exchanges/LP_cache.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 10
      iguana/exchanges/LP_transaction.c

15
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);
}

1
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

10
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; i<n; i++)
@ -602,7 +601,6 @@ 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 )
@ -1004,7 +1002,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_
char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime)
{
static void *ctx;
cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[64],spendscript[256]; char *coinaddr,*rawtxbytes; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[1024]; struct LP_address *ap;
cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[64],spendscript[256]; char *coinaddr,*rawtxbytes; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS]; struct LP_address *ap;
if ( ctx == 0 )
ctx = bitcoin_ctx();
*numvinsp = 0;
@ -1143,7 +1141,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
safecopy(changeaddr,coin->smartaddr,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++)
{

Loading…
Cancel
Save