Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
c81414c357
  1. 2
      iguana/SuperNET_category.c
  2. 2
      iguana/iguana777.h
  3. 9
      iguana/iguana_blocks.c
  4. 8
      iguana/iguana_msg.c
  5. 49
      iguana/iguana_sign.c
  6. 6
      iguana/iguana_volatiles.c
  7. 23
      iguana/swaps/iguana_BTCswap.c

2
iguana/SuperNET_category.c

@ -231,7 +231,7 @@ char *bitcoin_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void
}
if ( retstr == 0 )
return(0);
printf("RELAY will return.(%s)\n",retstr);
//printf("RELAY will return.(%s)\n",retstr);
for (j=0; j<IGUANA_MAXCOINS; j++)
{
if ( (coin= Coins[j]) == 0 )

2
iguana/iguana777.h

@ -813,7 +813,7 @@ int32_t iguana_send_VPNversion(struct iguana_info *coin,struct iguana_peer *addr
void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sleepflag);
int32_t iguana_rwvout(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvout *msg);
int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg);
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr);
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen);
int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs);
cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid);
cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag);

9
iguana/iguana_blocks.c

@ -92,7 +92,8 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin
while ( coin->blockdepth > 0 )
{
sleep(1);
printf("%s >>>>>>>>>> OK only if rare %s blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth);
if ( coin->blockdepth > 0 )
printf("A %s >>>>>>>>>> OK only if rare %s blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth);
//fprintf(stderr,">>>>>>>>>> OK only if rare %s blockhashset.%d depth.%d\n",debugstr,height,depth);
//printf("%d\n",1/(1 - depth/depth));
}
@ -105,7 +106,8 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin
while ( coin->blockdepth > 0 )
{
sleep(1);
printf(" %s >>>>>>>>>> OK only if rare %s match blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth);
if ( coin->blockdepth > 0 )
printf("B %s >>>>>>>>>> OK only if rare %s match blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth);
//fprintf(stderr,">>>>>>>>>> OK only if rare%s match blockhashset.%d depth.%d\n",debugstr,height,depth);
//printf("%d\n",1/(1 - depth/depth));
}
@ -142,7 +144,8 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin
while ( coin->blockdepth > 0 )
{
sleep(1);
printf("%s >>>>>>>>>> OK only if rare %s create blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth);
if ( coin->blockdepth > 0 )
printf("C %s >>>>>>>>>> OK only if rare %s create blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth);
//fprintf(stderr,">>>>>>>>>> OK only if rare%s create blockhashset.%d depth.%d\n",debugstr,height,depth);
//printf("%d\n",1/(1 - depth/depth));
}

8
iguana/iguana_msg.c

@ -420,22 +420,24 @@ int32_t iguana_rwtx(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,s
char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid)
{
struct iguana_msgtx tx; bits256 hash2; struct iguana_block block; struct iguana_msgblock msg;
int32_t i,n,len; char *txbytes,vpnstr[64];
int32_t i,n,len,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace;
memset(&msg,0,sizeof(msg));
vpnstr[0] = 0;
extraspace = calloc(1,extralen);
len = iguana_rwblock(coin->chain->hashalgo,0,&hash2,data,&msg);
iguana_blockconv(&block,&msg,hash2,-1);
for (i=0; i<msg.txn_count; i++)
{
if ( (n= iguana_rwmsgtx(coin,0,0,&data[len],recvlen - len,&tx,&tx.txid,vpnstr)) < 0 )
if ( (n= iguana_rwmsgtx(coin,0,0,&data[len],recvlen - len,&tx,&tx.txid,vpnstr,extraspace,extralen)) < 0 )
break;
//char str[65]; printf("%d of %d: %s\n",i,msg.txn_count,bits256_str(str,tx.txid));
if ( bits256_cmp(txid,tx.txid) == 0 )
{
if ( (n= iguana_rwmsgtx(coin,0,json,&data[len],recvlen - len,&tx,&tx.txid,vpnstr)) > 0 )
if ( (n= iguana_rwmsgtx(coin,0,json,&data[len],recvlen - len,&tx,&tx.txid,vpnstr,extraspace,extralen)) > 0 )
{
txbytes = malloc(n*2+1);
init_hexbytes_noT(txbytes,&data[len],n);
free(extraspace);
return(txbytes);
}
}

49
iguana/iguana_sign.c

@ -293,7 +293,7 @@ cJSON *iguana_voutjson(struct iguana_info *coin,struct iguana_msgvout *vout,int3
return(json);
}
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr)
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen)
{
int32_t i,n,len = 0; uint8_t *txstart = serialized; char txidstr[65]; cJSON *array=0;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version);
@ -314,15 +314,15 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8
// printf("%02x",serialized[i]);
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in);
//printf(" tx_in.%08x\n",msg->tx_in);
if ( rwflag == 0 )
if ( rwflag == 0 && msg->vins == 0 )
{
if ( len + sizeof(struct iguana_msgvin)*msg->tx_in > maxsize )
if ( sizeof(struct iguana_msgvin)*msg->tx_in > extralen )
{
printf("len.%d + tx_in.%d > maxsize.%d\n",len,msg->tx_in,maxsize);
printf("len.%d + tx_in.%d > maxsize.%d\n",len,msg->tx_in,extralen);
return(-1);
}
maxsize -= (sizeof(struct iguana_msgvin) * msg->tx_in);
msg->vins = (struct iguana_msgvin *)&serialized[maxsize];
extralen -= (sizeof(struct iguana_msgvin) * msg->tx_in);
msg->vins = (struct iguana_msgvin *)&extraspace[extralen];
memset(msg->vins,0,sizeof(struct iguana_msgvin) * msg->tx_in);
}
for (i=0; i<msg->tx_in; i++)
@ -349,15 +349,15 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8
// printf("%02x",serialized[i]);
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out);
//printf(" txout.%d\n",msg->tx_out);
if ( rwflag == 0 )
if ( rwflag == 0 && msg->vouts == 0 )
{
if ( len + sizeof(struct iguana_msgvout)*msg->tx_out > maxsize )
if ( len + sizeof(struct iguana_msgvout)*msg->tx_out > extralen )
{
printf("len.%d + tx_in.%d > maxsize.%d\n",len,msg->tx_in,maxsize);
printf("len.%d + tx_in.%d > maxsize.%d\n",len,msg->tx_in,extralen);
return(-1);
}
maxsize -= (sizeof(struct iguana_msgvout) * msg->tx_out);
msg->vouts = (struct iguana_msgvout *)&serialized[maxsize];
extralen -= (sizeof(struct iguana_msgvout) * msg->tx_out);
msg->vouts = (struct iguana_msgvout *)&serialized[extralen];
memset(msg->vouts,0,sizeof(struct iguana_msgvout) * msg->tx_out);
}
for (i=0; i<msg->tx_out; i++)
@ -456,7 +456,7 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,
msg->lock_time = (int32_t)j64bits(txobj,"locktime");
msg->txid = jbits256(txobj,"txid");
*txstartp = len;
if ( (msg->allocsize= iguana_rwmsgtx(coin,1,0,&serialized[len],maxsize-len,msg,&txid,vpnstr)) < 0 )
if ( (msg->allocsize= iguana_rwmsgtx(coin,1,0,&serialized[len],maxsize-len,msg,&txid,vpnstr,0,0)) < 0 )
{
memset(txid.bytes,0,sizeof(txid));
printf("error parsing txobj\n");
@ -472,7 +472,7 @@ char *iguana_rawtxbytes(struct iguana_info *coin,cJSON *json,struct iguana_msgtx
serialized = malloc(IGUANA_MAXPACKETSIZE);
vpnstr[0] = 0;
//char str[65]; printf("%d of %d: %s\n",i,msg.txn_count,bits256_str(str,tx.txid));
if ( (n= iguana_rwmsgtx(coin,1,json,serialized,IGUANA_MAXPACKETSIZE,msgtx,&msgtx->txid,vpnstr)) > 0 )
if ( (n= iguana_rwmsgtx(coin,1,json,serialized,IGUANA_MAXPACKETSIZE,msgtx,&msgtx->txid,vpnstr,0,0)) > 0 )
{
txbytes = malloc(n*2+1);
init_hexbytes_noT(txbytes,serialized,n);
@ -502,7 +502,7 @@ char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bit
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes)
{
int32_t n,len; char vpnstr[64]; struct iguana_msgtx M; uint8_t *serialized; cJSON *txobj;
int32_t n,len; char vpnstr[64]; struct iguana_msgtx M; uint8_t *serialized,*extraspace; cJSON *txobj;
txobj = cJSON_CreateObject();
if ( msgtx == 0 )
{
@ -510,16 +510,19 @@ cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_ms
memset(msgtx,0,sizeof(M));
}
len = (int32_t)strlen(txbytes) >> 1;
serialized = malloc(len + 32768);
serialized = malloc(len);
extraspace = calloc(1,65536);
decode_hex(serialized,len,txbytes);
vpnstr[0] = 0;
memset(txidp,0,sizeof(*txidp));
if ( (n= iguana_rwmsgtx(coin,0,txobj,serialized,len + 32768,msgtx,txidp,vpnstr)) <= 0 )
if ( (n= iguana_rwmsgtx(coin,0,txobj,serialized,len,msgtx,txidp,vpnstr,extraspace,65536)) <= 0 )
{
printf("error from rwmsgtx\n");
free_json(txobj);
txobj = 0;
txobj = cJSON_CreateObject();
jaddstr(txobj,"error","couldnt decode transaction");
jaddstr(txobj,"coin",coin->symbol);
}
free(extraspace);
free(serialized);
return(txobj);
}
@ -549,7 +552,7 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,uint8_t *serialized,int32_t max
dest.vins[i].p2shlen = 0;
dest.vins[i].redeemscript = 0;
}
len = iguana_rwmsgtx(coin,1,0,serialized,maxlen,&dest,&txid,vpnstr);
len = iguana_rwmsgtx(coin,1,0,serialized,maxlen,&dest,&txid,vpnstr,0,0);
if ( len > 0 )
{
len += iguana_rwnum(1,&serialized[len],sizeof(hashtype),&hashtype);
@ -664,7 +667,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **
}
else
{
printf("SIG.%d.%d VERIFIED \n",vini,j);//%s (%s)\n",vini,*signedtx,jprint(txobj,1));
//printf("SIG.%d.%d VERIFIED \n",vini,j);//%s (%s)\n",vini,*signedtx,jprint(txobj,1));
flag++;
numsigs++;
}
@ -1029,7 +1032,7 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount
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)
{
uint8_t *serialized,*serialized2,*serialized3; int32_t i,len,n,maxsize,complete = 0; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkey,txid; cJSON *item; cJSON *txobj = 0;
uint8_t *serialized,*serialized2,*serialized3,*extraspace; int32_t i,len,n,maxsize,complete = 0; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkey,txid; cJSON *item; cJSON *txobj = 0;
maxsize = 1000000;
if ( rawtx != 0 && rawtx[0] != 0 && (len= (int32_t)strlen(rawtx)>>1) < maxsize )
{
@ -1057,7 +1060,8 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
memset(msgtx,0,sizeof(*msgtx));
if ( iguana_rwmsgtx(coin,0,0,serialized,maxsize,msgtx,&txid,"") > 0 && numinputs == msgtx->tx_in )
extraspace = calloc(1,65536);
if ( iguana_rwmsgtx(coin,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536) > 0 && numinputs == msgtx->tx_in )
{
if ( (n= cJSON_GetArraySize(privkeys)) > 0 )
{
@ -1081,6 +1085,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
}
}
}
free(extraspace);
}
free(serialized), free(serialized2), free(serialized3);
} else return(-1);

6
iguana/iguana_volatiles.c

@ -130,7 +130,11 @@ struct iguana_utxo iguana_utxofind(struct iguana_info *coin,int16_t spent_hdrsi,
*RTspendflagp = 1;
}
}
} else printf("illegal unspentind.%u vs %u hdrs.%d\n",spent_unspentind,ramchain->H.data->numunspents,spent_hdrsi);
}
else
{
printf("illegal unspentind.%u vs %u hdrs.%d\n",spent_unspentind,ramchain->H.data->numunspents,spent_hdrsi);
}
return(utxo);
}

23
iguana/swaps/iguana_BTCswap.c

@ -77,9 +77,9 @@ int32_t instantdex_outputinsurance(uint8_t *script,int64_t insurance,uint64_t r,
{
uint8_t rmd160[20]; int32_t n = 0;
decode_hex(rmd160,sizeof(rmd160),(dest % 10) == 9 ? TIERNOLAN_RMD160 : INSTANTDEX_RMD160);
script[n++] = sizeof(r);
n += iguana_rwnum(1,&script[n],sizeof(r),&r);
script[n++] = SCRIPT_OP_DROP;
//script[n++] = sizeof(r);
//n += iguana_rwnum(1,&script[n],sizeof(r),&r);
//script[n++] = SCRIPT_OP_DROP;
n = bitcoin_standardspend(script,n,rmd160);
return(n);
}
@ -184,11 +184,11 @@ struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct ig
struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin)
{
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;
n = instantdex_outputinsurance(paymentscript,swap->insurance,r,r * (strcmp("BTC",coin->symbol) == 0));
init_hexbytes_noT(scriptstr,paymentscript,n);
printf("instantdex_feetx %.8f (%s)\n",dstr(swap->insurance),scriptstr);
ptr = instantdex_signtx(myinfo,coin,0,scriptstr,swap->insurance,coin->txfee,swap->mine.minconfirms,A->offer.myside);
ptr = instantdex_signtx(myinfo,coin,0,scriptstr,swap->insurance,coin->txfee,0,A->offer.myside);
return(ptr);
}
@ -667,7 +667,7 @@ cJSON *BOB_waitfeefunc(struct supernet_info *myinfo,struct exchange_info *exchan
{
retstr = swap->otherfee->txbytes;
jaddstr(newjson,"feefound",retstr);
if ( (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->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->choosei],swap->reftime,swap->BTCsatoshis,1)) != 0 )
{
// broadcast deposit
jaddstr(newjson,"deposit",swap->deposit->txbytes);
@ -945,7 +945,7 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
s = instantdex_statecreate(s,n,"BOB_sentprivs",BTC_waitprivsfunc,0,"BTC_cleanup",0,0);
instantdex_addevent(s,*n,"BOB_sentprivs","BTCprivs","poll","BOB_waitfee");
instantdex_addevent(s,*n,"BOB_sentprivs","BTCdeckC","BTCprivs","BOB_waitfee");
instantdex_addevent(s,*n,"BOB_sentprivs","poll","poll","BOB_sentprivs");
instantdex_addevent(s,*n,"BOB_sentprivs","poll","BTCdeckC","BOB_sentprivs");
s = instantdex_statecreate(s,n,"ALICE_sentprivs",BTC_waitprivsfunc,0,"BTC_cleanup",0,0);
instantdex_addevent(s,*n,"ALICE_sentprivs","BTCprivs","poll","Alice_waitfee");
@ -960,7 +960,7 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
s = instantdex_statecreate(s,n,"Alice_waitfee",ALICE_waitfeefunc,0,"BTC_cleanup",0,0);
instantdex_addevent(s,*n,"Alice_waitfee","feefound","poll","ALICE_waitdeposit");
instantdex_addevent(s,*n,"Alice_waitfee","BTCdeckC","BTCprivs","Alice_waitfee");
instantdex_addevent(s,*n,"Alice_waitfee","poll","poll","Alice_waitfee");
instantdex_addevent(s,*n,"Alice_waitfee","poll","BTCdeckC","Alice_waitfee");
s = instantdex_statecreate(s,n,"ALICE_waitdeposit",ALICE_waitdepositfunc,0,"BTC_cleanup",0,0);
instantdex_addevent(s,*n,"ALICE_waitdeposit","depfound","BTCalttx","ALICE_sentalt");
@ -1052,9 +1052,12 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta
void instantdex_statemachine_iter(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap)
{
char *str; struct bitcoin_eventitem *ptr;
char *str; struct bitcoin_eventitem *ptr; struct iguana_info *coinbtc;
coinbtc = iguana_coinfind("BTC");
if ( instantdex_isbob(swap) != 0 && swap->myfee == 0 )
swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,iguana_coinfind("BTC"));
swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,coinbtc);
else if ( instantdex_isbob(swap) == 0 && swap->otherfee == 0 )
swap->otherfee = instantdex_feetx(myinfo,&swap->mine,swap,coinbtc);
while ( (ptr= queue_dequeue(&swap->eventsQ,0)) != 0 )
{
//printf("deQ arg.%p new.%p\n",ptr->argjson,ptr->newjson);

Loading…
Cancel
Save