Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
3d385ca7ef
  1. 6
      iguana/SuperNET_category.c
  2. 1
      iguana/iguana777.h
  3. 4
      iguana/iguana_instantdex.c
  4. 59
      iguana/iguana_payments.c
  5. 31
      iguana/iguana_wallet.c
  6. 93
      iguana/swaps/iguana_BTCswap.c

6
iguana/SuperNET_category.c

@ -207,7 +207,7 @@ char *bitcoin_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void
char *method="",*agent="",*retstr = 0; int32_t i,j; cJSON *json,*valsobj; struct iguana_info *coin=0; struct iguana_peer *addr; char *method="",*agent="",*retstr = 0; int32_t i,j; cJSON *json,*valsobj; struct iguana_info *coin=0; struct iguana_peer *addr;
if ( (json= cJSON_Parse(ptr)) != 0 ) if ( (json= cJSON_Parse(ptr)) != 0 )
{ {
//printf("bitcoinprocess.(%s)\n",jprint(json,0)); printf("bitcoinprocess.(%s)\n",jprint(json,0));
agent = jstr(json,"agent"); agent = jstr(json,"agent");
method = jstr(json,"method"); method = jstr(json,"method");
valsobj = jobj(json,"vals"); valsobj = jobj(json,"vals");
@ -231,7 +231,7 @@ char *bitcoin_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void
} }
if ( retstr == 0 ) if ( retstr == 0 )
return(0); return(0);
//printf("RELAY will return.(%s)\n",retstr); printf("RELAY will return.(%s)\n",retstr);
for (j=0; j<IGUANA_MAXCOINS; j++) for (j=0; j<IGUANA_MAXCOINS; j++)
{ {
if ( (coin= Coins[j]) == 0 ) if ( (coin= Coins[j]) == 0 )
@ -263,7 +263,7 @@ char *bitcoin_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void
} }
} }
} }
printf("bitcoin_hexmsg.(%d) from %s (%s/%s)\n",len,remoteaddr,agent,method); printf("unhandled bitcoin_hexmsg.(%d) from %s (%s/%s)\n",len,remoteaddr,agent,method);
free_json(json); free_json(json);
return(retstr); return(retstr);
} }

1
iguana/iguana777.h

@ -985,6 +985,7 @@ void instantdex_FSMinit();
void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins); 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_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); char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx);
char *iguana_pollrawtx(queue_t *Q,cJSON **vinsp,uint32_t rawtxtag,double expiration);
extern int32_t HDRnet,netBLOCKS; extern int32_t HDRnet,netBLOCKS;

4
iguana/iguana_instantdex.c

@ -1271,7 +1271,9 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
} }
else //if ( (retstr= instantdex_addfeetx(myinfo,newjson,ap,swap,"BOB_gotoffer","ALICE_gotoffer")) == 0 ) else //if ( (retstr= instantdex_addfeetx(myinfo,newjson,ap,swap,"BOB_gotoffer","ALICE_gotoffer")) == 0 )
{ {
printf("create statemachine\n"); printf("create statemachine isbob.%d\n",isbob);
if ( isbob != 0 && (coinbtc= iguana_coinfind("BTC")) != 0 )
swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,coinbtc);
//queue_enqueue("acceptableQ",&exchange->acceptableQ,&swap->DL,0); //queue_enqueue("acceptableQ",&exchange->acceptableQ,&swap->DL,0);
instantdex_statemachineadd(exchange,swap); instantdex_statemachineadd(exchange,swap);
if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 ) if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 )

59
iguana/iguana_payments.c

@ -393,9 +393,36 @@ cJSON *iguana_requestjson(struct supernet_info *myinfo,cJSON *hexjson)
return(retjson); return(retjson);
} }
char *iguana_pollrawtx(queue_t *Q,cJSON **vinsp,uint32_t rawtxtag,double expiration)
{
struct rawtx_queue *ptr; char *rawtx;
while ( OS_milliseconds() < expiration )
{
if ( (ptr= queue_dequeue(Q,0)) != 0 )
{
if ( rawtxtag == ptr->rawtxtag )
{
rawtx = clonestr(ptr->rawtx);
//printf("got RAWTX.(%s)\n",rawtx);
if ( vinsp != 0 )
*vinsp = ptr->vins;
else free_json(ptr->vins);
free(ptr);
return(rawtx);
}
else
{
free_json(ptr->vins);
free(ptr);
}
}
}
return(0);
}
char *iguana_request_andwait(struct supernet_info *myinfo,queue_t *Q,cJSON **vinsp,cJSON *reqjson,uint32_t rawtxtag,int32_t timeout) char *iguana_request_andwait(struct supernet_info *myinfo,queue_t *Q,cJSON **vinsp,cJSON *reqjson,uint32_t rawtxtag,int32_t timeout)
{ {
struct rawtx_queue *ptr; int32_t i,j,n; struct iguana_peer *addr; double expiration; struct iguana_info *coin; char *rawtx,*reqstr; cJSON *tmpjson; struct rawtx_queue *ptr; int32_t i,j,n; struct iguana_peer *addr; double expiration; struct iguana_info *coin; char *reqstr; cJSON *tmpjson;
if ( vinsp != 0 ) if ( vinsp != 0 )
*vinsp = 0; *vinsp = 0;
tmpjson = iguana_requestjson(myinfo,reqjson); tmpjson = iguana_requestjson(myinfo,reqjson);
@ -421,28 +448,7 @@ char *iguana_request_andwait(struct supernet_info *myinfo,queue_t *Q,cJSON **vin
} }
} }
} }
while ( OS_milliseconds() < expiration ) return(iguana_pollrawtx(Q,vinsp,rawtxtag,expiration));
{
if ( (ptr= queue_dequeue(Q,0)) != 0 )
{
if ( rawtxtag == ptr->rawtxtag )
{
rawtx = clonestr(ptr->rawtx);
//printf("got RAWTX.(%s)\n",rawtx);
if ( vinsp != 0 )
*vinsp = ptr->vins;
else free_json(ptr->vins);
free(ptr);
return(rawtx);
}
else
{
free_json(ptr->vins);
free(ptr);
}
}
}
return(0);
} }
char *iguana_rawtxissue(struct supernet_info *myinfo,uint32_t rawtxtag,char *symbol,cJSON **vinsp,uint32_t locktime,uint64_t satoshis,char *changeaddr,uint64_t txfee,cJSON *addresses,int32_t minconf,char *spendscriptstr,int32_t timeout) char *iguana_rawtxissue(struct supernet_info *myinfo,uint32_t rawtxtag,char *symbol,cJSON **vinsp,uint32_t locktime,uint64_t satoshis,char *changeaddr,uint64_t txfee,cJSON *addresses,int32_t minconf,char *spendscriptstr,int32_t timeout)
@ -652,7 +658,12 @@ STRING_ARRAY_OBJ_STRING(iguana,rawtx,changeaddr,addresses,vals,spendscriptstr)
jaddstr(valsobj,"coin",symbol); jaddstr(valsobj,"coin",symbol);
jadd(hexjson,"vals",valsobj); jadd(hexjson,"vals",valsobj);
retjson = iguana_requestjson(myinfo,hexjson); retjson = iguana_requestjson(myinfo,hexjson);
} else jaddstr(retjson,"result",rawtx); }
else
{
jaddstr(retjson,"result",rawtx);
jadd(retjson,"vins",vins);
}
free(rawtx); free(rawtx);
} else jaddstr(retjson,"error","couldnt create rawtx"); } else jaddstr(retjson,"error","couldnt create rawtx");
} }

31
iguana/iguana_wallet.c

@ -268,7 +268,7 @@ uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin
cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account) cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account)
{ {
struct iguana_waccount *subset,*tmp; struct iguana_waddress *waddr,*tmp2; cJSON *retjson,*array; struct iguana_waccount *subset,*tmp; char coinaddr[64]; struct iguana_waddress *waddr,*tmp2; cJSON *retjson,*array;
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
array = cJSON_CreateArray(); array = cJSON_CreateArray();
if ( account == 0 ) if ( account == 0 )
@ -279,7 +279,8 @@ cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_i
{ {
HASH_ITER(hh,subset->waddr,waddr,tmp2) HASH_ITER(hh,subset->waddr,waddr,tmp2)
{ {
jaddistr(array,waddr->coinaddr); bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20);
jaddistr(array,coinaddr);
} }
} else jaddstr(retjson,"result","cant find account"); } else jaddstr(retjson,"result","cant find account");
} }
@ -289,7 +290,8 @@ cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_i
{ {
HASH_ITER(hh,subset->waddr,waddr,tmp2) HASH_ITER(hh,subset->waddr,waddr,tmp2)
{ {
jaddistr(array,waddr->coinaddr); bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20);
jaddistr(array,coinaddr);
} }
} }
} }
@ -322,12 +324,13 @@ int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,char
} }
} }
cJSON *iguana_waddressjson(cJSON *item,struct iguana_waddress *waddr) cJSON *iguana_waddressjson(struct iguana_info *coin,cJSON *item,struct iguana_waddress *waddr)
{ {
char str[256],redeemScript[4096]; char str[256],redeemScript[4096],coinaddr[64];
if ( item == 0 ) if ( item == 0 )
item = cJSON_CreateObject(); item = cJSON_CreateObject();
jaddstr(item,"address",waddr->coinaddr); bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20);
jaddstr(item,"address",coinaddr);
//jaddstr(item,"privkey",bits256_str(str,waddr->privkey)); //jaddstr(item,"privkey",bits256_str(str,waddr->privkey));
//jaddstr(item,"wif",waddr->wifstr); //jaddstr(item,"wif",waddr->wifstr);
init_hexbytes_noT(str,waddr->rmd160,20); init_hexbytes_noT(str,waddr->rmd160,20);
@ -375,7 +378,7 @@ char *getaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *coi
return(clonestr("{\"result\":\"no account for address\"}")); return(clonestr("{\"result\":\"no account for address\"}"));
if ( wacct != 0 ) if ( wacct != 0 )
{ {
retjson = iguana_waddressjson(0,waddr); retjson = iguana_waddressjson(coin,0,waddr);
jaddstr(retjson,"account",wacct->account); jaddstr(retjson,"account",wacct->account);
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");
return(jprint(retjson,1)); return(jprint(retjson,1));
@ -432,7 +435,7 @@ int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *co
if ( waddr != 0 && (valuestr= iguana_walletvalue(valuebuf,waddr)) != 0 ) if ( waddr != 0 && (valuestr= iguana_walletvalue(valuebuf,waddr)) != 0 )
{ {
init_hexbytes_noT(rmdstr,waddr->rmd160,20); init_hexbytes_noT(rmdstr,waddr->rmd160,20);
if ( (accountobj= jobj(payload,account)) != 0 && jobj(accountobj,waddr->coinaddr) != 0 && jobj(accountobj,rmdstr) != 0 ) if ( (accountobj= jobj(payload,account)) != 0 && jobj(accountobj,rmdstr) != 0 )
{ {
free_json(retjson); free_json(retjson);
free_json(payload); free_json(payload);
@ -497,7 +500,7 @@ cJSON *iguana_walletadd(struct supernet_info *myinfo,struct iguana_waddress **wa
} }
else else
{ {
retjson = iguana_waddressjson(retjson,waddr); retjson = iguana_waddressjson(coin,retjson,waddr);
jaddstr(retjson,"account",account); jaddstr(retjson,"account",account);
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");
} }
@ -686,7 +689,7 @@ uint8_t iguana_waddrvalidate(struct supernet_info *myinfo,struct iguana_info *co
cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t flag,cJSON *array,int32_t *goodp,int32_t *badp,int32_t *errors) cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t flag,cJSON *array,int32_t *goodp,int32_t *badp,int32_t *errors)
{ {
struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr=0,*tmp2; uint8_t errorflags; int32_t i,good=0,bad=0,_errors[8]; cJSON *item; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr=0,*tmp2; uint8_t errorflags; int32_t i,good=0,bad=0,_errors[8]; cJSON *item; char coinaddr[64];
if ( errors == 0 ) if ( errors == 0 )
errors = _errors; errors = _errors;
HASH_ITER(hh,myinfo->wallet,wacct,tmp) HASH_ITER(hh,myinfo->wallet,wacct,tmp)
@ -718,7 +721,8 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
bad++; bad++;
if ( array != 0 && (item= cJSON_CreateObject()) != 0 ) if ( array != 0 && (item= cJSON_CreateObject()) != 0 )
{ {
jaddnum(item,waddr->coinaddr,errorflags); bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20);
jaddnum(item,coinaddr,errorflags);
jaddi(array,item); jaddi(array,item);
} }
} else good++; } else good++;
@ -909,7 +913,6 @@ STRING_ARG(bitcoinrpc,validateaddress,address)
if ( iguana_addressvalidate(coin,&addrtype,address) < 0 ) if ( iguana_addressvalidate(coin,&addrtype,address) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}")); return(clonestr("{\"error\":\"invalid coin address\"}"));
bitcoin_addr2rmd160(&addrtype,rmd160,address); bitcoin_addr2rmd160(&addrtype,rmd160,address);
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");
jaddnum(retjson,"addrtype",addrtype); jaddnum(retjson,"addrtype",addrtype);
@ -1020,7 +1023,7 @@ struct iguana_waddress *iguana_getaccountaddress(struct supernet_info *myinfo,st
} }
if ( waddr != 0 ) if ( waddr != 0 )
{ {
strcpy(coinaddr,waddr->coinaddr); bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20);
return(waddr); return(waddr);
} }
return(0); return(0);
@ -1037,7 +1040,7 @@ STRING_ARG(bitcoinrpc,getaccountaddress,account)
if ( account != 0 && account[0] != 0 ) if ( account != 0 && account[0] != 0 )
{ {
if ( (waddr= iguana_getaccountaddress(myinfo,coin,json,remoteaddr,coinaddr,account)) != 0 ) if ( (waddr= iguana_getaccountaddress(myinfo,coin,json,remoteaddr,coinaddr,account)) != 0 )
retjson = iguana_waddressjson(0,waddr); retjson = iguana_waddressjson(coin,0,waddr);
else return(clonestr("{\"error\":\"couldnt create address\"}")); else return(clonestr("{\"error\":\"couldnt create address\"}"));
jaddstr(retjson,"account",account); jaddstr(retjson,"account",account);
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");

93
iguana/swaps/iguana_BTCswap.c

@ -107,48 +107,81 @@ 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 bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t locktime,char *scriptstr,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(); struct iguana_waddress *waddr; struct bitcoin_statetx *tx=0; uint8_t pubkey33[33]; char coinaddr[64]; char *rawtx,*signedtx,*retstr; bits256 signedtxid; uint32_t rawtxtag; int32_t flag,completed; cJSON *valsobj,*vins,*retjson,*argjson,*addresses = cJSON_CreateArray();
if ( coin->changeaddr[0] == 0 ) if ( coin->changeaddr[0] == 0 )
{ {
if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 ) if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 )
return(0); return(0);
strcpy(coin->changeaddr,waddr->coinaddr); bitcoin_address(coin->changeaddr,coin->chain->pubtype,waddr->rmd160,20);
} }
bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv); bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33); bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33);
printf("%s persistent.(%s) (%s)\n",coin->symbol,myinfo->myaddr.BTC,coinaddr); printf("%s persistent.(%s) (%s) change.(%s) scriptstr.(%s)\n",coin->symbol,myinfo->myaddr.BTC,coinaddr,coin->changeaddr,scriptstr);
jaddistr(addresses,coinaddr); jaddistr(addresses,coinaddr);
if ( (rawtx= iguana_calcrawtx(myinfo,coin,&vins,txobj,satoshis,coin->changeaddr,txfee,addresses,minconf)) != 0 && vins != 0 ) valsobj = cJSON_CreateObject();
jaddstr(valsobj,"coin",coin->symbol);
jadd64bits(valsobj,"amount",satoshis);
jadd64bits(valsobj,"txfee",txfee);
jaddnum(valsobj,"minconf",minconf);
rawtxtag = (uint32_t)rand();
jaddnum(valsobj,"rawtxtag",rawtxtag);
jaddnum(valsobj,"locktime",locktime);
argjson = cJSON_CreateObject();
jaddnum(argjson,"timeout",15000);
if ( (retstr= iguana_rawtx(myinfo,coin,argjson,0,coin->changeaddr,addresses,valsobj,scriptstr)) != 0 )
{ {
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx)) != 0 ) printf("feetx got.(%s)\n",retstr);
flag = 0;
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{ {
iguana_unspentslock(myinfo,coin,vins); if ( (rawtx= jstr(retjson,"result")) != 0 && (vins= jobj(retjson,"vins")) != 0 )
//avail = iguana_availunspents(myinfo,&unspents,&num,coin,coin->chain->minconfirms,"*",coin->blockspace,sizeof(coin->blockspace)); flag = 1;
//if ( (feetx= iguana_signunspents(myinfo,coin,&signedtxid,&completed,txobj,swap->insurance,coin->changeaddr,coin->txfee,unspents,num)) != 0 ) }
//{ if ( flag == 0 )
tx = calloc(1,sizeof(*tx) + strlen(rawtx) + 1); {
strcpy(tx->txbytes,signedtx); vins = 0;
tx->txid = signedtxid; if ( (rawtx= iguana_pollrawtx(&myinfo->rawtxQ,&vins,rawtxtag,OS_milliseconds() + 10000)) != 0 )
printf("%s feetx.%s\n",myside != 0 ? "BOB" : "ALICE",signedtx); {
//disp_tx(myinfo,coin,"feetx",feetx); if ( vins != 0 )
free(signedtx); flag = 2;
} free(rawtx); }
}
if ( flag != 0 )
{
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx)) != 0 )
{
iguana_unspentslock(myinfo,coin,vins);
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);
free(signedtx);
}
}
if ( retjson != 0 )
free_json(retjson);
if ( flag == 2 )
{
free_json(vins);
free(rawtx);
}
free(retstr);
} else printf("error creating %s feetx\n",myside != 0 ? "BOB" : "ALICE"); } else printf("error creating %s feetx\n",myside != 0 ? "BOB" : "ALICE");
free_json(addresses); free_json(addresses);
free_json(argjson);
return(tx); return(tx);
} }
struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin) struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin)
{ {
int32_t n; cJSON *txobj; uint8_t paymentscript[128]; struct bitcoin_statetx *ptr = 0; uint64_t r; int32_t n; uint8_t paymentscript[128]; char scriptstr[512]; struct bitcoin_statetx *ptr = 0; uint64_t r;
r = swap->mine.orderid ^ swap->other.orderid; r = swap->mine.orderid ^ swap->other.orderid;
n = instantdex_outputinsurance(paymentscript,swap->insurance,r,r * (strcmp("BTC",coin->symbol) == 0)); n = instantdex_outputinsurance(paymentscript,swap->insurance,r,r * (strcmp("BTC",coin->symbol) == 0));
txobj = bitcoin_txcreate(coin,0); init_hexbytes_noT(scriptstr,paymentscript,n);
bitcoin_txoutput(coin,txobj,paymentscript,n,swap->insurance); printf("feetx %.8f (%s)\n",dstr(swap->insurance),scriptstr);
ptr = instantdex_signtx(myinfo,coin,txobj,swap->insurance,coin->txfee,swap->mine.minconfirms,A->offer.myside); ptr = instantdex_signtx(myinfo,coin,0,scriptstr,swap->insurance,coin->txfee,swap->mine.minconfirms,A->offer.myside);
free_json(txobj);
return(ptr); return(ptr);
} }
@ -193,17 +226,15 @@ 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) 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; struct bitcoin_statetx *ptr = 0; uint8_t script[1024],secret[20]; uint32_t locktime; int64_t satoshis; int32_t n,secretstart; struct bitcoin_statetx *ptr = 0; uint8_t script[1024],secret[20]; uint32_t locktime; int64_t satoshis; char scriptstr[512];
if ( coin == 0 ) if ( coin == 0 )
return(0); return(0);
locktime = (uint32_t)(reftime + INSTANTDEX_LOCKTIME * (1 + depositflag)); locktime = (uint32_t)(reftime + INSTANTDEX_LOCKTIME * (1 + depositflag));
txobj = bitcoin_txcreate(coin,locktime);
calc_rmd160_sha256(secret,priv.bytes,sizeof(priv)); calc_rmd160_sha256(secret,priv.bytes,sizeof(priv));
n = instantdex_bobscript(script,0,&secretstart,locktime,pub1,secret,pub2); n = instantdex_bobscript(script,0,&secretstart,locktime,pub1,secret,pub2);
satoshis = amount + depositflag*swap->insurance*100; satoshis = amount + depositflag*swap->insurance*100;
bitcoin_txoutput(coin,txobj,script,n,satoshis); init_hexbytes_noT(scriptstr,script,n);
ptr = instantdex_signtx(myinfo,coin,txobj,satoshis,coin->txfee,swap->mine.minconfirms,swap->mine.offer.myside); ptr = instantdex_signtx(myinfo,coin,locktime,scriptstr,satoshis,coin->txfee,swap->mine.minconfirms,swap->mine.offer.myside);
free_json(txobj);
return(ptr); return(ptr);
} }
@ -284,14 +315,12 @@ int32_t instantdex_altpaymentverify(struct supernet_info *myinfo,struct iguana_i
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) 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; uint8_t script[1024]; struct bitcoin_statetx *ptr = 0; int32_t n; uint8_t script[1024]; char scriptstr[2048]; struct bitcoin_statetx *ptr = 0;
if ( altcoin != 0 ) if ( altcoin != 0 )
{ {
txobj = bitcoin_txcreate(altcoin,0);
n = instantdex_alicescript(script,0,msigaddr,altcoin->chain->p2shtype,pubAm,pubBn); n = instantdex_alicescript(script,0,msigaddr,altcoin->chain->p2shtype,pubAm,pubBn);
bitcoin_txoutput(altcoin,txobj,script,n,amount); init_hexbytes_noT(scriptstr,script,n);
ptr = instantdex_signtx(myinfo,altcoin,txobj,amount,altcoin->txfee,swap->mine.minconfirms,swap->mine.offer.myside); ptr = instantdex_signtx(myinfo,altcoin,0,scriptstr,amount,altcoin->txfee,swap->mine.minconfirms,swap->mine.offer.myside);
free_json(txobj);
} }
return(ptr); return(ptr);
} }

Loading…
Cancel
Save