Browse Source

SPV to detect spent unconfirmed

jl777
jl777 7 years ago
parent
commit
5efa94623e
  1. 2
      iguana/exchanges/LP_include.h
  2. 6
      iguana/exchanges/LP_scan.c
  3. 18
      iguana/exchanges/LP_transaction.c

2
iguana/exchanges/LP_include.h

@ -559,7 +559,7 @@ char *LP_unspents_filestr(char *symbol,char *addr);
cJSON *bitcoin_data2json(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash);
//int32_t LP_butxo_findeither(bits256 txid,int32_t vout);
cJSON *LP_listunspent(char *symbol,char *coinaddr,bits256 reftxid,bits256 reftxid2);
int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid);
int32_t LP_gettx_presence(int32_t *numconfirmsp,char *symbol,bits256 expectedtxid,char *coinaddr);
double LP_getestimatedrate(struct iguana_info *coin);
struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout);
struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid,int32_t vout);

6
iguana/exchanges/LP_scan.c

@ -448,7 +448,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid)
int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration)
{
struct iguana_info *coin; bits256 zero; cJSON *array,*item; uint32_t expiration,i,n; int32_t numconfirms = -1;
struct iguana_info *coin; bits256 zero; cJSON *array,*item; uint32_t expiration,i,n; int32_t num,numconfirms = -1;
if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 )
{
printf("LP_waitmempool missing coin.%p or inactive\n",coin);
@ -457,8 +457,8 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int
expiration = (uint32_t)time(NULL) + duration;
while ( LP_STOP_RECEIVED == 0 )
{
if ( LP_gettx_presence(symbol,txid) != 0 )
numconfirms = 0;
if ( LP_gettx_presence(&num,symbol,txid,coinaddr) != 0 )
numconfirms = num;
else
{
if ( coin->electrum == 0 )

18
iguana/exchanges/LP_transaction.c

@ -60,15 +60,25 @@ bits256 LP_pubkey(bits256 privkey)
return(pubkey);
}
int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid)
int32_t LP_gettx_presence(int32_t *numconfirmsp,char *symbol,bits256 expectedtxid,char *coinaddr)
{
cJSON *txobj; bits256 txid; int32_t flag = 0;
cJSON *txobj,*retjson; bits256 txid; struct iguana_info *coin; int32_t flag = 0;
if ( numconfirmsp != 0 )
*numconfirmsp = -1;
if ( (txobj= LP_gettx(symbol,expectedtxid,0)) != 0 )
{
txid = jbits256(txobj,"txid");
if ( jobj(txobj,"error") == 0 && bits256_cmp(txid,expectedtxid) == 0 )
{
//char str[65]; printf("%s already in gettx (%s)\n",bits256_str(str,txid),jprint(txobj,0));
if ( numconfirmsp != 0 && coinaddr != 0 && (coin= LP_coinfind(symbol)) != 0 && coin->electrum != 0 )
{
char str[65]; printf("%s %s already in gettx (%s)\n",coinaddr,bits256_str(str,txid),jprint(txobj,0));
if ( (retjson= electrum_address_gethistory(symbol,coin->electrum,&retjson,coinaddr,expectedtxid)) != 0 )
{
printf("got history\n");
free_json(retjson);
}
}
flag = 1;
}
free_json(txobj);
@ -94,7 +104,7 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi
for (i=0; i<2; i++)
{
//char str[65]; printf("LP_broadcast.%d (%s) %s i.%d sentflag.%d\n",i,symbol,bits256_str(str,expectedtxid),i,sentflag);
if ( sentflag == 0 && LP_gettx_presence(symbol,expectedtxid) != 0 )
if ( sentflag == 0 && LP_gettx_presence(0,symbol,expectedtxid,0) != 0 )
sentflag = 1;
if ( sentflag == 0 && (retstr= LP_sendrawtransaction(symbol,txbytes)) != 0 )
{

Loading…
Cancel
Save