diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 9dc94336e..038062743 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -898,7 +898,7 @@ int32_t instantdex_inv2data(struct supernet_info *myinfo,struct iguana_info *coi if ( instantdex_statemachinefind(0,exchange,ap->orderid) == 0 && instantdex_historyfind(0,exchange,ap->orderid) == 0 ) { encodedhash = instantdex_encodehash(ap->offer.base,ap->offer.rel,ap->offer.price64*instantdex_bidaskdir(&ap->offer),(ap->orderid&INSTANTDEX_ORDERSTATE_ORDERIDMASK) | ap->state,ap->offer.account); - if ( n < sizeof(hashes)/sizeof(*hashes) && GETBIT(ap->peerhas,addr->addrind) == 0 ) + if ( n < sizeof(hashes)/sizeof(*hashes) )//&& GETBIT(ap->peerhas,addr->addrind) == 0 ) { hashes[n++] = encodedhash; printf("(%d %llx) ",n,(long long)(ap->orderid&INSTANTDEX_ORDERSTATE_ORDERIDMASK) | ap->state); diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index c5dc49aea..dc0a4b00c 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -295,7 +295,7 @@ cJSON *iguana_voutjson(struct iguana_info *coin,struct iguana_msgvout *vout,int3 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; + int32_t i,n,len = 0,extraused=0; uint8_t *txstart = serialized; char txidstr[65]; cJSON *array=0; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( json != 0 ) { @@ -314,15 +314,18 @@ 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 && msg->vins == 0 ) + if ( rwflag == 0 ) { - if ( sizeof(struct iguana_msgvin)*msg->tx_in > extralen ) + if ( msg->vins == 0 ) { - printf("len.%d + tx_in.%d > maxsize.%d\n",len,msg->tx_in,extralen); - return(-1); - } - extralen -= (sizeof(struct iguana_msgvin) * msg->tx_in); - msg->vins = (struct iguana_msgvin *)&extraspace[extralen]; + if ( sizeof(struct iguana_msgvin)*msg->tx_in > extralen ) + { + printf("len.%d + tx_in.%d > extralen.%d\n",len,msg->tx_in,extralen); + return(-1); + } + msg->vins = (struct iguana_msgvin *)extraspace; + extraused += (sizeof(struct iguana_msgvin) * msg->tx_in); + } else printf("unexpected non-null msg->vins.%p\n",msg->vins); memset(msg->vins,0,sizeof(struct iguana_msgvin) * msg->tx_in); } for (i=0; itx_in; i++) @@ -349,15 +352,20 @@ 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 && msg->vouts == 0 ) + if ( rwflag == 0 ) { - if ( len + sizeof(struct iguana_msgvout)*msg->tx_out > extralen ) + if ( msg->vouts == 0 ) { - printf("len.%d + tx_in.%d > maxsize.%d\n",len,msg->tx_in,extralen); - return(-1); - } - extralen -= (sizeof(struct iguana_msgvout) * msg->tx_out); - msg->vouts = (struct iguana_msgvout *)&extraspace[extralen]; + if ( (extraused & 0xf) != 0 ) + extraused += 0xf - (extraused & 0xf); + if ( extraused + sizeof(struct iguana_msgvout)*msg->tx_out > extralen ) + { + printf("len.%d + tx_in.%d > extralen.%d\n",len,msg->tx_in,extralen); + return(-1); + } + msg->vouts = (struct iguana_msgvout *)&extraspace[extraused]; + extraused += (sizeof(struct iguana_msgvout) * msg->tx_out); + } else printf("unexpected non-null msg->vouts %p\n",msg->vouts); memset(msg->vouts,0,sizeof(struct iguana_msgvout) * msg->tx_out); } for (i=0; itx_out; i++) @@ -505,10 +513,8 @@ cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_ms int32_t n,len; char vpnstr[64]; struct iguana_msgtx M; uint8_t *serialized,*extraspace; cJSON *txobj; txobj = cJSON_CreateObject(); if ( msgtx == 0 ) - { msgtx = &M; - memset(msgtx,0,sizeof(M)); - } + memset(msgtx,0,sizeof(M)); len = (int32_t)strlen(txbytes) >> 1; serialized = malloc(len); extraspace = calloc(1,65536); diff --git a/iguana/swaps/iguana_BTCswap.c b/iguana/swaps/iguana_BTCswap.c index ad6a03d25..23c98ec63 100755 --- a/iguana/swaps/iguana_BTCswap.c +++ b/iguana/swaps/iguana_BTCswap.c @@ -740,21 +740,21 @@ cJSON *ALICE_waitfeefunc(struct supernet_info *myinfo,struct exchange_info *exch cJSON *ALICE_waitdepositfunc(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp) { - char *retstr; struct iguana_info *coinbtc,*altcoin; + char *retstr,msigaddr[64]; struct iguana_info *coinbtc,*altcoin; coinbtc = iguana_coinfind("BTC"); - altcoin = iguana_coinfind(swap->mine.offer.rel); + altcoin = iguana_coinfind(swap->mine.offer.base); strcpy(swap->waitfortx,"dep"); *serdatap = 0, *serdatalenp = 0; if ( swap->deposit != 0 && (retstr= BTC_txconfirmed(myinfo,coinbtc,swap,newjson,swap->deposit->txid,&swap->deposit->numconfirms,"depfound",0.5)) != 0 ) { free(retstr); - if ( instantdex_paymentverify(myinfo,iguana_coinfind("BTC"),swap,argjson,1) < 0 ) + if ( instantdex_paymentverify(myinfo,coinbtc,swap,argjson,1) < 0 ) { printf("deposit didnt verify\n"); return(cJSON_Parse("{\"error\":\"deposit didnt verify\"}")); } printf("deposit verified\n"); - if ( swap->altpayment == 0 && (swap->altpayment= instantdex_alicetx(myinfo,altcoin,swap->altpayment->destaddr,swap->pubAm,swap->pubBn,swap->altsatoshis,swap)) == 0 ) + if ( swap->altpayment == 0 && (swap->altpayment= instantdex_alicetx(myinfo,altcoin,msigaddr,swap->pubAm,swap->pubBn,swap->altsatoshis,swap)) == 0 ) printf("error creating altpayment\n"); else jaddstr(newjson,"virtevent","depfound"); }