Browse Source

Enable auto spend

jl777
jl777 7 years ago
parent
commit
3c6136ad29
  1. 31
      iguana/exchanges/LP_instantdex.c
  2. 2
      iguana/exchanges/LP_rpc.c

31
iguana/exchanges/LP_instantdex.c

@ -155,6 +155,19 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid)
LP_instantdex_filescreate(coinaddr); LP_instantdex_filescreate(coinaddr);
} }
uint32_t LP_claimtime(struct iguana_info *coin,uint32_t expiration)
{
uint32_t heighttime,now = (uint32_t)time(NULL);
if ( coin->height > 8 )
{
heighttime = LP_heighttime(coin->symbol,coin->height-8);
printf("claimtime: now %u height.%d heighttime.%u expiration.%u\n",now,coin->height,heighttime,expiration);
if ( heighttime >= expiration )
return(heighttime + 1);
}
return(0);
}
int32_t LP_deposit_addr(char *symbol,char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2shtype,uint32_t timestamp,uint8_t *pubsecp33) int32_t LP_deposit_addr(char *symbol,char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2shtype,uint32_t timestamp,uint8_t *pubsecp33)
{ {
uint8_t elsepub33[33],p2sh_rmd160[20]; int32_t n; uint8_t elsepub33[33],p2sh_rmd160[20]; int32_t n;
@ -285,19 +298,6 @@ int64_t LP_claimtx(void *ctx,struct iguana_info *coin,bits256 *claimtxidp,bits25
return(sum); return(sum);
} }
uint32_t LP_claimtime(struct iguana_info *coin,uint32_t expiration)
{
uint32_t heighttime,now = (uint32_t)time(NULL);
if ( coin->height > 8 )
{
heighttime = LP_heighttime(coin->symbol,coin->height-8);
printf("claimtime: now %u height.%d heighttime.%u expiration.%u\n",now,coin->height,heighttime,expiration);
if ( heighttime >= expiration )
return(heighttime + 1);
}
return(0);
}
char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid) char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
{ {
cJSON *txjson,*vouts,*vout0,*opret,*sobj,*retjson; uint16_t utxovout; char *signedtx,*opretstr,vinaddr[64],destaddr[64]; uint32_t expiration,claimtime; uint8_t redeemscript[128]; bits256 signedtxid,sendtxid; int32_t numvouts,redeemlen; int64_t satoshis,destamount; struct iguana_info *coin; cJSON *txjson,*vouts,*vout0,*opret,*sobj,*retjson; uint16_t utxovout; char *signedtx,*opretstr,vinaddr[64],destaddr[64]; uint32_t expiration,claimtime; uint8_t redeemscript[128]; bits256 signedtxid,sendtxid; int32_t numvouts,redeemlen; int64_t satoshis,destamount; struct iguana_info *coin;
@ -340,10 +340,10 @@ char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
jaddnum(retjson,"claimtime",claimtime); jaddnum(retjson,"claimtime",claimtime);
if ( claimtime > expiration && strcmp(destaddr,coin->smartaddr) == 0 ) if ( claimtime > expiration && strcmp(destaddr,coin->smartaddr) == 0 )
{ {
char str[65]; printf("LP_timespend satoshis %.8f %s/v%d\n",dstr(satoshis - coin->txfee),bits256_str(str,utxotxid),utxovout); char str[65]; //printf("LP_timespend satoshis %.8f %s/v%d\n",dstr(satoshis - coin->txfee),bits256_str(str,utxotxid),utxovout);
if ( (signedtx= basilisk_swap_bobtxspend(&signedtxid,coin->txfee,"timespend",coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript+2,redeemlen-2,0,0,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,0,coin->zcash)) != 0 ) if ( (signedtx= basilisk_swap_bobtxspend(&signedtxid,coin->txfee,"timespend",coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript+2,redeemlen-2,0,0,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,0,coin->zcash)) != 0 )
{ {
//sendtxid = LP_broadcast("timespend",symbol,signedtx,signedtxid); sendtxid = LP_broadcast("timespend",symbol,signedtx,signedtxid);
jaddstr(retjson,"signedtx",signedtx); jaddstr(retjson,"signedtx",signedtx);
jaddbits256(retjson,"txid",signedtxid); jaddbits256(retjson,"txid",signedtxid);
if ( bits256_cmp(sendtxid,signedtxid) == 0 ) if ( bits256_cmp(sendtxid,signedtxid) == 0 )
@ -422,6 +422,7 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info
{ {
flagi = 1; flagi = 1;
claimtime = (uint32_t)time(NULL)-777; claimtime = (uint32_t)time(NULL)-777;
//claimtime = LP_claimtime(coin,expiration);
item = cJSON_CreateObject(); item = cJSON_CreateObject();
jaddbits256(item,"txid",utxotxid); jaddbits256(item,"txid",utxotxid);
jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0))); jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0)));

2
iguana/exchanges/LP_rpc.c

@ -928,7 +928,7 @@ uint32_t LP_heighttime(char *symbol,int32_t height)
{ {
if ( (retjson= LP_getblockhashstr(symbol,blockhashstr)) != 0 ) if ( (retjson= LP_getblockhashstr(symbol,blockhashstr)) != 0 )
{ {
printf("%s -> height.(%s)\n",blockhashstr,jprint(retjson,0)); //printf("%s -> height.(%s)\n",blockhashstr,jprint(retjson,0));
timestamp = juint(retjson,"time"); timestamp = juint(retjson,"time");
free_json(retjson); free_json(retjson);
} }

Loading…
Cancel
Save