From c0c36f2076ad4964daddcbaf8e0a268f2933d142 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 12:45:44 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_cache.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 3 +-- iguana/exchanges/LP_ordermatch.c | 15 ++++++++++++++- iguana/exchanges/LP_rpc.c | 4 ++-- iguana/exchanges/LP_socket.c | 21 ++++++++++++++++++--- iguana/exchanges/LP_transaction.c | 2 +- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index fdc734fe9..fbce9ddff 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -235,7 +235,7 @@ int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_i return(0); if ( (tx= LP_transactionfind(coin,txid)) == 0 && strcmp(coinaddr,coin->smartaddr) == 0 ) { - if ( (retjson= electrum_transaction(coin->symbol,ep,&retjson,txid)) != 0 ) + if ( (retjson= electrum_transaction(coin->symbol,ep,&retjson,txid,0)) != 0 ) free_json(retjson); } if ( tx != 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6edb2f03d..3ca6cb879 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,11 +17,10 @@ // LP_nativeDEX.c // marketmaker // +// destpubkey // if ( G.LP_pendingswaps != 0 ) return(-1); // bot safe to exit? -// 324744 and 50mb // BCH signing -// single utxo allocations alice // alice waiting for bestprice // // previously, it used to show amount, kmd equiv, perc diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 60de857a8..7e440d990 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -746,10 +746,23 @@ int32_t LP_aliceonly(char *symbol) int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout) { - struct electrum_info *ep,*backupep; struct LP_address_utxo *up; struct iguana_info *coin; + struct electrum_info *ep,*backupep; cJSON *txobj; struct LP_address_utxo *up; struct iguana_info *coin; struct LP_transaction *tx; coin = LP_coinfind(symbol); if ( coin != 0 && (ep= coin->electrum) != 0 ) { + if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) == 0 ) + { + if ( (txobj= electrum_transaction(symbol,ep,&txobj,txid,coinaddr)) != 0 ) + free_json(txobj); + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + { + if ( vout < tx->numvouts && tx->height > 0 ) + LP_address_utxoadd((uint32_t)time(NULL),"LP_validSPV",coin,coinaddr,txid,vout,tx->outpoints[vout].value,tx->height,-1); + if ( tx->SPV <= 0 ) + return(-1); + return(0); + } + } if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) { if ( up->SPV < 0 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 11924e51c..8639646ee 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -429,7 +429,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else { - if ( (retjson= electrum_transaction(symbol,coin->electrum,&retjson,txid)) != 0 ) + if ( (retjson= electrum_transaction(symbol,coin->electrum,&retjson,txid,0)) != 0 ) return(retjson); else printf("failed blockchain.transaction.get %s %s\n",coin->symbol,bits256_str(str,txid)); return(cJSON_Parse("{\"error\":\"no transaction bytes\"}")); @@ -507,7 +507,7 @@ cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout) } if ( coinaddr[0] == 0 ) { - if ( (txobj= electrum_transaction(symbol,coin->electrum,&txobj,txid)) != 0 ) + if ( (txobj= electrum_transaction(symbol,coin->electrum,&txobj,txid,0)) != 0 ) { if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n > 0 ) LP_destaddr(coinaddr,jitem(vouts,vout)); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 723a61a92..f1a895b38 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -742,12 +742,27 @@ cJSON *_electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjs return(*retjsonp); } -cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) +cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,char *SPVcheck) { - cJSON *retjson; + cJSON *retjson,*array; struct LP_transaction *tx; struct iguana_info *coin; + coin = LP_coinfind(symbol); if ( ep != 0 ) portable_mutex_lock(&ep->txmutex); retjson = _electrum_transaction(symbol,ep,retjsonp,txid); + if ( ep != 0 && coin != 0 && SPVcheck != 0 && SPVcheck[0] != 0 && (tx= LP_transactionfind(coin,txid)) != 0 ) + { + if ( tx->height <= 0 ) + { + if ( (array= electrum_address_listunspent(symbol,ep,&array,SPVcheck,2)) != 0 ) + { + printf("SPVcheck.%s got %d unspents\n",SPVcheck,cJSON_GetArraySize(array)); + free_json(array); + } + } + if ( tx->height > 0 ) + tx->SPV = LP_merkleproof(coin,SPVcheck,ep,txid,tx->height); + char str[65]; printf("%s %s %s SPV height %d SPV %d\n",coin->symbol,SPVcheck,bits256_str(str,txid),tx->height,tx->SPV); + } if ( ep != 0 ) portable_mutex_unlock(&ep->txmutex); return(retjson); @@ -789,7 +804,7 @@ void electrum_test() decode_hex(hash.bytes,sizeof(hash),"b967a7d55889fe11e993430921574ec6379bc8ce712a652c3fcb66c6be6e925c"); if ( (retjson= electrum_getmerkle(symbol,ep,0,hash,403000)) != 0 ) printf("electrum_getmerkle %s\n",jprint(retjson,1)); - if ( (retjson= electrum_transaction(symbol,ep,0,hash)) != 0 ) + if ( (retjson= electrum_transaction(symbol,ep,0,hash,0)) != 0 ) printf("electrum_transaction %s\n",jprint(retjson,1)); addr = "14NeevLME8UAANiTCVNgvDrynUPk1VcQKb"; if ( (retjson= electrum_address_gethistory(symbol,ep,0,addr)) != 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index f90a87170..133ee6c41 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -118,7 +118,7 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi } else if ( (errstr= jstr(retjson,"error")) != 0 && strcmp(errstr,"timeout") == 0 && coin != 0 && coin->electrum != 0 ) { - if ( totalretries < 10 ) + if ( totalretries < 4 ) { printf("time error with electrum, retry.%d\n",totalretries); totalretries++;