diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 0786d81d3..623b61dfc 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -261,7 +261,7 @@ struct basilisk_swap }; -void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint8_t *data,int32_t datalen,int32_t vout); +void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t vout); void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx); uint32_t basilisk_requestid(struct basilisk_request *rp); uint32_t basilisk_quoteid(struct basilisk_request *rp); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index c21a65dce..373d11ca1 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -47,7 +47,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx fprintf(fp,"\",\"txid\":\"%s\"",bits256_str(str,bits256_doublesha256(0,rawtx->txbytes,rawtx->I.datalen))); if ( rawtx == &swap->bobdeposit || rawtx == &swap->bobpayment ) { - LP_swap_coinaddr(&swap->bobcoin,coinaddr,rawtx->txbytes,rawtx->I.datalen,0); + LP_swap_coinaddr(&swap->bobcoin,coinaddr,0,rawtx->txbytes,rawtx->I.datalen,0); if ( coinaddr[0] != 0 ) { LP_importaddress(swap->bobcoin.symbol,coinaddr); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d5051a47c..f68a89f96 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -266,7 +266,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) { - char buf[128],str[65],coinaddr[64],*hexstr; uint8_t *serialized; cJSON *item,*array,*listjson,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; + char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*listjson,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); @@ -286,7 +286,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) len >>= 1; serialized = malloc(len); decode_hex(serialized,len,hexstr); - LP_swap_coinaddr(coin,coinaddr,serialized,len,0); + LP_swap_coinaddr(coin,coinaddr,&value,serialized,len,0); if ( (listjson= electrum_address_listunspent(coin->symbol,0,0,coinaddr)) != 0 ) { if ( (array= jarray(&n,listjson,"result")) != 0 ) @@ -299,9 +299,33 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) if ( v == vout && bits256_cmp(t,txid) == 0 ) { retjson = cJSON_CreateObject(); + /*{ + "bestblock": "002f7bbe3973b735f535d472501962e86ce8dbc76c73ac5a310a905931b907fa", + "confirmations": 7, + "value": 2013.10431750, + "scriptPubKey": { + "asm": "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828 OP_CHECKSIG", + "hex": "2103b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828ac", + "reqSigs": 1, + "type": "pubkey", + "addresses": [ + "RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc" + ] + }, + "version": 1, + "coinbase": false + }*/ + jaddnum(retjson,"value",dstr(value)); jaddbits256(retjson,"txid",t); jaddnum(retjson,"vout",v); - jaddstr(retjson,"address",coinaddr); + addresses = cJSON_CreateArray(); + jaddistr(addresses,coinaddr); + sobj = cJSON_CreateObject(); + jaddnum(sobj,"reqSigs",1); + jaddstr(sobj,"type","pubkey"); + jadd(sobj,"addresses",addresses); + jadd(retjson,"scriptPubkey",sobj); + printf("GETTXOUT.(%s)\n",jprint(retjson,0)); break; } } diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 4d0812a40..968851e3f 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -125,7 +125,7 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf if ( n > 1 ) printf("LP_txinterestvalue warning: violation of 1 output assumption n.%d\n",n); } else printf("LP_txinterestvalue no addresses found?\n"); - //char str[65]; printf("%s %.8f <- %s.(%s) txobj.(%s)\n",destaddr,dstr(value),coin->symbol,bits256_str(str,txid),jprint(txobj,0)); + char str[65]; printf("%s %.8f <- %s.(%s) txobj.(%s)\n",destaddr,dstr(value),coin->symbol,bits256_str(str,txid),jprint(txobj,0)); free_json(txobj); } //else { char str[65]; printf("null gettxout return %s/v%d\n",bits256_str(str,txid),vout); } return(value); diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 860ed0459..c4a95969e 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -533,7 +533,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba printf("%02x",rawtx->redeemscript[i]); bitcoin_address(redeemaddr,rawtx->coin->taddr,rawtx->coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen); printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,rawtx->coin->symbol,rawtx->coin->taddr); - LP_swap_coinaddr(rawtx->coin,checkaddr,data,datalen,0); + LP_swap_coinaddr(rawtx->coin,checkaddr,0,data,datalen,0); if ( strcmp(redeemaddr,checkaddr) != 0 ) { printf("REDEEMADDR MISMATCH??? %s != %s\n",redeemaddr,checkaddr); @@ -592,7 +592,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba if ( rawtx == &swap->otherfee ) { char str[65]; - LP_swap_coinaddr(rawtx->coin,rawtx->p2shaddr,data,datalen,0); + LP_swap_coinaddr(rawtx->coin,rawtx->p2shaddr,0,data,datalen,0); printf("got %s txid.%s (%s) -> %s\n",rawtx->name,bits256_str(str,rawtx->I.signedtxid),jprint(txobj,0),rawtx->p2shaddr); } else bitcoin_address(rawtx->p2shaddr,rawtx->coin->taddr,rawtx->coin->p2shtype,rawtx->spendscript,hexlen); } diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index d96adc219..2374379c7 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1160,15 +1160,22 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) return(-1); } -void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint8_t *data,int32_t datalen,int32_t v) +void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t v) { cJSON *txobj,*vouts,*vout,*addresses,*item,*skey; uint8_t extraspace[8192]; bits256 signedtxid; struct iguana_msgtx msgtx; char *addr; int32_t n,m,suppress_pubkeys = 0; + if ( valuep != 0 ) + *valuep = 0; if ( (txobj= bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->longestchain,&signedtxid,&msgtx,extraspace,sizeof(extraspace),data,datalen,0,suppress_pubkeys)) != 0 ) { //char str[65]; printf("got txid.%s (%s)\n",bits256_str(str,signedtxid),jprint(txobj,0)); if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n > 0 ) { vout = jitem(vouts,v); + if ( valuep != 0 ) + { + if ( (*valuep= SATOSHIDEN * jdouble(vout,"value")) == 0 ) + *valuep= SATOSHIDEN * jdouble(vout,"amount"); + } //printf("VOUT.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) { @@ -1217,7 +1224,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i printf("%02x",swap->bobpayment.redeemscript[j]); printf(" <- redeem.%d\n",swap->bobpayment.I.redeemlen); printf(" <- GENERATED BOB PAYMENT.%d destaddr.(%s)\n",swap->bobpayment.I.datalen,swap->bobpayment.I.destaddr); - LP_swap_coinaddr(&swap->bobcoin,checkaddr,swap->bobpayment.txbytes,swap->bobpayment.I.datalen,0); + LP_swap_coinaddr(&swap->bobcoin,checkaddr,0,swap->bobpayment.txbytes,swap->bobpayment.I.datalen,0); if ( strcmp(swap->bobpayment.I.destaddr,checkaddr) != 0 ) { printf("BOBPAYMENT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobpayment.I.destaddr,checkaddr); @@ -1251,7 +1258,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i for (j=0; jbobdeposit.I.datalen; j++) printf("%02x",swap->bobdeposit.txbytes[j]); printf(" <- GENERATED BOB DEPOSIT.%d (%s)\n",swap->bobdeposit.I.datalen,swap->bobdeposit.I.destaddr); - LP_swap_coinaddr(&swap->bobcoin,checkaddr,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen,0); + LP_swap_coinaddr(&swap->bobcoin,checkaddr,0,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen,0); if ( strcmp(swap->bobdeposit.I.destaddr,checkaddr) != 0 ) { printf("BOBDEPOSIT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobdeposit.I.destaddr,checkaddr);