Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
25b7684402
  1. 20
      deprecated/obsolete.h
  2. 2
      iguana/exchanges777.h
  3. 13
      iguana/iguana777.h
  4. 1
      iguana/iguana_init.c
  5. 4
      iguana/iguana_instantdex.c
  6. 258
      iguana/iguana_payments.c
  7. 11
      iguana/iguana_realtime.c
  8. 54
      iguana/iguana_unspents.c
  9. 4
      iguana/iguana_wallet.c
  10. 87
      iguana/swaps/iguana_BTCswap.c
  11. 2
      includes/iguana_apideclares.h

20
deprecated/obsolete.h

@ -16521,6 +16521,26 @@ len = 0;
privkey = rand256(0);
}
}*/
HASH_ITER(hh,myinfo->wallet,wacct,tmp)
{
if ( account != 0 && strcmp(account,"*") != 0 && strcmp(account,wacct->account) != 0 )
continue;
HASH_ITER(hh,wacct->waddr,waddr,tmp2)
{
if ( waddr->addrtype != coin->chain->pubtype || (bits256_nonz(waddr->privkey) == 0 && waddr->scriptlen == 0) )
continue;
if ( waddr->balance > 0 )
{
remains -= waddr->balance;
waddrs[num++] = waddr;
if ( num >= maxwaddrs || remains <= 0 )
break;
}
}
if ( num >= maxwaddrs || remains <= 0 )
break;
}
#endif
#endif

2
iguana/exchanges777.h

@ -129,7 +129,7 @@ struct instantdex_offer
struct instantdex_accept
{
struct instantdex_accept *next,*prev;
uint8_t state,reported,peerhas[IGUANA_MAXPEERS/8];
uint8_t state,reported,minconfirms,peerhas[IGUANA_MAXPEERS/8];
uint64_t pendingvolume64,orderid;
uint32_t dead;
struct instantdex_offer offer;

13
iguana/iguana777.h

@ -837,10 +837,10 @@ int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr
char *issue_startForging(struct supernet_info *myinfo,char *secret);
struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,char **retstrp,double *balancep,int32_t *numunspentsp,double minconfirms,char *account);
void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson);
int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,uint64_t *unspents,int32_t *numunspentsp,int32_t maxunspents);
int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp,int32_t maxunspents);
long iguana_spentsfile(struct iguana_info *coin,int32_t n);
uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti);
int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,uint64_t *unspents,int32_t *numunspentsp);
int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp);
uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp);
char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi);
uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8_t rmd160[20],struct iguana_pkhash *P,uint32_t pkind,struct iguana_ramchain *ramchain);
@ -946,7 +946,7 @@ int64_t iguana_fastfindcreate(struct iguana_info *coin);
int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr);
int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_ramchain *spentchain,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight);
int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight);
int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waddress **waddrs,int32_t maxwaddrs,int64_t required,int32_t minconf,char *account);
int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses);
int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin);
int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 txid,int32_t lasthdrsi);
uint8_t iguana_addrtype(struct iguana_info *coin,uint8_t script_type);
@ -961,7 +961,7 @@ int64_t iguana_unspentavail(struct iguana_info *coin,uint64_t hdrsi_unspendind,i
struct iguana_utxo iguana_utxofind(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,int32_t *RTspendflagp,int32_t lockflag);
int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeys);
cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins);
char *iguana_inputaddress(struct iguana_info *coin,char *coinaddr,cJSON *vinobj);
char *iguana_inputaddress(struct iguana_info *coin,char *coinaddr,int16_t *spent_hdrsip,uint32_t *unspentindp,cJSON *vinobj);
struct iguana_waddress *iguana_getaccountaddress(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,char *coinaddr,char *account);
int32_t iguana_uvaltxid(struct supernet_info *myinfo,bits256 *txidp,struct iguana_info *coin,int16_t hdrsi,uint32_t unspentind);
struct instantdex_accept *instantdex_quotefind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 encodedhash);
@ -972,7 +972,7 @@ void instantdex_update(struct supernet_info *myinfo);
cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account);
int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLockTime,struct vin_info *V,int32_t numvins);
int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvin *vin,cJSON *vinobj,struct vin_info *V);
int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,int32_t *nump,struct iguana_info *coin,int32_t minconf,char *account,void *ptr,int32_t maxsize);
//int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,int32_t *nump,struct iguana_info *coin,int32_t minconf,char *account,void *ptr,int32_t maxsize);
char *iguana_signunspents(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *txobj,uint64_t satoshis,char *changeaddr,uint64_t txfee,uint64_t *unspents,int32_t num);
bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx);
int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits256 *hashes,int32_t n);
@ -982,6 +982,9 @@ struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson);
int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin);
struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,int32_t datalen);
void instantdex_FSMinit();
void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins);
char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf);
char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx);
extern int32_t HDRnet,netBLOCKS;

1
iguana/iguana_init.c

@ -58,6 +58,7 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,coin->symbol), OS_portable_path(dirname);
portable_mutex_init(&coin->peers_mutex);
portable_mutex_init(&coin->blocks_mutex);
coin->txfee = 10000;
iguana_meminit(&coin->blockMEM,"blockMEM",coin->blockspace,sizeof(coin->blockspace),0);
iguana_initQs(coin);
coin->bindsock = -1;

4
iguana/iguana_instantdex.c

@ -1176,7 +1176,7 @@ struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct ex
char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson)
{
struct instantdex_accept *otherap,*tmp; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0;
struct instantdex_accept *otherap,*tmp; struct iguana_info *coin; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0;
*addedp = 0;
if ( exchange == 0 )
{
@ -1222,6 +1222,8 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_
{
printf("STATEMACHINEQ.(%llx / %llx)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid);
//queue_enqueue("acceptableQ",&exchange->acceptableQ,&swap->DL,0);
if ( isbob != 0 && (coin= iguana_coinfind("BTC")) != 0 )
swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,coin);
instantdex_statemachineadd(exchange,swap);
*addedp = 1;
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 )

258
iguana/iguana_payments.c

@ -160,7 +160,7 @@ cJSON *iguana_scriptobj(struct iguana_info *coin,uint8_t rmd160[20],char *coinad
return(scriptobj);
}
int32_t iguana_bestunspent(struct iguana_info *coin,int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,uint64_t *unspents,int32_t numunspents,uint64_t value)
int32_t iguana_bestunspent(struct iguana_info *coin,int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,int64_t *unspents,int32_t numunspents,uint64_t value)
{
int32_t i,abovei,belowi; int64_t above,below,gap,atx_value;
abovei = belowi = -1;
@ -198,7 +198,7 @@ int32_t iguana_bestunspent(struct iguana_info *coin,int32_t *aboveip,int64_t *ab
return(abovei >= 0 ? abovei : belowi);
}
cJSON *iguana_inputsjson(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,uint64_t amount,uint64_t *unspents,int32_t num)
cJSON *iguana_inputsjson(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,uint64_t amount,int64_t *unspents,int32_t num)
{
cJSON *item,*vins; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE]; struct iguana_txid *T; struct iguana_unspent *U,*u; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; char coinaddr[64],hexstr[IGUANA_MAXSCRIPTSIZE*2+1]; int32_t height,abovei,belowi,i,spendlen,ind,hdrsi; uint32_t txidind,unspentind; int64_t value,above,below,total = 0; int64_t remains = amount;
*totalp = 0;
@ -272,80 +272,32 @@ cJSON *iguana_inputsjson(struct supernet_info *myinfo,struct iguana_info *coin,i
return(vins);
}
char *iguana_signunspents(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *txobj,uint64_t satoshis,char *changeaddr,uint64_t txfee,uint64_t *unspents,int32_t num)
char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx)
{
uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; int32_t spendlen,numinputs,i,RTspentflag; struct iguana_msgtx msgtx; char *rawtx=0,*signedtx = 0; bits256 txid; cJSON *vins=0,*privkeys=0; struct vin_info *V; int64_t value,total,change; char changeaddress[64]; struct iguana_waddress *waddr;
cJSON *privkeys; struct vin_info *V; char *signedtx = 0; struct iguana_msgtx msgtx; int32_t numinputs;
*completedp = 0;
if ( txobj != 0 && (vins= iguana_inputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num)) != 0 )
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 && (privkeys= iguana_privkeysjson(myinfo,coin,vins)) != 0 )
{
if ( total < (satoshis + txfee) )
memset(&msgtx,0,sizeof(msgtx));
if ( (V= calloc(numinputs,sizeof(*V))) != 0 )
{
free_json(vins);
printf("insufficient total %.8f vs (%.8f + %.8f)\n",dstr(total),dstr(satoshis),dstr(txfee));
return(0);
if ( iguana_signrawtransaction(myinfo,coin,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 )
*completedp = 1;
else printf("signrawtransaction incomplete\n");
free(V);
}
if ( (change= (total - (satoshis + txfee))) > 0 )
{
if ( changeaddr == 0 || changeaddr[0] == 0 )
{
if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,changeaddress,"change")) == 0 )
{
free_json(vins);
return(0);
}
strcpy(changeaddress,waddr->coinaddr);
changeaddr = changeaddress;
}
}
if ( (privkeys= iguana_privkeysjson(myinfo,coin,vins)) != 0 )
{
iguana_createvins(myinfo,coin,txobj,vins);
if ( change > 0 )
{
if ( iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 )
{
free_json(vins), free_json(privkeys), free_json(txobj);
printf("illegal destination address.(%s)\n",changeaddr);
return(0);
}
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
bitcoin_txoutput(coin,txobj,spendscript,spendlen,change);
}
if ( (rawtx= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 )
{
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 && (V= calloc(numinputs,sizeof(*V))) != 0 )
{
memset(&msgtx,0,sizeof(msgtx));
if ( iguana_signrawtransaction(myinfo,coin,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 )
{
for (i=0; i<num; i++)
{
value = unspents[(i << 1) + 1];
if ( value == -1 )
iguana_utxofind(coin,(int32_t)(unspents[i << 1] >> 32),(uint32_t)unspents[i << 1],&RTspentflag,1);
}
*completedp = 1;
}
else printf("signrawtransaction incomplete\n");
free(V);
}
free(rawtx);
}
free_json(privkeys);
}
free_json(vins);
free_json(privkeys);
}
return(signedtx);
}
int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,int32_t *nump,struct iguana_info *coin,int32_t minconf,char *account,void *ptr,int32_t maxsize)
/*int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,int32_t *nump,struct iguana_info *coin,int32_t minconf,char *account,void *ptr,int32_t maxsize)
{
int32_t i,j,num,numwaddrs; struct iguana_waddress **waddrs,*waddr; uint64_t *unspents,value,avail=0;
*unspentsp = unspents = 0;
*nump = num = 0;
waddrs = (struct iguana_waddress **)ptr;
numwaddrs = iguana_unspentslists(myinfo,coin,waddrs,(int32_t)(maxsize/sizeof(*waddrs)),(uint64_t)1 << 62,minconf,account);
numwaddrs = iguana_unspentslists(myinfo,coin,waddrs,(int32_t)(maxsize/sizeof(*waddrs)),(uint64_t)1 << 62,minconf);
if ( numwaddrs > 0 )
{
unspents = (uint64_t *)((long)ptr + sizeof(*waddrs)*numwaddrs);
@ -371,7 +323,7 @@ int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,i
*unspentsp = unspents;
*nump = num;
return(avail);
}
}*/
bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx)
{
@ -392,46 +344,180 @@ bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_inf
return(txid);
}
char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf)
{
uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; int32_t max,num,spendlen; char *rawtx=0; bits256 txid; cJSON *vins=0; int64_t avail,total,change,*unspents = 0;
*vinsp = 0;
max = 10000;
unspents = calloc(max,sizeof(*unspents));
if ( (num= iguana_unspentslists(myinfo,coin,&avail,unspents,max,satoshis,minconf,addresses)) <= 0 )
{
free(unspents);
return(0);
}
if ( txobj != 0 && avail >= satoshis+txfee )
{
if ( (vins= iguana_inputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num)) != 0 )
{
if ( total < (satoshis + txfee) )
{
free_json(txobj), free_json(vins);
free(unspents);
printf("insufficient total %.8f vs (%.8f + %.8f)\n",dstr(total),dstr(satoshis),dstr(txfee));
return(0);
}
if ( (change= (total - (satoshis + txfee))) > 0 && (changeaddr == 0 || changeaddr[0] == 0) )
{
printf("no changeaddr for %.8f\n",dstr(change));
free_json(txobj), free_json(vins);
free(unspents);
return(0);
}
iguana_createvins(myinfo,coin,txobj,vins);
if ( change > 0 )
{
if ( iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 )
{
free_json(txobj), free_json(vins);
free(unspents);
printf("illegal destination address.(%s)\n",changeaddr);
return(0);
}
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
bitcoin_txoutput(coin,txobj,spendscript,spendlen,change);
}
rawtx = bitcoin_json2hex(myinfo,coin,&txid,txobj,0);
}
free_json(txobj);
}
free(unspents);
*vinsp = vins;
return(rawtx);
}
void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins)
{
uint32_t spent_unspentind; char coinaddr[64]; int16_t spent_hdrsi; int32_t i,RTspentflag,num;
num = cJSON_GetArraySize(vins);
for (i=0; i<num; i++)
{
if ( iguana_inputaddress(coin,coinaddr,&spent_hdrsi,&spent_unspentind,jitem(vins,i)) != 0 )
iguana_utxofind(coin,spent_hdrsi,spent_unspentind,&RTspentflag,1);
}
}
char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint64_t satoshis,uint64_t txfee,char *comment,char *comment2,int32_t minconf,char *account)
{
uint8_t addrtype,rmd160[20],spendscript[4096]; int32_t spendlen,num,completed; uint64_t *unspents,avail=0; char *signedtx = 0; bits256 signedtxid,senttxid; cJSON *retjson,*txobj; uint32_t locktime = 0;
uint8_t addrtype,spendscript[1024],rmd160[20]; int32_t completed; char *rawtx=0,*signedtx = 0; bits256 signedtxid,senttxid; cJSON *retjson,*vins,*addresses,*txobj; uint32_t spendlen,locktime = 0; struct iguana_waddress *waddr;
//sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] <amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful. Y
addresses = iguana_getaddressesbyaccount(myinfo,coin,account);
if ( coin->changeaddr[0] == 0 )
{
if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 )
return(clonestr("{\"error\":\"not enough funds\"}"));
strcpy(coin->changeaddr,waddr->coinaddr);
}
if ( coinaddr != 0 && coinaddr[0] != 0 && satoshis != 0 )
{
if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
avail = iguana_availunspents(myinfo,&unspents,&num,coin,minconf,account,coin->blockspace,sizeof(coin->blockspace));
if ( avail < satoshis+txfee || unspents == 0 || num <= 0 )
return(clonestr("{\"error\":\"not enough funds\"}"));
else if ( (txobj= bitcoin_txcreate(coin,locktime)) != 0 )
//avail = iguana_availunspents(myinfo,&unspents,&num,coin,minconf,account,coin->blockspace,sizeof(coin->blockspace));
//if ( avail < satoshis+txfee || unspents == 0 || num <= 0 )
// return(clonestr("{\"error\":\"not enough funds\"}"));
//else
if ( (txobj= bitcoin_txcreate(coin,locktime)) != 0 )
{
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
bitcoin_txoutput(coin,txobj,spendscript,spendlen,satoshis);
if ( (signedtx= iguana_signunspents(myinfo,coin,&signedtxid,&completed,txobj,satoshis,coin->changeaddr,txfee,unspents,num)) != 0 )
if ( (rawtx= iguana_calcrawtx(myinfo,coin,&vins,txobj,satoshis,coin->changeaddr,txfee,addresses,minconf)) != 0 && vins != 0 )
{
retjson = cJSON_CreateObject();
jaddbits256(retjson,"result",signedtxid);
jaddstr(retjson,"signedtx",signedtx);
jadd(retjson,"complete",completed != 0 ? jtrue() : jfalse());
if ( 0 )
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx)) != 0 )
{
senttxid = iguana_sendrawtransaction(myinfo,coin,signedtx);
if ( bits256_cmp(senttxid,signedtxid) == 0 )
jaddstr(retjson,"sendrawtransaction","success");
else jaddbits256(retjson,"senderror",senttxid);
iguana_unspentslock(myinfo,coin,vins);
retjson = cJSON_CreateObject();
jaddbits256(retjson,"result",signedtxid);
jaddstr(retjson,"signedtx",signedtx);
jadd(retjson,"complete",completed != 0 ? jtrue() : jfalse());
if ( 0 )
{
senttxid = iguana_sendrawtransaction(myinfo,coin,signedtx);
if ( bits256_cmp(senttxid,signedtxid) == 0 )
jaddstr(retjson,"sendrawtransaction","success");
else jaddbits256(retjson,"senderror",senttxid);
}
free_json(vins);
free(rawtx);
free(signedtx);
free_json(txobj);
return(jprint(retjson,1));
}
free(signedtx);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"couldnt create signedtx\"}"));
else
{
free_json(vins);
free(rawtx);
free_json(txobj);
return(clonestr("{\"error\":\"couldnt sign rawtx\"}"));
}
}
else
{
free_json(txobj);
return(clonestr("{\"error\":\"couldnt create rawtx\"}"));
}
} else return(clonestr("{\"error\":\"couldnt create txobj\"}"));
}
return(clonestr("{\"error\":\"need address and amount\"}"));
}
char *iguana_createrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,uint32_t locktime,uint64_t satoshis,char *spendscriptstr,char *changeaddr,int64_t txfee,int32_t minconf,cJSON *addresses)
{
cJSON *txobj; char *rawtx=0; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE]; int32_t spendlen;
*vinsp = 0;
if ( (txobj= bitcoin_txcreate(coin,locktime)) != 0 )
{
spendlen = (int32_t)strlen(spendscriptstr) >> 1;
decode_hex(spendscript,spendlen,spendscriptstr);
bitcoin_txoutput(coin,txobj,spendscript,spendlen,satoshis);
rawtx = iguana_calcrawtx(myinfo,coin,vinsp,txobj,satoshis,changeaddr,txfee,addresses,minconf);
free_json(txobj);
}
return(rawtx);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
STRING_ARRAY_OBJ_STRING(iguana,rawtx,changeaddr,addresses,vals,spendscriptstr)
{
cJSON *vins=0,*retjson; char *rawtx=0,*symbol=0; int64_t txfee,satoshis; uint32_t locktime,minconf;
retjson = cJSON_CreateObject();
if ( vals != 0 )
printf("vals.(%s)\n",jprint(vals,0));
if ( addresses != 0 )
printf("addresses.(%s)\n",jprint(addresses,0));
if ( (symbol= jstr(vals,"coin")) != 0 && (coin= iguana_coinfind(symbol)) != 0 )
{
minconf = juint(vals,"minconf");
locktime = juint(vals,"locktime");
satoshis = j64bits(vals,"amount");
if ( (txfee= j64bits(vals,"txfee")) == 0 )
txfee = coin->txfee;
if ( (rawtx= iguana_createrawtx(myinfo,coin,&vins,locktime,satoshis,spendscriptstr,changeaddr,txfee,minconf,addresses)) != 0 )
{
jaddstr(retjson,"rawtx",rawtx);
jaddstr(retjson,"agent","iguana");
jaddstr(retjson,"method","rawtx_result");
jadd(retjson,"vins",vins);
free(rawtx);
} else jaddstr(retjson,"error","couldnt create rawtx");
if ( vins != 0 )
free_json(vins);
}
return(jprint(retjson,1));
}
STRING_AND_INT(bitcoinrpc,sendrawtransaction,rawtx,allowhighfees)
{
cJSON *retjson = cJSON_CreateObject(); bits256 txid;
@ -1119,7 +1205,7 @@ S_D_SS(bitcoinrpc,sendtoaddress,address,amount,comment,comment2)
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
myinfo->expiration++;
iguana_unspentset(myinfo,coin);
//iguana_unspentset(myinfo,coin);
return(sendtoaddress(myinfo,coin,address,amount * SATOSHIDEN,coin->txfee,comment,comment2,coin->minconfirms,0));
}
@ -1130,7 +1216,7 @@ SS_D_I_SS(bitcoinrpc,sendfrom,fromaccount,toaddress,amount,minconf,comment,comme
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
myinfo->expiration++;
iguana_unspentset(myinfo,coin);
//iguana_unspentset(myinfo,coin);
return(sendtoaddress(myinfo,coin,toaddress,amount * SATOSHIDEN,coin->txfee,comment,comment2,minconf,fromaccount));
}
@ -1142,7 +1228,7 @@ S_A_I_S(bitcoinrpc,sendmany,fromaccount,payments,minconf,comment)
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
myinfo->expiration++;
iguana_unspentset(myinfo,coin);
//iguana_unspentset(myinfo,coin);
n = cJSON_GetArraySize(payments);
item = payments->child;
for (required=i=0; i<n; i++)

11
iguana/iguana_realtime.c

@ -200,8 +200,9 @@ void iguana_RTspendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
int32_t iguana_realtime_update(struct iguana_info *coin)
{
double startmillis0; static double totalmillis0; static int32_t num0;
struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t bundlei,i,n,flag=0; bits256 hash2,*ptr; struct iguana_peer *addr;
struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t offset,bundlei,i,n,flag=0; bits256 hash2,*ptr; struct iguana_peer *addr;
struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR;
offset = (strcmp("BTC",coin->symbol) != 0);
if ( coin->current != 0 && (coin->blocks.hwmchain.height % coin->chain->bundlesize) == coin->chain->bundlesize-1 && coin->blocks.hwmchain.height/coin->chain->bundlesize == coin->longestchain/coin->chain->bundlesize )
{
block = coin->current->blocks[coin->current->n - 1];
@ -235,7 +236,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
iguana_RTramchainfree(coin,coin->current);
return(0);
}
if ( coin->RTdatabad == 0 && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi >= coin->balanceswritten && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n && ((coin->RTheight < coin->blocks.hwmchain.height && time(NULL) > bp->lastRT) || time(NULL) > bp->lastRT+10) )
if ( coin->RTdatabad == 0 && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi >= coin->balanceswritten && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n && ((coin->RTheight < coin->blocks.hwmchain.height-offset && time(NULL) > bp->lastRT) || time(NULL) > bp->lastRT+10) )
{
if ( (block= bp->blocks[0]) == 0 || block->txvalid == 0 || block->mainchain == 0 )
{
@ -257,7 +258,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
if ( bits256_cmp(coin->RThash1,bp->hashes[1]) != 0 )
coin->RThash1 = bp->hashes[1];
bp->lastRT = (uint32_t)time(NULL);
if ( coin->RTheight <= coin->longestchain-2*(strcmp("BTC",coin->symbol)!=0) && coin->peers.numranked > 0 && time(NULL) > coin->RThdrstime+10 )
if ( coin->RTheight <= coin->longestchain-offset && coin->peers.numranked > 0 && time(NULL) > coin->RThdrstime+10 )
{
iguana_RThdrs(coin,bp,coin->peers.numranked);
coin->RThdrstime = bp->lastRT;
@ -273,7 +274,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
bp->lastRT = (uint32_t)time(NULL);
iguana_RTramchainalloc("RTbundle",coin,bp);
bp->isRT = 1;
while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height )
while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height-offset )
{
if ( coin->RTdatabad != 0 )
break;
@ -327,7 +328,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
}
}
n = 0;
if ( coin->RTdatabad == 0 && dest != 0 && flag != 0 && coin->RTheight >= coin->longestchain )
if ( coin->RTdatabad == 0 && dest != 0 && flag != 0 && coin->RTheight >= coin->longestchain-offset )
{
//printf("ramchainiterate.[%d] ave %.2f micros, total %.2f seconds starti.%d num.%d\n",num0,(totalmillis0*1000.)/num0,totalmillis0/1000.,coin->RTstarti,coin->RTheight%bp->n);
if ( (n= iguana_walkchain(coin,1)) == coin->RTheight-1 )

54
iguana/iguana_unspents.c

@ -54,15 +54,21 @@ int32_t iguana_unspentindfind(struct iguana_info *coin,char *coinaddr,uint8_t *s
return(unspentind);
}
char *iguana_inputaddress(struct iguana_info *coin,char *coinaddr,cJSON *vinobj)
char *iguana_inputaddress(struct iguana_info *coin,char *coinaddr,int16_t *spent_hdrsip,uint32_t *unspentindp,cJSON *vinobj)
{
bits256 txid; int32_t vout,checkind,height;
*unspentindp = 0;
*spent_hdrsip = -1;
if ( jobj(vinobj,"txid") != 0 && jobj(vinobj,"vout") != 0 )
{
txid = jbits256(vinobj,"txid");
vout = jint(vinobj,"vout");
if ( (checkind= iguana_unspentindfind(coin,coinaddr,0,0,0,&height,txid,vout,coin->bundlescount-1)) != 0 )
{
*spent_hdrsip = (height / coin->chain->bundlesize);
*unspentindp = checkind;
return(coinaddr);
}
}
return(0);
}
@ -170,7 +176,7 @@ int32_t iguana_uheight(struct iguana_info *coin,int32_t bundleheight,struct igua
else return(bundleheight);
}
int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int64_t *spentp,uint64_t *unspents,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi,int32_t lastheight,int32_t minconf,int32_t maxconf)
int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int64_t *spentp,int64_t *unspents,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi,int32_t lastheight,int32_t minconf,int32_t maxconf)
{
struct iguana_unspent *U; struct iguana_utxo *U2; struct iguana_spend *S; int32_t max,uheight,spentheight; uint32_t pkind=0,unspentind; int64_t spent = 0,checkval,deposits = 0; struct iguana_txid *T; struct iguana_account *A2; struct iguana_ramchaindata *rdata = 0; int64_t RTspend = 0;
max = *nump;
@ -237,7 +243,7 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co
return(deposits - spent);
}
int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,uint64_t *unspents,int32_t *numunspentsp,int32_t maxunspents)
int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp,int32_t maxunspents)
{
int32_t i,n,m,numunspents; int64_t spent,deposits,netbalance,total; uint32_t lastunspentind; struct iguana_pkhash *p,_p; struct iguana_ramchain *ramchain; struct iguana_bundle *bp;
if ( 0 && coin->RTramchain_busy != 0 )
@ -288,7 +294,7 @@ int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin
return(n);
}
int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,uint64_t *unspents,int32_t *numunspentsp)
int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp)
{
int64_t total=0,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,numunspents,maxunspents,flag = 0; char coinaddr[64];
if ( 0 && coin->RTramchain_busy != 0 )
@ -351,15 +357,16 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i
return(rmdarray);
}
int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin)
/*int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin)
{
int64_t sum = 0,total; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2; int32_t n,numunspents = 0;
int64_t sum = 0,total; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2; int32_t n,numunspents = 0; cJSON *addresses = cJSON_CreateArray();
HASH_ITER(hh,myinfo->wallet,wacct,tmp)
{
HASH_ITER(hh,wacct->waddr,waddr,tmp2)
{
if ( waddr->addrtype != coin->chain->pubtype || (bits256_nonz(waddr->privkey) == 0 && waddr->scriptlen == 0) )
continue;
jaddstr(array,waddr->coinaddr);
total = 0;
n = 0;
iguana_pkhasharray(myinfo,coin,0,coin->minconfirms,coin->longestchain,&total,0,coin->bundlescount,waddr->rmd160,waddr->coinaddr,waddr->pubkey,coin->blocks.hwmchain.height - coin->minconfirms,(uint64_t *)coin->blockspace,&n,(int32_t)(sizeof(coin->blockspace)/sizeof(*waddr->unspents))-1000);
@ -380,32 +387,33 @@ int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin)
}
//printf("available %.8f\n",dstr(sum));
return(sum);
}
}*/
int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waddress **waddrs,int32_t maxwaddrs,int64_t required,int32_t minconf,char *account)
int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses)
{
int64_t remains; int32_t num = 0; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2;
int64_t remains,total,sum = 0; int32_t i,n,numunspents,numaddrs; uint8_t pubkey[65],rmd160[20]; char *coinaddr;
*totalp = 0;
if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 )
return(0);
memset(pubkey,0,sizeof(pubkey));
remains = required * 1.1 + coin->txfee;
HASH_ITER(hh,myinfo->wallet,wacct,tmp)
for (i=numunspents=0; i<numaddrs; i++)
{
if ( account != 0 && strcmp(account,"*") != 0 && strcmp(account,wacct->account) != 0 )
continue;
HASH_ITER(hh,wacct->waddr,waddr,tmp2)
if ( (coinaddr= jstri(addresses,i)) != 0 )
{
if ( waddr->addrtype != coin->chain->pubtype || (bits256_nonz(waddr->privkey) == 0 && waddr->scriptlen == 0) )
continue;
if ( waddr->balance > 0 )
total = 0;
n = 0;
iguana_pkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,coin->blocks.hwmchain.height - minconf,unspents,&n,max-1000);
if ( n > 0 )
{
remains -= waddr->balance;
waddrs[num++] = waddr;
if ( num >= maxwaddrs || remains <= 0 )
break;
sum += total;
numunspents += n;
unspents += n;
}
}
if ( num >= maxwaddrs || remains <= 0 )
break;
}
return(num);
*totalp = sum;
return(numunspents);
}
int32_t iguana_uvaltxid(struct supernet_info *myinfo,bits256 *txidp,struct iguana_info *coin,int16_t hdrsi,uint32_t unspentind)

4
iguana/iguana_wallet.c

@ -826,13 +826,13 @@ int64_t iguana_waccountbalance(struct supernet_info *myinfo,struct iguana_info *
cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins)
{
int32_t i,j,n,numinputs; struct iguana_waddress *waddr; struct iguana_waccount *wacct; char *addresses,*address,coinaddr[64]; cJSON *privkeys = cJSON_CreateArray();
int32_t i,j,n,numinputs; uint32_t spent_unspentind; int16_t spent_hdrsi; struct iguana_waddress *waddr; struct iguana_waccount *wacct; char *addresses,*address,coinaddr[64]; cJSON *privkeys = cJSON_CreateArray();
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
addresses = calloc(numinputs,64);
for (i=n=0; i<numinputs; i++)
{
if ( (address= iguana_inputaddress(coin,coinaddr,jitem(vins,i))) != 0 )
if ( (address= iguana_inputaddress(coin,coinaddr,&spent_hdrsi,&spent_unspentind,jitem(vins,i))) != 0 )
{
for (j=0; j<n; j++)
{

87
iguana/swaps/iguana_BTCswap.c

@ -107,24 +107,47 @@ void iguana_addinputs(struct iguana_info *coin,struct bitcoin_spend *spend,cJSON
}
}
struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *txobj,int64_t satoshis,int64_t txfee,int32_t minconf,int32_t myside)
{
struct iguana_waddress *waddr; struct bitcoin_statetx *tx=0; uint8_t pubkey33[33]; char coinaddr[64]; char *rawtx,*signedtx; cJSON *vins; bits256 signedtxid; int32_t completed; cJSON *addresses = cJSON_CreateArray();
if ( coin->changeaddr[0] == 0 )
{
if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 )
return(0);
strcpy(coin->changeaddr,waddr->coinaddr);
}
bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33);
jaddistr(addresses,coinaddr);
if ( (rawtx= iguana_calcrawtx(myinfo,coin,&vins,txobj,satoshis,coin->changeaddr,txfee,addresses,minconf)) != 0 && vins != 0 )
{
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx)) != 0 )
{
iguana_unspentslock(myinfo,coin,vins);
//avail = iguana_availunspents(myinfo,&unspents,&num,coin,coin->chain->minconfirms,"*",coin->blockspace,sizeof(coin->blockspace));
//if ( (feetx= iguana_signunspents(myinfo,coin,&signedtxid,&completed,txobj,swap->insurance,coin->changeaddr,coin->txfee,unspents,num)) != 0 )
//{
tx = calloc(1,sizeof(*tx) + strlen(rawtx) + 1);
strcpy(tx->txbytes,signedtx);
tx->txid = signedtxid;
printf("%s feetx.%s\n",myside != 0 ? "BOB" : "ALICE",signedtx);
//disp_tx(myinfo,coin,"feetx",feetx);
free(signedtx);
} free(rawtx);
} else printf("error creating %s feetx\n",myside != 0 ? "BOB" : "ALICE");
free_json(addresses);
return(tx);
}
struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin)
{
int32_t n,num,completed; char *feetx = 0; bits256 signedtxid; cJSON *txobj;int64_t avail; uint8_t paymentscript[128]; struct bitcoin_statetx *ptr = 0; uint64_t *unspents,r;
int32_t n; cJSON *txobj; uint8_t paymentscript[128]; struct bitcoin_statetx *ptr = 0; uint64_t r;
r = swap->mine.orderid ^ swap->other.orderid;
txobj = bitcoin_txcreate(coin,0);
n = instantdex_outputinsurance(paymentscript,swap->insurance,r,r * (strcmp("BTC",coin->symbol) == 0));
txobj = bitcoin_txcreate(coin,0);
bitcoin_txoutput(coin,txobj,paymentscript,n,swap->insurance);
avail = iguana_availunspents(myinfo,&unspents,&num,coin,coin->chain->minconfirms,"*",coin->blockspace,sizeof(coin->blockspace));
if ( (feetx= iguana_signunspents(myinfo,coin,&signedtxid,&completed,txobj,swap->insurance,coin->changeaddr,coin->txfee,unspents,num)) != 0 )
{
ptr = calloc(1,sizeof(*ptr) + strlen(feetx) + 1);
strcpy(ptr->txbytes,feetx);
ptr->txid = signedtxid;
printf("%s feetx.%s\n",A->offer.myside != 0 ? "BOB" : "ALICE",feetx);
//disp_tx(myinfo,coin,"feetx",feetx);
free(feetx);
}
else printf("error creating %s feetx\n",A->offer.myside != 0 ? "BOB" : "ALICE");
ptr = instantdex_signtx(myinfo,coin,txobj,swap->insurance,coin->txfee,swap->mine.minconfirms,A->offer.myside);
free_json(txobj);
return(ptr);
}
@ -169,25 +192,16 @@ int32_t instantdex_feetxverify(struct supernet_info *myinfo,struct iguana_info *
struct bitcoin_statetx *instantdex_bobtx(struct supernet_info *myinfo,struct bitcoin_swapinfo *swap,struct iguana_info *coin,bits256 pub1,bits256 pub2,bits256 priv,uint32_t reftime,int64_t amount,int32_t depositflag)
{
cJSON *txobj; int32_t n,secretstart; char *signedtx = 0; struct bitcoin_statetx *ptr = 0;
uint8_t script[1024],secret[20]; bits256 signedtxid; uint32_t locktime; int64_t avail; int32_t completed,num; uint64_t *unspents;
cJSON *txobj; int32_t n,secretstart; struct bitcoin_statetx *ptr = 0; uint8_t script[1024],secret[20]; uint32_t locktime; int64_t satoshis;
if ( coin == 0 )
return(0);
locktime = (uint32_t)(reftime + INSTANTDEX_LOCKTIME * (1 + depositflag));
txobj = bitcoin_txcreate(coin,locktime);
calc_rmd160_sha256(secret,priv.bytes,sizeof(priv));
n = instantdex_bobscript(script,0,&secretstart,locktime,pub1,secret,pub2);
bitcoin_txoutput(coin,txobj,script,n,amount + depositflag*swap->insurance*100);
avail = iguana_availunspents(myinfo,&unspents,&num,coin,coin->chain->minconfirms,"*",coin->blockspace,sizeof(coin->blockspace));
if ( (signedtx= iguana_signunspents(myinfo,coin,&signedtxid,&completed,txobj,amount + swap->insurance,coin->changeaddr,coin->txfee,unspents,num)) != 0 )
{
ptr = calloc(1,sizeof(*ptr) + strlen(signedtx) + 1);
strcpy(ptr->txbytes,signedtx);
ptr->txid = signedtxid;
printf("depositflag.%d bobtx.%s\n",depositflag,signedtx);
//disp_tx(myinfo,coin,depositflag != 0 ? "deposit" : "payment",signedtx);
free(signedtx);
} else printf("error signing bobdeposit\n");
satoshis = amount + depositflag*swap->insurance*100;
bitcoin_txoutput(coin,txobj,script,n,satoshis);
ptr = instantdex_signtx(myinfo,coin,txobj,satoshis,coin->txfee,swap->mine.minconfirms,swap->mine.offer.myside);
free_json(txobj);
return(ptr);
}
@ -267,24 +281,15 @@ int32_t instantdex_altpaymentverify(struct supernet_info *myinfo,struct iguana_i
return(retval);
}
struct bitcoin_statetx *instantdex_alicetx(struct supernet_info *myinfo,struct iguana_info *altcoin,char *msigaddr,bits256 pubAm,bits256 pubBn,int64_t amount)
struct bitcoin_statetx *instantdex_alicetx(struct supernet_info *myinfo,struct iguana_info *altcoin,char *msigaddr,bits256 pubAm,bits256 pubBn,int64_t amount,struct bitcoin_swapinfo *swap)
{
cJSON *txobj; int32_t n,completed,num; char *signedtx = 0; uint8_t script[1024]; struct bitcoin_statetx *ptr = 0; bits256 signedtxid; uint64_t *unspents; int64_t avail;
cJSON *txobj; int32_t n; uint8_t script[1024]; struct bitcoin_statetx *ptr = 0;
if ( altcoin != 0 )
{
txobj = bitcoin_txcreate(altcoin,0);
n = instantdex_alicescript(script,0,msigaddr,altcoin->chain->p2shtype,pubAm,pubBn);
bitcoin_txoutput(altcoin,txobj,script,n,amount);
avail = iguana_availunspents(myinfo,&unspents,&num,altcoin,altcoin->chain->minconfirms,"*",altcoin->blockspace,sizeof(altcoin->blockspace));
if ( (signedtx= iguana_signunspents(myinfo,altcoin,&signedtxid,&completed,txobj,amount,altcoin->changeaddr,altcoin->txfee,unspents,num)) != 0 )
{
printf("alice payment.%s\n",signedtx);
//disp_tx(myinfo,altcoin,"altpayment",signedtx);
ptr = calloc(1,sizeof(*ptr) + strlen(signedtx) + 1);
ptr->txid = signedtxid;
strcpy(ptr->txbytes,signedtx);
free(signedtx);
} else printf("error signing alicetx\n");
ptr = instantdex_signtx(myinfo,altcoin,txobj,amount,altcoin->txfee,swap->mine.minconfirms,swap->mine.offer.myside);
free_json(txobj);
}
return(ptr);
@ -591,7 +596,7 @@ cJSON *BTC_waitdeckCfunc(struct supernet_info *myinfo,struct exchange_info *exch
cJSON *BTC_waitprivCfunc(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp)
{
strcmp(swap->expectedcmdstr,"BTCprivC");
printf("call privkey extract from serdatalen.%d\n",*serdatalenp);
//printf("call privkey extract from serdatalen.%d\n",*serdatalenp);
instantdex_privkeyextract(myinfo,swap,*serdatap,*serdatalenp);
*serdatap = 0, *serdatalenp = 0;
return(newjson);
@ -673,7 +678,7 @@ cJSON *BTC_waitprivsfunc(struct supernet_info *myinfo,struct exchange_info *exch
{
strcmp(swap->expectedcmdstr,"BTCprivs");
instantdex_privkeyextract(myinfo,swap,*serdatap,*serdatalenp);
if ( (swap->myfee= instantdex_feetx(myinfo,&swap->mine,swap,coin)) != 0 )
if ( swap->myfee != 0 || (swap->myfee= instantdex_feetx(myinfo,&swap->mine,swap,coin)) != 0 )
{
jaddstr(newjson,"feetx",swap->myfee->txbytes);
jaddbits256(newjson,"feetxid",swap->myfee->txid);
@ -714,7 +719,7 @@ cJSON *ALICE_waitdepositfunc(struct supernet_info *myinfo,struct exchange_info *
jaddstr(newjson,"depfound",retstr);
if ( instantdex_paymentverify(myinfo,iguana_coinfind("BTC"),swap,argjson,1) != 0 )
return(cJSON_Parse("{\"error\":\"deposit didnt verify\"}"));
if ( (swap->altpayment= instantdex_alicetx(myinfo,altcoin,swap->altpayment->destaddr,swap->pubAm,swap->pubBn,swap->altsatoshis)) != 0 )
if ( (swap->altpayment= instantdex_alicetx(myinfo,altcoin,swap->altpayment->destaddr,swap->pubAm,swap->pubBn,swap->altsatoshis,swap)) != 0 )
{
// broadcast altpayment
jaddstr(newjson,"altpayment",swap->altpayment->txbytes);

2
includes/iguana_apideclares.h

@ -83,6 +83,8 @@ ZERO_ARGS(bitcoinrpc,gettxoutsetinfo);
ZERO_ARGS(bitcoinrpc,getrawchangeaddress);
SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment);
STRING_ARRAY_OBJ_STRING(iguana,rawtx,changeaddr,addresses,vals,spendscriptstr);
STRING_ARG(iguana,initfastfind,activecoin);
STRING_ARG(iguana,peers,activecoin);
STRING_AND_INT(iguana,maxpeers,activecoin,max);

Loading…
Cancel
Save