jl777 8 years ago
parent
commit
eddf0f1851
  1. 20
      basilisk/basilisk_swap.c
  2. 7
      iguana/iguana777.c
  3. 2
      iguana/tests/request

20
basilisk/basilisk_swap.c

@ -24,7 +24,7 @@
e) BEFORE Bob broadcasts deposit, Alice broadcasts BTC denominated fee in cltv so if trade isnt done fee is reclaimed
*/
//#define DISABLE_CHECKSIG
//#define DISABLE_CHECKSIG // unsolved MITM (evil peer)
/*
both fees are standard payments: OP_DUP OP_HASH160 FEE_RMD160 OP_EQUALVERIFY OP_CHECKSIG
@ -287,13 +287,13 @@ bits256 basilisk_swap_broadcast(char *name,struct supernet_info *myinfo,struct b
int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr)
{
char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; uint32_t timestamp; struct vin_info *V; uint32_t locktime=0;
char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; uint32_t timestamp,sequenceid=0xffffffff; struct vin_info *V; uint32_t locktime=0;
V = calloc(16,sizeof(*V));
timestamp = swap->started;
if ( dest == &swap->aliceclaim )
locktime = (timestamp + INSTANTDEX_LOCKTIME + 3);
locktime = swap->bobdeposit.locktime - 1, sequenceid = 0;
else if ( dest == &swap->bobreclaim )
locktime = (timestamp + 2*INSTANTDEX_LOCKTIME + 3);
locktime = swap->bobpayment.locktime - 1, sequenceid = 0;
V[0].signers[0].privkey = privkey;
bitcoin_pubkey33(myinfo->ctx,V[0].signers[0].pubkey,privkey);
privkeys = cJSON_CreateArray();
@ -321,7 +321,6 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b
V[0].userdatalen = userdatalen;
init_hexbytes_noT(hexstr,userdata,userdatalen);
jaddstr(item,"userdata",hexstr);
//jaddnum(item,"sequence",0);
#ifdef DISABLE_CHECKSIG
needsig = 0;
#endif
@ -335,8 +334,7 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b
jaddstr(sobj,"hex",hexstr);
jadd(item,"scriptPubKey",sobj);
jaddnum(item,"suppress",dest->suppress_pubkeys);
//if ( locktime != 0 )
// jaddnum(item,"sequence",0);
jaddnum(item,"sequence",sequenceid);
if ( (dest->redeemlen= rawtx->redeemlen) != 0 )
{
init_hexbytes_noT(hexstr,rawtx->redeemscript,rawtx->redeemlen);
@ -1522,7 +1520,7 @@ void basilisk_swaploop(void *_swap)
fprintf(stderr,"start swap\n");
maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + 300;
expiration = (uint32_t)time(NULL) + 600;
myinfo->DEXactive = expiration;
while ( time(NULL) < expiration )
{
@ -1533,7 +1531,7 @@ void basilisk_swaploop(void *_swap)
basilisk_waitchoosei(myinfo,swap,data,maxlen); // wait for choosei 0x08
if ( (swap->statebits & (0x08|0x02)) == (0x08|0x02) )
break;
sleep(3);
sleep(1);
}
while ( time(NULL) < expiration )
{
@ -1544,7 +1542,7 @@ void basilisk_swaploop(void *_swap)
swap->statebits |= 0x20;
break;
}
sleep(3 + (swap->iambob == 0)*10);
sleep(1);//3 + (swap->iambob == 0)*10);
}
if ( time(NULL) >= expiration )
retval = -1;
@ -1641,7 +1639,7 @@ void basilisk_swaploop(void *_swap)
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
if ( (swap->otherstatebits & 0x80) != 0 && (swap->statebits & 0x80) != 0 )
break;
sleep(3 + (swap->iambob == 0)*10);
sleep(1);//3 + (swap->iambob == 0)*10);
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
basilisk_sendstate(myinfo,swap,data,maxlen);
if ( (swap->otherstatebits & 0x80) == 0 )

7
iguana/iguana777.c

@ -882,7 +882,12 @@ void iguana_coinloop(void *arg)
if ( coin->started == 0 && coin->active != 0 )
{
iguana_callcoinstart(myinfo,coin);
/*if ( 0 && strcmp("BTC",coin->symbol) == 0 )
/*if ( strcmp("BTC",coin->symbol) == 0 )
{
uint8_t redeemscript;
n = bitcoin_checklocktimeverify(redeemscript,n,time(NULL)+300);
}
if ( 0 && strcmp("BTC",coin->symbol) == 0 )
{
char *txstr = "0100000001d378ebd1b0c230b4d078288cf95fe28d7b3032d28c47de22ed6140d845dcb01f00000000d147304402204dd322834ff15cf1526dae3940521bb504b365b194515725d9c0f81dfbeae68d02205fb8fd269e3f2ddf7d0a17b056d2904ce572b8f22edeb39cd4c209fcf5244645011d74c7e7d8a2041be600e74708276d79ff001e754269b6e868ccf517f87f3d004c674c6763040cd6e557b175210326af93b75917b4903d7acdf8e2a560357ce18b7615cc7de02ade4f62861a57dfac67a9149c41c06aac6a7fcfd29eef87c4a633b9126b8b09882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68ffffffff01127b0000000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000";
cJSON *txobj = cJSON_Parse("{\"version\":1,\"locktime\":1474666158,\"vin\":[{\"userdata\":\"51\",\"txid\":\"fc97c3675c83c09723e0b14292ddec73820cb7352166ace4fe81ed62568315f2\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a914b7a2e599edb55d3f78ebcbfd49e82dd9a12adc2487\"},\"suppress\":1,\"sequence\":0,\"redeemScript\":\"6304ae9ee557b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a914adfad35d6646a0514011ba6ab53462319b651f96882103225046c9947222ab04acdefe2ed5dec4dcb593c5e6ae58e2c61c7ace14d81b70ac68\"}],\"vout\":[{\"satoshis\":\"36042\",\"scriptPubkey\":{\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\"}}]}");

2
iguana/tests/request

@ -1,2 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":0.1,\"dest\":\"BTC\",\"minprice\":0.002}}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":0.03,\"dest\":\"BTC\",\"minprice\":0.002}}"

Loading…
Cancel
Save