diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index 18ed73f16..c66957bd1 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -85,7 +85,7 @@ cJSON *LP_create_transaction(struct iguana_info *coin,bits256 txid,uint8_t *seri return(txobj); } -void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t height) +void LP_SPV_store(struct iguana_info *coin,bits256 txid,int32_t height) { FILE *fp; char fname[512]; struct LP_transaction *tx = 0; if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 && tx->len > 0 ) @@ -223,7 +223,7 @@ bits256 LP_merkleroot(struct iguana_info *coin,struct electrum_info *ep,int32_t return(merkleroot); } -int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height) +int32_t LP_merkleproof(struct iguana_info *coin,struct electrum_info *ep,bits256 txid,int32_t height) { 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 ) @@ -244,7 +244,7 @@ int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_i SPV = height; if ( tx != 0 ) tx->SPV = height; - LP_SPV_store(coin,coinaddr,txid,height); + LP_SPV_store(coin,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)); } else printf("ERROR MERK %s ht.%d -> %s root.(%s) vs %s\n",bits256_str(str,txid),height,jprint(merkobj,0),bits256_str(str2,roothash),bits256_str(str3,merkleroot)); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 08f82f182..2003f3a06 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -371,6 +371,19 @@ struct LP_pubkeyinfo uint8_t rmd160[20],sig[65],pubsecp[33],siglen; }; +struct electrum_info +{ + queue_t sendQ,pendingQ; + portable_mutex_t mutex,txmutex; + struct electrum_info *prev; + int32_t bufsize,sock,*heightp,numerrors; + struct iguana_info *coin; + uint32_t stratumid,lasttime,keepalive,pending,*heighttimep; + char ipaddr[64],symbol[16]; + uint16_t port; + uint8_t buf[]; +}; + int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item); int32_t LP_pubkey_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp); int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson); @@ -410,6 +423,7 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha struct iguana_info *LP_coinfind(char *symbol); int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32); char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price); +int32_t LP_merkleproof(struct iguana_info *coin,struct electrum_info *ep,bits256 txid,int32_t height); struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins); void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid); uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9ab94a382..49eca0745 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -524,7 +524,7 @@ void LP_coinsloop(void *_coins) if ( up->SPV == 0 ) { nonz++; - up->SPV = LP_merkleproof(coin,ap->coinaddr,backupep,up->U.txid,up->U.height); + up->SPV = LP_merkleproof(coin,backupep,up->U.txid,up->U.height); if ( 0 && up->SPV > 0 ) printf("%s %s: SPV.%d\n",coin->symbol,bits256_str(str,up->U.txid),up->SPV); } @@ -535,7 +535,7 @@ void LP_coinsloop(void *_coins) oldht = up->U.height; LP_txheight_check(coin,ap->coinaddr,up); if ( oldht != up->U.height ) - up->SPV = LP_merkleproof(coin,ap->coinaddr,backupep,up->U.txid,up->U.height); + up->SPV = LP_merkleproof(coin,backupep,up->U.txid,up->U.height); if ( up->SPV <= 0 ) up->SPV = -2; else printf("%s %s: corrected SPV.%d\n",coin->symbol,bits256_str(str,up->U.txid),up->SPV); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index fb5761d86..c04beef58 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -647,7 +647,7 @@ int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout) return(-1); if ( (backupep= ep->prev) == 0 ) backupep = ep; - up->SPV = LP_merkleproof(coin,coinaddr,backupep,up->U.txid,up->U.height); + up->SPV = LP_merkleproof(coin,backupep,up->U.txid,up->U.height); if ( up->SPV <= 0 ) return(-1); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 9c816046a..c06101f1a 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -238,18 +238,7 @@ int32_t LP_socketrecv(int32_t sock,uint8_t *recvbuf,int32_t maxlen) return(recvlen); } -struct electrum_info -{ - queue_t sendQ,pendingQ; - portable_mutex_t mutex,txmutex; - struct electrum_info *prev; - int32_t bufsize,sock,*heightp,numerrors; - struct iguana_info *coin; - uint32_t stratumid,lasttime,keepalive,pending,*heighttimep; - char ipaddr[64],symbol[16]; - uint16_t port; - uint8_t buf[]; -} *Electrums[8192]; +struct electrum_info *Electrums[8192]; int32_t Num_electrums; struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) @@ -750,12 +739,17 @@ cJSON *_electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjs cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { - cJSON *retjson; + cJSON *retjson; struct iguana_info *coin; struct LP_transaction *tx; if ( ep != 0 ) portable_mutex_lock(&ep->txmutex); retjson = _electrum_transaction(symbol,ep,retjsonp,txid); if ( ep != 0 ) portable_mutex_unlock(&ep->txmutex); + if ( ep != 0 && (coin= LP_coinfind(symbol)) != 0 && (tx= LP_transactionfind(coin,txid)) != 0 && tx->height > 0 && tx->SPV <= 0 ) + { + LP_merkleproof(coin,ep,txid,tx->height); + printf("extra merkle\n"); + } return(retjson); }