Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
f74750332f
  1. 1
      deprecated/obsolete.h
  2. 2
      iguana/exchanges777.h
  3. 5
      iguana/iguana_instantdex.c
  4. 6
      iguana/iguana_realtime.c
  5. 90
      iguana/swaps/iguana_BTCswap.c

1
deprecated/obsolete.h

@ -17022,5 +17022,6 @@ len = 0;
instantdex_addevent(s,*n,"BOB_idle","BTCoffer","poll","BTC_waitdeck"); // send deck + Chose
instantdex_addevent(s,*n,"ALICE_idle","BTCoffer","poll","BTC_waitdeck");*/
#endif
#endif

2
iguana/exchanges777.h

@ -161,7 +161,7 @@ struct bitcoin_swapinfo
uint64_t altsatoshis,BTCsatoshis,insurance,altinsurance;
int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate;
struct bitcoin_statetx *deposit,*payment,*altpayment,*myfee,*otherfee;
char expectedcmdstr[16],status[16],waitfortx[16];
char status[16],waitfortx[16];
struct instantdex_stateinfo *state; struct instantdex_accept mine,other;
struct iguana_info *coinbtc,*altcoin; uint8_t secretAm[20],secretBn[20];
uint32_t expiration,dead,reftime,btcconfirms,altconfirms,locktime;

5
iguana/iguana_instantdex.c

@ -1176,7 +1176,7 @@ struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct ex
swap->othertrader = jbits256(argjson,"traderpub");
swap->altsatoshis = myap->offer.basevolume64;
swap->BTCsatoshis = instantdex_BTCsatoshis(myap->offer.price64,myap->offer.basevolume64);
swap->btcconfirms = 1 + sqrt(dstr(swap->BTCsatoshis) * .1);
swap->btcconfirms = 0 * (1 + sqrt(dstr(swap->BTCsatoshis) * .1));
swap->altconfirms = swap->btcconfirms * 3;
swap->insurance = (swap->BTCsatoshis / INSTANTDEX_INSURANCEDIV);
swap->altinsurance = (swap->altsatoshis / INSTANTDEX_INSURANCEDIV);
@ -1353,7 +1353,10 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
printf("OTHER SIDE sent packet\n");
}
if ( swap->cutverified == 0 && swap->choosei >= 0 && serdatalen == sizeof(swap->privkeys) )
{
printf("cutverfied.%d choosei.%d privkeyextract\n",swap->cutverified,swap->choosei);
instantdex_privkeyextract(myinfo,swap,serdata,serdatalen);
}
printf("found existing state machine %llx choosei.%d other.%d\n",(long long)A.orderid,swap->choosei,swap->otherchoosei);
newjson = instantdex_parseargjson(myinfo,exchange,swap,argjson,0);
if ( serdatalen == sizeof(swap->otherdeck) && swap->choosei < 0 && (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 )

6
iguana/iguana_realtime.c

@ -173,7 +173,7 @@ void iguana_RTspendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
}
else
{
printf("RTspendvectors calculated to %d [%d]\n",coin->RTheight,bp->hdrsi);
//printf("RTspendvectors calculated to %d [%d]\n",coin->RTheight,bp->hdrsi);
bp->converted = 1;
for (hdrsi=num=0; hdrsi<bp->hdrsi; hdrsi++)
{
@ -186,14 +186,14 @@ void iguana_RTspendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
#endif
num += iguana_convert(coin,IGUANA_NUMHELPERS,coin->bundles[hdrsi],1,orignumemit);
}
printf("RTspendvectors converted.%d to %d\n",num,coin->RTheight);
//printf("RTspendvectors converted.%d to %d\n",num,coin->RTheight);
bp->converted = (uint32_t)time(NULL);
if ( iguana_balancegen(coin,1,bp,coin->RTstarti,coin->RTheight > 0 ? coin->RTheight-1 : bp->n-1,orignumemit) < 0 )
{
printf("balancegen error\n");
coin->RTdatabad = 1;
}
else if ( coin->RTgenesis == 0 )//&& coin->firstRTgenesis == 0 )
else if ( coin->RTgenesis == 0 && coin->firstRTgenesis == 0 )
coin->firstRTgenesis++, printf(">>>>>> IGUANA %s READY FOR REALTIME RPC <<<<<<\n",coin->symbol);
//printf("iguana_balancegen [%d] (%d to %d)\n",bp->hdrsi,coin->RTstarti,(coin->RTheight-1)%bp->n);
coin->RTstarti = (coin->RTheight % bp->n);

90
iguana/swaps/iguana_BTCswap.c

@ -55,7 +55,7 @@ Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start o
int32_t instantdex_bobscript(uint8_t *script,int32_t n,uint32_t *locktimep,int32_t *secretstartp,struct bitcoin_swapinfo *swap,int32_t depositflag)
{
uint8_t pubkeyA[33],pubkeyB[33],*secret160; bits256 cltvpub,destpub;
uint8_t pubkeyA[33],pubkeyB[33],*secret160; bits256 cltvpub,destpub; int32_t i;
*locktimep = swap->locktime;
if ( depositflag != 0 )
{
@ -74,6 +74,13 @@ int32_t instantdex_bobscript(uint8_t *script,int32_t n,uint32_t *locktimep,int32
pubkeyA[0] = 0x03;
pubkeyB[0] = 0x02;
}
if ( bits256_nonz(cltvpub) == 0 || bits256_nonz(destpub) == 0 )
return(-1);
for (i=0; i<20; i++)
if ( secret160[i] != 0 )
break;
if ( i < 20 )
return(-1);
memcpy(pubkeyA+1,cltvpub.bytes,sizeof(cltvpub));
memcpy(pubkeyB+1,destpub.bytes,sizeof(destpub));
script[n++] = SCRIPT_OP_IF;
@ -119,6 +126,31 @@ void disp_tx(struct supernet_info *myinfo,struct iguana_info *coin,char *str,cha
printf("disp_tx (%s) -> %s.(%s)\n",txbytes,str,jprint(txobj,1));
}
struct bitcoin_statetx *instantdex_getstatetx(struct bitcoin_swapinfo *swap,char *txname)
{
//char *txnames[] = { "fee", "dep", "alt", "acl", "bre", "bcl", "bfr", "are", "adp" };
if ( strcmp(txname,"fee") == 0 )
return(swap->otherfee);
else if ( strcmp(txname,"dep") == 0 )
return(swap->deposit);
else if ( strcmp(txname,"alt") == 0 )
return(swap->altpayment);
else if ( strcmp(txname,"acl") == 0 )
return(swap->payment);
else if ( strcmp(txname,"bre") == 0 )
return(swap->deposit);
else if ( strcmp(txname,"bcl") == 0 )
return(swap->altpayment);
else if ( strcmp(txname,"bfr") == 0 )
return(swap->myfee);
else if ( strcmp(txname,"are") == 0 )
return(swap->altpayment);
else if ( strcmp(txname,"adp") == 0 )
return(swap->deposit);
printf("unrecognized txname.(%s)\n",txname);
return(0);
}
void iguana_addinputs(struct iguana_info *coin,struct bitcoin_spend *spend,cJSON *txobj,uint32_t sequence)
{
int32_t i,j,plen; uint8_t *pubkeyptrs[16];
@ -245,10 +277,10 @@ int32_t instantdex_feetxverify(struct supernet_info *myinfo,struct iguana_info *
{
for (i=0; i<n; i++)
printf("%02x",script[i]);
printf("fee script\n");
printf(" fee script\n");
for (i=0; i<n; i++)
printf("%02x",msgtx.vouts[0].pk_script[i]);
printf("feetx mismatched\n");
printf(" feetx mismatched\n");
}
} else printf("pk_scriptlen %d mismatch %d\n",msgtx.vouts[0].pk_scriptlen,n);
free_json(txobj);
@ -257,18 +289,18 @@ int32_t instantdex_feetxverify(struct supernet_info *myinfo,struct iguana_info *
return(retval);
}
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,uint32_t reftime,int64_t amount,int32_t depositflag)
{
int32_t n,secretstart; struct bitcoin_statetx *ptr = 0; uint8_t script[1024]; uint32_t locktime; int64_t satoshis; char scriptstr[512];
if ( coin == 0 )
return(0);
if ( bits256_nonz(pub1) == 0 || bits256_nonz(pub2) == 0 )
satoshis = amount + depositflag*swap->insurance*100 + swap->coinbtc->chain->txfee;
n = instantdex_bobscript(script,0,&locktime,&secretstart,swap,depositflag);
if ( n < 0 )
{
printf("instantdex_bobtx null pub1.%llx or pub2.%llx\n",(long long)pub1.txid,(long long)pub2.txid);
printf("instantdex_bobtx couldnt generate bobscript\n");
return(0);
}
satoshis = amount + depositflag*swap->insurance*100 + swap->coinbtc->chain->txfee;
n = instantdex_bobscript(script,0,&locktime,&secretstart,swap,depositflag);
printf("locktime.%u amount %.8f satoshis %.8f\n",locktime,dstr(amount),dstr(satoshis));
init_hexbytes_noT(scriptstr,script,n);
if ( (ptr= instantdex_signtx(depositflag != 0 ? "deposit" : "payment",myinfo,coin,locktime,scriptstr,satoshis,coin->txfee,swap->mine.minconfirms,swap->mine.offer.myside)) != 0 )
@ -286,9 +318,10 @@ int32_t instantdex_paymentverify(struct supernet_info *myinfo,struct iguana_info
if ( coin != 0 && swap->deposit != 0 )
{
amount = swap->BTCsatoshis + depositflag*swap->insurance*100 + swap->coinbtc->chain->txfee;
if ( (n= instantdex_bobscript(script,0,&locktime,&secretstart,swap,depositflag)) <= 0 )
return(retval);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,swap->deposit->txbytes)) != 0 )
{
n = instantdex_bobscript(script,0,&locktime,&secretstart,swap,depositflag);
memcpy(&script[secretstart],&msgtx.vouts[0].pk_script[secretstart],20);
printf("locktime.%u amount %.8f satoshis %.8f\n",locktime,dstr(amount),dstr(amount));
if ( msgtx.lock_time == locktime && msgtx.vouts[0].value == amount && n == msgtx.vouts[0].pk_scriptlen )
@ -330,7 +363,8 @@ int32_t instantdex_altpaymentverify(struct supernet_info *myinfo,struct iguana_i
{
if ( memcmp(script,msgtx.vouts[0].pk_script,n) == 0 )
{
printf("deposit script verified\n");
printf("altpayment script verified\n");
retval = 0;
}
else
{
@ -604,6 +638,7 @@ void instantdex_newjson(struct supernet_info *myinfo,struct bitcoin_swapinfo *sw
{
jaddbits256(newjson,"altpaymenttxid",swap->altpayment->txid);
jaddstr(newjson,"altpayment",swap->altpayment->txbytes);
jaddstr(newjson,"altmsigaddr",swap->altpayment->destaddr);
printf("add altpayment.(%s) have.%x\n",swap->altpayment->txbytes,swap->havestate);
}
jaddbits256(newjson,"A0",swap->mypubs[0]);
@ -753,7 +788,7 @@ cJSON *BTC_waitfeefunc(struct supernet_info *myinfo,struct exchange_info *exchan
jaddstr(newjson,"virtevent","feefound");
if ( instantdex_isbob(swap) != 0 )
{
if ( swap->deposit == 0 && (swap->deposit= instantdex_bobtx(myinfo,swap,coinbtc,swap->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->choosei],swap->reftime,swap->BTCsatoshis,1)) == 0 )
if ( swap->deposit == 0 && (swap->deposit= instantdex_bobtx(myinfo,swap,coinbtc,swap->reftime,swap->BTCsatoshis,1)) == 0 )
printf("bobtx deposit couldnt be created\n");
}
}
@ -790,13 +825,12 @@ cJSON *BTC_waitaltpaymentfunc(struct supernet_info *myinfo,struct exchange_info
{
if ( instantdex_isbob(swap) != 0 )
{
strcmp(swap->expectedcmdstr,"BTCalttx");
if ( instantdex_altpaymentverify(myinfo,swap->altcoin,swap,argjson) == 0 )
{
if ( swap->payment == 0 && (swap->payment= instantdex_bobtx(myinfo,swap,swap->coinbtc,swap->mypubs[1],swap->otherpubs[0],swap->privkeys[swap->otherchoosei],swap->reftime,swap->BTCsatoshis,0)) == 0 )
if ( swap->payment == 0 && (swap->payment= instantdex_bobtx(myinfo,swap,swap->coinbtc,swap->reftime,swap->BTCsatoshis,0)) == 0 )
printf("couldnt create Bob's payment\n");
jaddstr(newjson,"virtevent","altfound");
}
} else printf("alt payment didnt verify\n");
} else jaddstr(newjson,"virtevent","altfound");
}
return(newjson);
@ -809,7 +843,6 @@ cJSON *BTC_waitpaymentfunc(struct supernet_info *myinfo,struct exchange_info *ex
{
if ( instantdex_isbob(swap) == 0 )
{
strcmp(swap->expectedcmdstr,"BTCpaytx");
if ( instantdex_paymentverify(myinfo,iguana_coinfind(swap->mine.offer.base),swap,argjson,0) == 0 )
jaddstr(newjson,"virtevent","payfound");
} else jaddstr(newjson,"virtevent","payfound");
@ -843,31 +876,6 @@ cJSON *BTC_cleanupfunc(struct supernet_info *myinfo,struct exchange_info *exchan
return(newjson);
}
struct bitcoin_statetx *instantdex_getstatetx(struct bitcoin_swapinfo *swap,char *txname)
{
//char *txnames[] = { "fee", "dep", "alt", "acl", "bre", "bcl", "bfr", "are", "adp" };
if ( strcmp(txname,"fee") == 0 )
return(swap->otherfee);
else if ( strcmp(txname,"dep") == 0 )
return(swap->deposit);
else if ( strcmp(txname,"alt") == 0 )
return(swap->altpayment);
else if ( strcmp(txname,"acl") == 0 )
return(swap->payment);
else if ( strcmp(txname,"bre") == 0 )
return(swap->deposit);
else if ( strcmp(txname,"bcl") == 0 )
return(swap->altpayment);
else if ( strcmp(txname,"bfr") == 0 )
return(swap->myfee);
else if ( strcmp(txname,"are") == 0 )
return(swap->altpayment);
else if ( strcmp(txname,"adp") == 0 )
return(swap->deposit);
printf("unrecognized txname.(%s)\n",txname);
return(0);
}
struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
{
struct instantdex_stateinfo *s = 0;
@ -1014,7 +1022,7 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta
{
if ( strcmp("poll",state->events[i].sendcmd) == 0 )
{
printf("POLL for pending tx expected.(%s) (%s)\n",swap->expectedcmdstr,swap->waitfortx);
printf("POLL for pending tx (%s)\n",swap->waitfortx);
//return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,myinfo->myaddr.persistent,0,serdata,serdatalen,0));
}
else

Loading…
Cancel
Save