From fb74f7a0ec627c8456d5b615a7736e35742c43fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Feb 2016 13:48:26 -0300 Subject: [PATCH] test --- iguana/exchanges777.h | 2 +- iguana/iguana_instantdex.c | 6 ++++++ iguana/main.c | 6 +++--- iguana/swaps/iguana_BTCswap.c | 22 +++++++++++++++------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges777.h b/iguana/exchanges777.h index f0129a0f2..60c320bbd 100755 --- a/iguana/exchanges777.h +++ b/iguana/exchanges777.h @@ -19,7 +19,7 @@ #include #include -#define INSTANTDEX_OFFERDURATION 3600 +#define INSTANTDEX_OFFERDURATION 300 #define EXCHANGES777_MINPOLLGAP 3 #define EXCHANGES777_MAXDEPTH 200 diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index f8f1cb8b9..0a0b31359 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -334,6 +334,9 @@ int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson) ap->orderid = j64bits(argjson,"i"); if ( hash.txid != ap->orderid ) { + int32_t i; + for (i=0; iorderid); return(-1); } @@ -369,6 +372,7 @@ cJSON *instantdex_acceptsendjson(struct instantdex_accept *ap) jaddnum(json,"d",ap->A.acceptdir); jadd64bits(json,"p",ap->A.price64); jadd64bits(json,"v",ap->A.basevolume64); + jadd64bits(json,"o",ap->A.offer64); jadd64bits(json,"i",ap->orderid); return(json); } @@ -390,6 +394,8 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms if ( (traderip= jstr(argjson,"traderip")) != 0 && strcmp(traderip,myinfo->ipaddr) == 0 ) { printf("got my own request\n"); + if ( instantdex_acceptextract(&A,argjson) < 0 ) + return(clonestr("{\"error\":\"hash txid mismatches orderid\"}")); return(clonestr("{\"result\":\"got my own request\"}")); } if ( (orderidstr= jstr(argjson,"id")) != 0 ) diff --git a/iguana/main.c b/iguana/main.c index a47c4b494..90f7e7998 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -1099,10 +1099,10 @@ void iguana_main(void *arg) #ifdef __APPLE__ sleep(1); char *str; - strcpy(MYINFO.rpcsymbol,"BTC"); + strcpy(MYINFO.rpcsymbol,"BTCD"); iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}")); - if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTC\",\"active\":0}"),0)) != 0 ) + if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTCD\",\"active\":0}"),0)) != 0 ) { printf("got.(%s)\n",str); free(str); @@ -1110,7 +1110,7 @@ void iguana_main(void *arg) sleep(1); static bits256 txid; bitcoin_txtest(iguana_coinfind(MYINFO.rpcsymbol),"000",txid); - getchar(); + //getchar(); #endif } if ( arg != 0 ) diff --git a/iguana/swaps/iguana_BTCswap.c b/iguana/swaps/iguana_BTCswap.c index 79b43589b..40b0e6cc7 100755 --- a/iguana/swaps/iguana_BTCswap.c +++ b/iguana/swaps/iguana_BTCswap.c @@ -113,7 +113,7 @@ struct bitcoin_unspent *instantdex_bestfit(struct iguana_info *coin,struct bitco struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numunspentsp) { - struct bitcoin_unspent *ups = calloc(1,sizeof(*ups)); //uint8_t addrtype; + struct bitcoin_unspent *ups = calloc(1,sizeof(*ups)); uint8_t addrtype; // struct bitcoin_unspent { bits256 txid,privkey; uint64_t value; int32_t vout; }; *numunspentsp = 0; return(ups); @@ -302,11 +302,18 @@ int32_t instantdex_calcx20(char hexstr[41],uint8_t *p2shscript,uint8_t firstbyte char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exchange,char *othercoin,double othervolume,double maxprice) // Bob sending to network (Alice) { char *str,coinaddr[64],xstr[41]; uint8_t xscript[64]; struct iguana_info *other; int32_t isbob = 1; - struct instantdex_accept A; cJSON *newjson; bits256 hash,pub3,sharedprivs[4]; + struct instantdex_accept checkA,A; cJSON *newjson; bits256 hash,pub3,sharedprivs[4]; if ( othercoin == 0 || (other= iguana_coinfind(othercoin)) == 0 ) return(clonestr("{\"error\":\"invalid othercoin\"}")); hash = instantdex_acceptset(&A,othercoin,"BTC",INSTANTDEX_OFFERDURATION,1,-1,maxprice,othervolume,myinfo->myaddr.nxt64bits); newjson = instantdex_acceptsendjson(&A); + if ( instantdex_acceptextract(&checkA,newjson) < 0 ) + { + int32_t i; + for (i=0; ipersistent_priv,hash,0x02+isbob) != 4 ) return(clonestr("{\"error\":\"highly unlikely run of 02 pubkeys\"}")); pub3 = jbits256(newjson,"B3"); @@ -329,9 +336,10 @@ void instantdex_pendingnotice(struct supernet_info *myinfo,struct exchange_info ap->pendingvolume64 -= A->A.basevolume64; } -cJSON *instantdex_newjson(struct supernet_info *myinfo,bits256 *A0p,bits256 *B0p,bits256 *sharedprivs,uint8_t secret160[20],int32_t isbob,cJSON *argjson,bits256 hash) +cJSON *instantdex_newjson(struct supernet_info *myinfo,bits256 *A0p,bits256 *B0p,bits256 *sharedprivs,uint8_t secret160[20],int32_t isbob,cJSON *argjson,bits256 hash,struct instantdex_accept *A) { - cJSON *newjson = cJSON_CreateObject(); char *xstr; + cJSON *newjson; char *xstr; + newjson = instantdex_acceptsendjson(A); if ( instantdex_pubkeyargs(sharedprivs,newjson,3+isbob,myinfo->persistent_priv,hash,0x02+isbob) != 3 ) return(0); if ( isbob == 0 ) @@ -370,7 +378,7 @@ char *instantdex_bailinrefund(struct supernet_info *myinfo,struct iguana_info *c cJSON *instantdex_payout(struct supernet_info *myinfo,struct iguana_info *coin,struct exchange_info *exchange,struct instantdex_accept *A,uint8_t secret160[20],int32_t isbob,bits256 *A0p,bits256 *B0p,bits256 *sharedprivs,bits256 hash,uint64_t satoshis[2],cJSON *argjson) { cJSON *newjson; char field[32],payoutsigstr[256],*signedpayout; int32_t payoutsiglen; bits256 payouttxid,bailintxid; - if ( (newjson= instantdex_newjson(myinfo,A0p,B0p,sharedprivs,secret160,isbob,argjson,hash)) == 0 ) + if ( (newjson= instantdex_newjson(myinfo,A0p,B0p,sharedprivs,secret160,isbob,argjson,hash,A)) == 0 ) return(0); sprintf(field,"bailintxid%c",'A' + (isbob^1)), bailintxid = jbits256(argjson,field); sprintf(field,"payoutsig%c",'A' + (isbob^1)); @@ -388,7 +396,7 @@ cJSON *instantdex_payout(struct supernet_info *myinfo,struct iguana_info *coin,s char *instantdex_advance(struct supernet_info *myinfo,bits256 *sharedprivs,int32_t isbob,cJSON *argjson,bits256 hash,char *addfield,char *nextstate,struct instantdex_accept *A) { cJSON *newjson; bits256 A0,B0; uint8_t secret160[20]; - if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash)) == 0 ) + if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash,A)) == 0 ) return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}")); if ( A->statusjson != 0 && jstr(A->statusjson,addfield) != 0 ) { @@ -425,7 +433,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch if ( (ap= instantdex_acceptable(exchange,A,myinfo->myaddr.nxt64bits)) != 0 ) { isbob = 0; - if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash)) == 0 ) + if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash,A)) == 0 ) return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}")); else {