@ -260,24 +260,24 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in
}
}
txid = txids [ utxoind ] ;
txid = txids [ utxoind ] ;
memset ( & spendtxid , 0 , sizeof ( spendtxid ) ) ;
memset ( & spendtxid , 0 , sizeof ( spendtxid ) ) ;
if ( bits256_nonz ( txid ) ! = 0 )
if ( bits256_nonz ( txid ) ! = 0 ) //&& sentflags[utxoind] != 0 )
{
{
destaddr [ 0 ] = 0 ;
destaddr [ 0 ] = 0 ;
spendtxid = LP_swap_spendtxid ( symbol , destaddr , txid , vout ) ;
spendtxid = LP_swap_spendtxid ( symbol , destaddr , txid , vout ) ;
if ( bits256_nonz ( spendtxid ) ! = 0 )
if ( bits256_nonz ( spendtxid ) ! = 0 )
{
{
sentflags [ utxoind ] = 1 ;
sentflags [ utxoind ] = 1 ;
printf ( " utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s) \n " , utxoind , aliceaddr , Adest , bobaddr , dest , destaddr ) ;
//printf(" utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s)\n",utxoind,aliceaddr,Adest,bobaddr,dest,destaddr);
if ( aliceaddr ! = 0 & & ( strcmp ( destaddr , aliceaddr ) = = 0 | | strcmp ( Adest , destaddr ) = = 0 ) )
if ( aliceaddr ! = 0 & & ( strcmp ( destaddr , aliceaddr ) = = 0 | | strcmp ( Adest , destaddr ) = = 0 ) )
{
{
printf ( " ALICE spent.(%s) -> %s \n " , bits256_str ( str , txid ) , destaddr ) ;
//printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr);
sentflags [ alicespent ] = 1 ;
sentflags [ alicespent ] = 1 ;
sentflags [ bobspent ] = 0 ;
sentflags [ bobspent ] = 0 ;
txids [ alicespent ] = spendtxid ;
txids [ alicespent ] = spendtxid ;
}
}
else if ( bobaddr ! = 0 & & ( strcmp ( destaddr , bobaddr ) = = 0 | | strcmp ( dest , destaddr ) = = 0 ) )
else if ( bobaddr ! = 0 & & ( strcmp ( destaddr , bobaddr ) = = 0 | | strcmp ( dest , destaddr ) = = 0 ) )
{
{
printf ( " BOB spent.(%s) -> %s \n " , bits256_str ( str , txid ) , destaddr ) ;
//printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr);
sentflags [ bobspent ] = 1 ;
sentflags [ bobspent ] = 1 ;
sentflags [ alicespent ] = 0 ;
sentflags [ alicespent ] = 0 ;
txids [ bobspent ] = spendtxid ;
txids [ bobspent ] = spendtxid ;
@ -298,7 +298,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in
txids [ alicespent ] = spendtxid ;
txids [ alicespent ] = spendtxid ;
}
}
}
}
} else printf ( " no spend of %s/v%d detected \n " , bits256_str ( str , txid ) , vout ) ;
} //else printf("no spend of %s/v%d detected\n",bits256_str(str,txid),vout);
} else printf ( " utxoind.%d null txid \n " , utxoind ) ;
} else printf ( " utxoind.%d null txid \n " , utxoind ) ;
return ( spendtxid ) ;
return ( spendtxid ) ;
}
}
@ -353,7 +353,7 @@ int32_t basilisk_swap_isfinished(int32_t iambob,bits256 *txids,int32_t *sentflag
{
{
if ( bits256_nonz ( txids [ BASILISK_BOBDEPOSIT ] ) = = 0 & & sentflags [ BASILISK_BOBDEPOSIT ] = = 0 )
if ( bits256_nonz ( txids [ BASILISK_BOBDEPOSIT ] ) = = 0 & & sentflags [ BASILISK_BOBDEPOSIT ] = = 0 )
return ( 1 ) ;
return ( 1 ) ;
else if ( bits256_nonz ( txids [ BASILISK_BOBPAYMENT ] ) = = 0 & & sentflags [ BASILISK_BOBPAYMENT ] = = 0 )
else if ( bits256_nonz ( txids [ BASILISK_BOBPAYMENT ] ) = = 0 | | sentflags [ BASILISK_BOBPAYMENT ] = = 0 )
{
{
if ( bits256_nonz ( depositspent ) ! = 0 )
if ( bits256_nonz ( depositspent ) ! = 0 )
return ( 1 ) ;
return ( 1 ) ;
@ -670,7 +670,7 @@ int32_t LP_refht_update(char *symbol,bits256 txid)
int32_t LP_swap_load ( struct LP_swap_remember * rswap )
int32_t LP_swap_load ( struct LP_swap_remember * rswap )
{
{
int32_t i , needflag , addflag ; long fsize ; char fname [ 1024 ] , str [ 65 ] , * fstr , * symbol , * rstr ; cJSON * txobj , * sentobj , * fileobj ; bits256 txid , checktxid ; uint64_t value ;
int32_t i , needflag , addflag ; long fsize ; char fname [ 1024 ] , * fstr , * symbol , * rstr ; cJSON * txobj , * sentobj , * fileobj ; bits256 txid , checktxid ; uint64_t value ;
rswap - > iambob = - 1 ;
rswap - > iambob = - 1 ;
sprintf ( fname , " %s/SWAPS/%u-%u.finished " , GLOBAL_DBDIR , rswap - > requestid , rswap - > quoteid ) , OS_compatible_path ( fname ) ;
sprintf ( fname , " %s/SWAPS/%u-%u.finished " , GLOBAL_DBDIR , rswap - > requestid , rswap - > quoteid ) , OS_compatible_path ( fname ) ;
if ( ( fstr = OS_filestr ( & fsize , fname ) ) ! = 0 )
if ( ( fstr = OS_filestr ( & fsize , fname ) ) ! = 0 )
@ -767,7 +767,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap)
}
}
free_json ( sentobj ) ;
free_json ( sentobj ) ;
}
}
printf ( " %s %s %.8f \n " , txnames [ i ] , bits256_str ( str , txid ) , dstr ( value ) ) ;
//printf("%s %s %.8f\n",txnames[i],bits256_str(str,txid),dstr(value));
}
}
}
}
} //else printf("no symbol\n");
} //else printf("no symbol\n");
@ -804,17 +804,19 @@ void LP_txbytes_update(char *name,char *symbol,char *txbytes,bits256 *txidp,bits
int32_t LP_rswap_checktx ( struct LP_swap_remember * rswap , char * symbol , int32_t txi )
int32_t LP_rswap_checktx ( struct LP_swap_remember * rswap , char * symbol , int32_t txi )
{
{
struct LP_transact io n * tx ; struct iguana_info * coin ; char str [ 65 ] ;
int32_t h t; struct iguana_info * coin ; //char str[65];
if ( rswap - > sentflags [ txi ] = = 0 & & bits256_nonz ( rswap - > txids [ txi ] ) ! = 0 )
if ( rswap - > sentflags [ txi ] = = 0 & & bits256_nonz ( rswap - > txids [ txi ] ) ! = 0 )
{
{
coin = LP_coinfind ( symbol ) ;
if ( ( coin = LP_coinfind ( symbol ) ) ! = 0 )
printf ( " [%s] %s txbytes.%p %s \n " , txnames [ txi ] , txnames [ txi ] , rswap - > txbytes [ txi ] , bits256_str ( str , rswap - > txids [ txi ] ) ) ;
{
if ( coin ! = 0 & & ( tx = LP_transactionfind ( coin , rswap - > txids [ txi ] ) ) ! = 0 & & tx - > height > 0 )
if ( ( ht = LP_txheight ( coin , rswap - > txids [ txi ] ) ) > 0 )
{
{
rswap - > sentflags [ txi ] = 1 ;
rswap - > sentflags [ txi ] = 1 ;
_LP_refht_update ( coin , rswap - > txids [ txi ] , tx - > heig ht) ;
_LP_refht_update ( coin , rswap - > txids [ txi ] , ht ) ;
} else LP_refht_update ( symbol , rswap - > txids [ txi ] ) ;
} else LP_refht_update ( symbol , rswap - > txids [ txi ] ) ;
//printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),ht);
}
}
} //else printf("sent.%d %s txi.%d\n",rswap->sentflags[txi],bits256_str(str,rswap->txids[txi]),txi);
return ( 0 ) ;
return ( 0 ) ;
}
}
@ -845,11 +847,12 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap)
cJSON * basilisk_remember ( int64_t * KMDtotals , int64_t * BTCtotals , uint32_t requestid , uint32_t quoteid )
cJSON * basilisk_remember ( int64_t * KMDtotals , int64_t * BTCtotals , uint32_t requestid , uint32_t quoteid )
{
{
static void * ctx ;
static void * ctx ;
struct LP_swap_remember rswap ; int32_t i , j , numspent , len , secretstart , redeemlen ; char str [ 65 ] , * srcAdest , * srcBdest , * destAdest , * destBdest , otheraddr [ 64 ] ; cJSON * item ; bits256 rev , signedtxid , zero ; struct iguana_info * bob = 0 , * alice = 0 ; uint8_t redeemscript [ 1024 ] , userdata [ 1024 ] ;
struct LP_swap_remember rswap ; int32_t i , j , flag , numspent , len , secretstart , redeemlen ; char str [ 65 ] , * srcAdest , * srcBdest , * destAdest , * destBdest , otheraddr [ 64 ] ; cJSON * item , * txoutobj ; bits256 rev , signedtxid , zero , deadtxid ; struct iguana_info * bob = 0 , * alice = 0 ; uint8_t redeemscript [ 1024 ] , userdata [ 1024 ] ;
if ( ctx = = 0 )
if ( ctx = = 0 )
ctx = bitcoin_ctx ( ) ;
ctx = bitcoin_ctx ( ) ;
if ( ( rswap . iambob = LP_rswap_init ( & rswap , requestid , quoteid ) ) < 0 )
if ( ( rswap . iambob = LP_rswap_init ( & rswap , requestid , quoteid ) ) < 0 )
return ( cJSON_Parse ( " { \" error \" : \" couldnt initialize rswap, are all coins active? \" } " ) ) ;
return ( cJSON_Parse ( " { \" error \" : \" couldnt initialize rswap, are all coins active? \" } " ) ) ;
decode_hex ( deadtxid . bytes , 32 , " deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef " ) ;
LP_swap_load ( & rswap ) ;
LP_swap_load ( & rswap ) ;
memset ( zero . bytes , 0 , sizeof ( zero ) ) ;
memset ( zero . bytes , 0 , sizeof ( zero ) ) ;
otheraddr [ 0 ] = 0 ;
otheraddr [ 0 ] = 0 ;
@ -925,7 +928,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
{
if ( rswap . sentflags [ BASILISK_BOBPAYMENT ] ! = 0 & & bits256_nonz ( rswap . paymentspent ) = = 0 )
if ( rswap . sentflags [ BASILISK_BOBPAYMENT ] ! = 0 & & bits256_nonz ( rswap . paymentspent ) = = 0 )
{
{
//if ( txbytes[BASILISK_ALICESPEND] == 0 )
if ( ( txoutobj = LP_gettxout ( rswap . bobcoin , rswap . bobpaymentaddr , rswap . txids [ BASILISK_BOBPAYMENT ] , 0 ) ) ! = 0 )
free_json ( txoutobj ) , flag = 0 ;
else flag = - 1 , rswap . paymentspent = deadtxid ;
if ( flag = = 0 )
{
{
if ( bits256_nonz ( rswap . txids [ BASILISK_BOBPAYMENT ] ) ! = 0 )
if ( bits256_nonz ( rswap . txids [ BASILISK_BOBPAYMENT ] ) ! = 0 )
{
{
@ -950,15 +956,18 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( ( rswap . txbytes [ BASILISK_ALICESPEND ] = basilisk_swap_bobtxspend ( & signedtxid , rswap . Btxfee , " alicespend " , rswap . bobcoin , bob - > wiftaddr , bob - > taddr , bob - > pubtype , bob - > p2shtype , bob - > isPoS , bob - > wiftype , ctx , rswap . myprivs [ 0 ] , 0 , redeemscript , redeemlen , userdata , len , rswap . txids [ BASILISK_BOBPAYMENT ] , 0 , 0 , rswap . pubkey33 , 1 , rswap . expiration , & rswap . values [ BASILISK_ALICESPEND ] , 0 , 0 , rswap . bobpaymentaddr , 1 ) ) ! = 0 )
if ( ( rswap . txbytes [ BASILISK_ALICESPEND ] = basilisk_swap_bobtxspend ( & signedtxid , rswap . Btxfee , " alicespend " , rswap . bobcoin , bob - > wiftaddr , bob - > taddr , bob - > pubtype , bob - > p2shtype , bob - > isPoS , bob - > wiftype , ctx , rswap . myprivs [ 0 ] , 0 , redeemscript , redeemlen , userdata , len , rswap . txids [ BASILISK_BOBPAYMENT ] , 0 , 0 , rswap . pubkey33 , 1 , rswap . expiration , & rswap . values [ BASILISK_ALICESPEND ] , 0 , 0 , rswap . bobpaymentaddr , 1 ) ) ! = 0 )
printf ( " alicespend.(%s) \n " , rswap . txbytes [ BASILISK_ALICESPEND ] ) ;
printf ( " alicespend.(%s) \n " , rswap . txbytes [ BASILISK_ALICESPEND ] ) ;
}
}
}
LP_txbytes_update ( " alicespend " , rswap . bobcoin , rswap . txbytes [ BASILISK_ALICESPEND ] , & rswap . txids [ BASILISK_ALICESPEND ] , & rswap . paymentspent , & rswap . sentflags [ BASILISK_ALICESPEND ] ) ;
LP_txbytes_update ( " alicespend " , rswap . bobcoin , rswap . txbytes [ BASILISK_ALICESPEND ] , & rswap . txids [ BASILISK_ALICESPEND ] , & rswap . paymentspent , & rswap . sentflags [ BASILISK_ALICESPEND ] ) ;
}
}
}
}
}
if ( rswap . sentflags [ BASILISK_ALICECLAIM ] = = 0 & & rswap . sentflags [ BASILISK_BOBDEPOSIT ] ! = 0 & & bits256_nonz ( rswap . txids [ BASILISK_BOBDEPOSIT ] ) ! = 0 & & bits256_nonz ( rswap . depositspent ) = = 0 )
if ( rswap . sentflags [ BASILISK_ALICECLAIM ] = = 0 & & rswap . sentflags [ BASILISK_BOBDEPOSIT ] ! = 0 & & bits256_nonz ( rswap . txids [ BASILISK_BOBDEPOSIT ] ) ! = 0 & & bits256_nonz ( rswap . depositspent ) = = 0 )
{
{
if ( time ( NULL ) > rswap . expiration )
if ( time ( NULL ) > rswap . expiration )
{
{
//if ( txbytes[BASILISK_ALICECLAIM] == 0 )
if ( ( txoutobj = LP_gettxout ( rswap . bobcoin , rswap . bobdepositaddr , rswap . txids [ BASILISK_BOBDEPOSIT ] , 0 ) ) ! = 0 )
free_json ( txoutobj ) , flag = 0 ;
else flag = - 1 , rswap . depositspent = deadtxid ;
if ( flag = = 0 )
{
{
if ( rswap . Dredeemlen ! = 0 )
if ( rswap . Dredeemlen ! = 0 )
redeemlen = rswap . Dredeemlen , memcpy ( redeemscript , rswap . Dredeemscript , rswap . Dredeemlen ) ;
redeemlen = rswap . Dredeemlen , memcpy ( redeemscript , rswap . Dredeemscript , rswap . Dredeemlen ) ;
@ -974,13 +983,16 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf ( " privBn.(%s) aliceclaim.(%s) \n " , bits256_str ( str , rswap . privBn ) , rswap . txbytes [ BASILISK_ALICECLAIM ] ) ;
printf ( " privBn.(%s) aliceclaim.(%s) \n " , bits256_str ( str , rswap . privBn ) , rswap . txbytes [ BASILISK_ALICECLAIM ] ) ;
}
}
}
}
}
LP_txbytes_update ( " aliceclaim " , rswap . bobcoin , rswap . txbytes [ BASILISK_ALICECLAIM ] , & rswap . txids [ BASILISK_ALICECLAIM ] , & rswap . depositspent , & rswap . sentflags [ BASILISK_ALICECLAIM ] ) ;
LP_txbytes_update ( " aliceclaim " , rswap . bobcoin , rswap . txbytes [ BASILISK_ALICECLAIM ] , & rswap . txids [ BASILISK_ALICECLAIM ] , & rswap . depositspent , & rswap . sentflags [ BASILISK_ALICECLAIM ] ) ;
}
} else printf ( " now %u before expiration %u \n " , ( uint32_t ) time ( NULL ) , rswap . expiration ) ;
} else printf ( " now %u before expiration %u \n " , ( uint32_t ) time ( NULL ) , rswap . expiration ) ;
}
}
if ( rswap . sentflags [ BASILISK_ALICEPAYMENT ] ! = 0 & & bits256_nonz ( rswap . Apaymentspent ) = = 0 & & rswap . sentflags [ BASILISK_ALICECLAIM ] = = 0 )
if ( rswap . sentflags [ BASILISK_ALICEPAYMENT ] ! = 0 & & bits256_nonz ( rswap . Apaymentspent ) = = 0 & & rswap . sentflags [ BASILISK_ALICECLAIM ] = = 0 )
{
{
//if ( txbytes[BASILISK_ALICERECLAIM] == 0 )
if ( ( txoutobj = LP_gettxout ( rswap . alicecoin , rswap . alicepaymentaddr , rswap . txids [ BASILISK_ALICEPAYMENT ] , 0 ) ) ! = 0 )
free_json ( txoutobj ) , flag = 0 ;
else flag = - 1 , rswap . Apaymentspent = deadtxid ;
if ( flag = = 0 )
{
{
rswap . privBn = basilisk_swap_privBn_extract ( & rswap . txids [ BASILISK_BOBREFUND ] , rswap . bobcoin , rswap . txids [ BASILISK_BOBDEPOSIT ] , rswap . privBn ) ;
rswap . privBn = basilisk_swap_privBn_extract ( & rswap . txids [ BASILISK_BOBREFUND ] , rswap . bobcoin , rswap . txids [ BASILISK_BOBDEPOSIT ] , rswap . privBn ) ;
if ( bits256_nonz ( rswap . txids [ BASILISK_ALICEPAYMENT ] ) ! = 0 & & bits256_nonz ( rswap . privAm ) ! = 0 & & bits256_nonz ( rswap . privBn ) ! = 0 )
if ( bits256_nonz ( rswap . txids [ BASILISK_ALICEPAYMENT ] ) ! = 0 & & bits256_nonz ( rswap . privAm ) ! = 0 & & bits256_nonz ( rswap . privBn ) ! = 0 )
@ -988,36 +1000,42 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( ( rswap . txbytes [ BASILISK_ALICERECLAIM ] = basilisk_swap_Aspend ( " alicereclaim " , rswap . alicecoin , rswap . Atxfee , alice - > wiftaddr , alice - > taddr , alice - > pubtype , alice - > p2shtype , alice - > isPoS , alice - > wiftype , ctx , rswap . privAm , rswap . privBn , rswap . txids [ BASILISK_ALICEPAYMENT ] , 0 , rswap . pubkey33 , rswap . expiration , & rswap . values [ BASILISK_ALICERECLAIM ] , rswap . alicepaymentaddr ) ) ! = 0 )
if ( ( rswap . txbytes [ BASILISK_ALICERECLAIM ] = basilisk_swap_Aspend ( " alicereclaim " , rswap . alicecoin , rswap . Atxfee , alice - > wiftaddr , alice - > taddr , alice - > pubtype , alice - > p2shtype , alice - > isPoS , alice - > wiftype , ctx , rswap . privAm , rswap . privBn , rswap . txids [ BASILISK_ALICEPAYMENT ] , 0 , rswap . pubkey33 , rswap . expiration , & rswap . values [ BASILISK_ALICERECLAIM ] , rswap . alicepaymentaddr ) ) ! = 0 )
printf ( " privBn.(%s) alicereclaim.(%s) \n " , bits256_str ( str , rswap . privBn ) , rswap . txbytes [ BASILISK_ALICERECLAIM ] ) ;
printf ( " privBn.(%s) alicereclaim.(%s) \n " , bits256_str ( str , rswap . privBn ) , rswap . txbytes [ BASILISK_ALICERECLAIM ] ) ;
}
}
}
LP_txbytes_update ( " alicereclaim " , rswap . alicecoin , rswap . txbytes [ BASILISK_ALICERECLAIM ] , & rswap . txids [ BASILISK_ALICERECLAIM ] , & rswap . Apaymentspent , & rswap . sentflags [ BASILISK_ALICERECLAIM ] ) ;
LP_txbytes_update ( " alicereclaim " , rswap . alicecoin , rswap . txbytes [ BASILISK_ALICERECLAIM ] , & rswap . txids [ BASILISK_ALICERECLAIM ] , & rswap . Apaymentspent , & rswap . sentflags [ BASILISK_ALICERECLAIM ] ) ;
}
}
}
}
}
else if ( rswap . iambob = = 1 )
else if ( rswap . iambob = = 1 )
{
{
if ( rswap . sentflags [ BASILISK_BOBSPEND ] = = 0 & & bits256_nonz ( rswap . Apaymentspent ) = = 0 )
if ( rswap . sentflags [ BASILISK_BOBSPEND ] = = 0 & & bits256_nonz ( rswap . Apaymentspent ) = = 0 )
{
{
printf ( " try to bobspend aspend.%s have privAm.%d \n " , bits256_str ( str , rswap . txids [ BASILISK_ALICESPEND ] ) , bits256_nonz ( rswap . privAm ) ) ;
//printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm));
if ( bits256_nonz ( rswap . txids [ BASILISK_ALICESPEND ] ) ! = 0 | | bits256_nonz ( rswap . privAm ) ! = 0 )
if ( bits256_nonz ( rswap . txids [ BASILISK_ALICESPEND ] ) ! = 0 | | bits256_nonz ( rswap . privAm ) ! = 0 )
{
{
//if ( txbytes[BASILISK_BOBSPEND] == 0 )
if ( ( txoutobj = LP_gettxout ( rswap . alicecoin , rswap . alicepaymentaddr , rswap . txids [ BASILISK_ALICEPAYMENT ] , 0 ) ) ! = 0 )
free_json ( txoutobj ) , flag = 0 ;
else flag = - 1 , rswap . Apaymentspent = deadtxid ;
if ( flag = = 0 )
{
{
if ( bits256_nonz ( rswap . privAm ) = = 0 )
if ( bits256_nonz ( rswap . privAm ) = = 0 )
{
{
rswap . privAm = basilisk_swap_privbob_extract ( rswap . bobcoin , rswap . txids [ BASILISK_ALICESPEND ] , 0 , 1 ) ;
rswap . privAm = basilisk_swap_privbob_extract ( rswap . bobcoin , rswap . txids [ BASILISK_ALICESPEND ] , 0 , 1 ) ;
printf ( " try to bobspend aspend.%s have privAm.%d \n " , bits256_str ( str , rswap . txids [ BASILISK_ALICESPEND ] ) , bits256_nonz ( rswap . privAm ) ) ;
//printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm));
}
}
if ( bits256_nonz ( rswap . privAm ) ! = 0 & & bits256_nonz ( rswap . privBn ) ! = 0 )
if ( bits256_nonz ( rswap . privAm ) ! = 0 & & bits256_nonz ( rswap . privBn ) ! = 0 )
{
{
if ( ( rswap . txbytes [ BASILISK_BOBSPEND ] = basilisk_swap_Aspend ( " bobspend " , rswap . alicecoin , rswap . Atxfee , alice - > wiftaddr , alice - > taddr , alice - > pubtype , alice - > p2shtype , alice - > isPoS , alice - > wiftype , ctx , rswap . privAm , rswap . privBn , rswap . txids [ BASILISK_ALICEPAYMENT ] , 0 , rswap . pubkey33 , rswap . expiration , & rswap . values [ BASILISK_BOBSPEND ] , rswap . alicepaymentaddr ) ) ! = 0 )
if ( ( rswap . txbytes [ BASILISK_BOBSPEND ] = basilisk_swap_Aspend ( " bobspend " , rswap . alicecoin , rswap . Atxfee , alice - > wiftaddr , alice - > taddr , alice - > pubtype , alice - > p2shtype , alice - > isPoS , alice - > wiftype , ctx , rswap . privAm , rswap . privBn , rswap . txids [ BASILISK_ALICEPAYMENT ] , 0 , rswap . pubkey33 , rswap . expiration , & rswap . values [ BASILISK_BOBSPEND ] , rswap . alicepaymentaddr ) ) ! = 0 )
printf ( " bobspend.(%s) \n " , rswap . txbytes [ BASILISK_BOBSPEND ] ) ;
printf ( " bobspend.(%s) \n " , rswap . txbytes [ BASILISK_BOBSPEND ] ) ;
}
}
}
LP_txbytes_update ( " bobspend " , rswap . alicecoin , rswap . txbytes [ BASILISK_BOBSPEND ] , & rswap . txids [ BASILISK_BOBSPEND ] , & rswap . Apaymentspent , & rswap . sentflags [ BASILISK_BOBSPEND ] ) ;
LP_txbytes_update ( " bobspend " , rswap . alicecoin , rswap . txbytes [ BASILISK_BOBSPEND ] , & rswap . txids [ BASILISK_BOBSPEND ] , & rswap . Apaymentspent , & rswap . sentflags [ BASILISK_BOBSPEND ] ) ;
}
}
}
}
if ( rswap . sentflags [ BASILISK_BOBRECLAIM ] = = 0 & & rswap . sentflags [ BASILISK_BOBPAYMENT ] ! = 0 & & bits256_nonz ( rswap . txids [ BASILISK_BOBPAYMENT ] ) ! = 0 & & time ( NULL ) > rswap . expiration & & bits256_nonz ( rswap . paymentspent ) = = 0 )
}
if ( rswap . sentflags [ BASILISK_BOBRECLAIM ] = = 0 & & rswap . sentflags [ BASILISK_BOBPAYMENT ] ! = 0 & & bits256_nonz ( rswap . txids [ BASILISK_BOBPAYMENT ] ) ! = 0 & & bits256_nonz ( rswap . paymentspent ) = = 0 )
{
{
//if ( txbytes[BASILISK_BOBRECLAIM] == 0 )
if ( ( txoutobj = LP_gettxout ( rswap . bobcoin , rswap . bobpaymentaddr , rswap . txids [ BASILISK_BOBPAYMENT ] , 0 ) ) ! = 0 )
free_json ( txoutobj ) , flag = 0 ;
else flag = - 1 , rswap . paymentspent = deadtxid ;
if ( flag = = 0 & & time ( NULL ) > rswap . expiration )
{
{
// bobreclaim
// bobreclaim
redeemlen = basilisk_swap_bobredeemscript ( 0 , & secretstart , redeemscript , rswap . plocktime , rswap . pubA0 , rswap . pubB0 , rswap . pubB1 , zero , rswap . privBn , rswap . secretAm , rswap . secretAm256 , rswap . secretBn , rswap . secretBn256 ) ;
redeemlen = basilisk_swap_bobredeemscript ( 0 , & secretstart , redeemscript , rswap . plocktime , rswap . pubA0 , rswap . pubB0 , rswap . pubB1 , zero , rswap . privBn , rswap . secretAm , rswap . secretAm256 , rswap . secretBn , rswap . secretBn256 ) ;
@ -1032,12 +1050,17 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf ( " secretAm, myprivs[1].(%s) bobreclaim.(%s) \n " , bits256_str ( str , rswap . myprivs [ 1 ] ) , rswap . txbytes [ BASILISK_BOBRECLAIM ] ) ;
printf ( " secretAm, myprivs[1].(%s) bobreclaim.(%s) \n " , bits256_str ( str , rswap . myprivs [ 1 ] ) , rswap . txbytes [ BASILISK_BOBRECLAIM ] ) ;
}
}
}
}
}
LP_txbytes_update ( " bobreclaim " , rswap . bobcoin , rswap . txbytes [ BASILISK_BOBRECLAIM ] , & rswap . txids [ BASILISK_BOBRECLAIM ] , & rswap . paymentspent , & rswap . sentflags [ BASILISK_BOBRECLAIM ] ) ;
LP_txbytes_update ( " bobreclaim " , rswap . bobcoin , rswap . txbytes [ BASILISK_BOBRECLAIM ] , & rswap . txids [ BASILISK_BOBRECLAIM ] , & rswap . paymentspent , & rswap . sentflags [ BASILISK_BOBRECLAIM ] ) ;
}
}
else if ( flag = = 0 )
printf ( " bobpayment: now.%u < expiration %u \n " , ( uint32_t ) time ( NULL ) , rswap . expiration ) ;
}
if ( rswap . sentflags [ BASILISK_BOBREFUND ] = = 0 & & rswap . sentflags [ BASILISK_BOBDEPOSIT ] ! = 0 & & bits256_nonz ( rswap . txids [ BASILISK_BOBDEPOSIT ] ) ! = 0 & & bits256_nonz ( rswap . depositspent ) = = 0 )
if ( rswap . sentflags [ BASILISK_BOBREFUND ] = = 0 & & rswap . sentflags [ BASILISK_BOBDEPOSIT ] ! = 0 & & bits256_nonz ( rswap . txids [ BASILISK_BOBDEPOSIT ] ) ! = 0 & & bits256_nonz ( rswap . depositspent ) = = 0 )
{
{
if ( bits256_nonz ( rswap . Apaymentspent ) ! = 0 | | time ( NULL ) > rswap . expiration )
if ( ( txoutobj = LP_gettxout ( rswap . bobcoin , rswap . bobdepositaddr , rswap . txids [ BASILISK_BOBDEPOSIT ] , 0 ) ) ! = 0 )
free_json ( txoutobj ) , flag = 0 ;
else flag = - 1 , rswap . depositspent = deadtxid ;
if ( flag = = 0 & & ( bits256_nonz ( rswap . Apaymentspent ) ! = 0 | | time ( NULL ) > rswap . expiration ) )
{
{
printf ( " do the refund! paymentspent.%s now.%u vs expiration.%u \n " , bits256_str ( str , rswap . paymentspent ) , ( uint32_t ) time ( NULL ) , rswap . expiration ) ;
printf ( " do the refund! paymentspent.%s now.%u vs expiration.%u \n " , bits256_str ( str , rswap . paymentspent ) , ( uint32_t ) time ( NULL ) , rswap . expiration ) ;
//if ( txbytes[BASILISK_BOBREFUND] == 0 )
//if ( txbytes[BASILISK_BOBREFUND] == 0 )
@ -1050,7 +1073,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf ( " pubB1.(%s) bobrefund.(%s) \n " , bits256_str ( str , rswap . pubB1 ) , rswap . txbytes [ BASILISK_BOBREFUND ] ) ;
printf ( " pubB1.(%s) bobrefund.(%s) \n " , bits256_str ( str , rswap . pubB1 ) , rswap . txbytes [ BASILISK_BOBREFUND ] ) ;
}
}
LP_txbytes_update ( " bobrefund " , rswap . bobcoin , rswap . txbytes [ BASILISK_BOBREFUND ] , & rswap . txids [ BASILISK_BOBREFUND ] , & rswap . depositspent , & rswap . sentflags [ BASILISK_BOBREFUND ] ) ;
LP_txbytes_update ( " bobrefund " , rswap . bobcoin , rswap . txbytes [ BASILISK_BOBREFUND ] , & rswap . txids [ BASILISK_BOBREFUND ] , & rswap . depositspent , & rswap . sentflags [ BASILISK_BOBREFUND ] ) ;
} else printf ( " bobrefund's time %u vs expiration %u \n " , ( uint32_t ) time ( NULL ) , rswap . expiration ) ;
}
else if ( flag = = 0 )
printf ( " bobrefund's time %u vs expiration %u \n " , ( uint32_t ) time ( NULL ) , rswap . expiration ) ;
}
}
}
}
}
}
@ -1064,7 +1089,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
for ( i = 0 ; i < sizeof ( txnames ) / sizeof ( * txnames ) ; i + + )
for ( i = 0 ; i < sizeof ( txnames ) / sizeof ( * txnames ) ; i + + )
if ( bits256_nonz ( rswap . txids [ i ] ) ! = 0 & & rswap . values [ i ] = = 0 )
if ( bits256_nonz ( rswap . txids [ i ] ) ! = 0 & & rswap . values [ i ] = = 0 )
rswap . values [ i ] = basilisk_txvalue ( basilisk_isbobcoin ( rswap . iambob , i ) ? rswap . bobcoin : rswap . alicecoin , rswap . txids [ i ] , 0 ) ;
rswap . values [ i ] = basilisk_txvalue ( basilisk_isbobcoin ( rswap . iambob , i ) ? rswap . bobcoin : rswap . alicecoin , rswap . txids [ i ] , 0 ) ;
if ( rswap . origfinishedflag = = 0 )
if ( 0 & & rswap . origfinishedflag = = 0 )
{
{
printf ( " iambob.%d Apaymentspent.(%s) alice.%d bob.%d %s %.8f \n " , rswap . iambob , bits256_str ( str , rswap . Apaymentspent ) , rswap . sentflags [ BASILISK_ALICERECLAIM ] , rswap . sentflags [ BASILISK_BOBSPEND ] , rswap . alicecoin , dstr ( rswap . values [ BASILISK_ALICEPAYMENT ] ) ) ;
printf ( " iambob.%d Apaymentspent.(%s) alice.%d bob.%d %s %.8f \n " , rswap . iambob , bits256_str ( str , rswap . Apaymentspent ) , rswap . sentflags [ BASILISK_ALICERECLAIM ] , rswap . sentflags [ BASILISK_BOBSPEND ] , rswap . alicecoin , dstr ( rswap . values [ BASILISK_ALICEPAYMENT ] ) ) ;
printf ( " paymentspent.(%s) alice.%d bob.%d %s %.8f \n " , bits256_str ( str , rswap . paymentspent ) , rswap . sentflags [ BASILISK_ALICESPEND ] , rswap . sentflags [ BASILISK_BOBRECLAIM ] , rswap . bobcoin , dstr ( rswap . values [ BASILISK_BOBPAYMENT ] ) ) ;
printf ( " paymentspent.(%s) alice.%d bob.%d %s %.8f \n " , bits256_str ( str , rswap . paymentspent ) , rswap . sentflags [ BASILISK_ALICESPEND ] , rswap . sentflags [ BASILISK_BOBRECLAIM ] , rswap . bobcoin , dstr ( rswap . values [ BASILISK_BOBPAYMENT ] ) ) ;