Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
023d9c963d
  1. 47
      deprecated/obsolete.h
  2. 15
      iguana/exchanges/bitcoin.c
  3. 3
      iguana/exchanges777.h
  4. 86
      iguana/iguana_instantdex.c
  5. 51
      iguana/swaps/iguana_BTCswap.c

47
deprecated/obsolete.h

@ -13337,5 +13337,52 @@ len = 0;
printf("othersatoshis mismatch %llu vs %llu\n",(long long)satoshis,(long long)A->A.basevolume64);
return(clonestr("{\"error\":\"instantdex_BTCswap satoshis mismatch\"}"));
}
/*TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,BTCoffer,othercoin,otherassetid,maxprice,othervolume)
{
if ( remoteaddr == 0 )
return(instantdex_btcoffer(myinfo,exchanges777_find("bitcoin"),othercoin[0] != 0 ? othercoin : otherassetid,othervolume,maxprice));
else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
STRING_AND_TWO_DOUBLES(InstantDEX,ALToffer,basecoin,minprice,basevolume)
{
int32_t hops = INSTANTDEX_HOPS; cJSON *argjson; char *str; struct instantdex_accept A;
if ( remoteaddr == 0 )
{
if ( iguana_coinfind(basecoin) == 0 )
return(clonestr("{\"error\":\"InstantDEX basecoin is not active, need to addcoin\"}"));
instantdex_acceptset(&A,basecoin,"BTC",INSTANTDEX_OFFERDURATION,0,1,minprice,basevolume,myinfo->myaddr.nxt64bits);
argjson = instantdex_acceptsendjson(&A);
if ( minprice > 0. )
{
if ( (str= InstantDEX_minaccept(IGUANA_CALLARGS,basecoin,"BTC",minprice,basevolume)) != 0 )
free(str);
}
return(instantdex_sendcmd(myinfo,argjson,"ALToffer",myinfo->ipaddr,hops));
} else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
STRING_AND_TWO_DOUBLES(InstantDEX,NXToffer,assetid,minprice,basevolume)
{
int32_t hops = INSTANTDEX_HOPS; cJSON *argjson; char *base,*str; struct instantdex_accept A;
if ( remoteaddr == 0 )
{
if ( assetid == 0 || assetid[0] == 0 || strcmp(assetid,"0") == 0 || strcmp(assetid,"NXT") == 0 || strcmp(assetid,"nxt") == 0 )
base = "NXT";
else if ( is_decimalstr(assetid) <= 0 )
return(clonestr("{\"error\":\"InstantDEX NXToffer illegal assetid\"}"));
else base = assetid;
instantdex_acceptset(&A,base,"BTC",INSTANTDEX_OFFERDURATION,0,1,minprice,basevolume,myinfo->myaddr.nxt64bits);
argjson = instantdex_acceptsendjson(&A);
if ( minprice > 0. )
{
if ( (str= InstantDEX_minaccept(IGUANA_CALLARGS,base,"BTC",minprice,basevolume)) != 0 )
free(str);
}
return(instantdex_sendcmd(myinfo,argjson,"NXToffer",myinfo->ipaddr,hops));
} else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
*/
#endif

15
iguana/exchanges/bitcoin.c

@ -1497,7 +1497,7 @@ int32_t is_valid_BTCother(char *other)
uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson)
{
char *str,coinaddr[64]; uint64_t txid = 0; cJSON *tmp,*json=0; struct instantdex_accept *ap;
struct supernet_info *myinfo; uint8_t pubkey[33]; struct iguana_info *other; int32_t hops = 3;
struct supernet_info *myinfo; uint8_t pubkey[33]; struct iguana_info *other;
myinfo = SuperNET_accountfind(argjson);
printf("TRADE with myinfo.%p\n",myinfo);
if ( retstrp != 0 )
@ -1538,23 +1538,22 @@ uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,cha
jaddnum(json,"volume",volume);
jaddstr(json,"BTC",myinfo->myaddr.BTC);
//printf("trade dir.%d (%s/%s) %.6f vol %.8f\n",dir,base,"BTC",price,volume);
if ( (str= instantdex_queueaccept(myinfo,exchange,base,"BTC",price,volume,-dir,dir > 0 ? "BTC" : base,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits)) != 0 )
if ( (str= instantdex_queueaccept(myinfo,&ap,exchange,base,"BTC",price,volume,-dir,dir > 0 ? "BTC" : base,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits)) != 0 )
{
jaddstr(json,"queue",str);
if ( (tmp= cJSON_Parse(str)) != 0 )
{
txid = j64bits(json,"orderid");
if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,txid,"*","*")) != 0 )
{
if ( (str= instantdex_sendcmd(myinfo,&ap->offer,json,"BTCoffer",GENESIS_PUBKEY,hops,0,0)) != 0 )
if ( (str= instantdex_btcoffer(myinfo,exchange,ap)) != 0 )
{
json = cJSON_CreateObject();
jaddstr(json,"BTCoffer",str);
}
}
} else printf("null return from btcoffer\n");
} else printf("couldnt find just added offer\n");
free_json(tmp);
}
}
} else printf("queueaccept return parse error.(%s)\n",str);
} else printf("null return queueaccept\n");
if ( retstrp != 0 )
*retstrp = jprint(json,1);
else free_json(json);

3
iguana/exchanges777.h

@ -117,8 +117,9 @@ double truefx_price(struct exchange_info *exchange,char *base,char *rel,struct e
double fxcm_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert);
double instaforex_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert);
char *instantdex_queueaccept(struct supernet_info *myinfo,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t txid);
char *instantdex_queueaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t txid);
void instantdex_update(struct supernet_info *myinfo);
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen);
char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *ap); // Bob sending to network (Alice)
#endif

86
iguana/iguana_instantdex.c

@ -153,7 +153,9 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o
break;
memcpy(msg->serialized,reqstr,slen);
memcpy(&msg->serialized[slen],serialized,olen);
memcpy(&msg->serialized[slen + olen],extraser,extralen);
printf("extralen.%d\n",extralen);
if ( extralen > 0 )
memcpy(&msg->serialized[slen + olen],extraser,extralen);
free(reqstr);
if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 )
{
@ -393,13 +395,15 @@ struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,str
// NXT node verifies bitcoin txbytes has proper payment and cashes in with onetimepubkey
// BTC* node approves phased tx with onetimepubkey
bits256 instantdex_acceptset(struct instantdex_accept *ap,char *base,char *rel,int32_t duration,int32_t myside,int32_t acceptdir,double price,double volume,uint64_t offerbits)
bits256 instantdex_acceptset(struct instantdex_accept *ap,char *base,char *rel,int32_t duration,int32_t myside,int32_t acceptdir,double price,double volume,uint64_t offerbits,uint32_t nonce)
{
bits256 hash;
memset(ap,0,sizeof(*ap));
safecopy(ap->offer.base,base,sizeof(ap->offer.base));
safecopy(ap->offer.rel,rel,sizeof(ap->offer.rel));
OS_randombytes((uint8_t *)&ap->offer.nonce,sizeof(ap->offer.nonce));
if ( nonce == 0 )
OS_randombytes((uint8_t *)&ap->offer.nonce,sizeof(ap->offer.nonce));
else ap->offer.nonce = nonce;
if ( duration < 1000000000 )
ap->offer.expiration = (uint32_t)time(NULL) + duration;
else ap->offer.expiration = duration;
@ -410,7 +414,10 @@ bits256 instantdex_acceptset(struct instantdex_accept *ap,char *base,char *rel,i
ap->offer.basevolume64 = volume * SATOSHIDEN;
vcalc_sha256(0,hash.bytes,(void *)&ap->offer,sizeof(ap->offer));
ap->orderid = hash.txid;
//printf("(%s/%s) acceptdir.%d myside.%d\n",base,rel,acceptdir,myside);
int32_t i;
for (i=0; i<sizeof(ap->offer); i++)
printf("%02x ",((uint8_t *)&ap->offer)[i]);
printf("\n(%s/%s) %.8f %.8f acceptdir.%d myside.%d\n",base,rel,price,volume,acceptdir,myside);
return(hash);
}
@ -435,7 +442,7 @@ int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson)
} else return(-1);
//printf("price %f vol %f baserel.%d acceptdir.%d\n",price,volume,baserel,acceptdir);
traderpub = jbits256(argjson,"traderpub");
hash = instantdex_acceptset(ap,base,rel,INSTANTDEX_LOCKTIME*2,baserel,acceptdir,price,volume,traderpub.txid);
hash = instantdex_acceptset(ap,base,rel,INSTANTDEX_LOCKTIME*2,baserel,acceptdir,price,volume,traderpub.txid,0);
}
else
{
@ -607,12 +614,13 @@ char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char
return(retstr);
}
char *instantdex_queueaccept(struct supernet_info *myinfo,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t txid)
char *instantdex_queueaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t offerer)
{
struct instantdex_accept *ap; int32_t myside;
struct instantdex_accept *ap; int32_t myside; char *retstr;
*aptrp = 0;
if ( exchange != 0 )
{
ap = calloc(1,sizeof(*ap));
*aptrp = ap = calloc(1,sizeof(*ap));
if ( strcmp(mysidestr,base) == 0 )
myside = 0;
else if ( strcmp(mysidestr,rel) == 0 )
@ -622,11 +630,12 @@ char *instantdex_queueaccept(struct supernet_info *myinfo,struct exchange_info *
myside = -1;
printf("myside.(%s) != base.%s or rel.%s\n",mysidestr,base,rel);
}
instantdex_acceptset(ap,base,rel,duration,myside,acceptdir,price,basevolume,txid);
instantdex_acceptset(ap,base,rel,duration,myside,acceptdir,price,basevolume,offerer,0);
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
return(jprint(instantdex_acceptjson(ap),1));
}
else return(clonestr("{\"error\":\"invalid exchange\"}"));
retstr = jprint(instantdex_acceptjson(ap),1);
printf("acceptableQ %llu (%s)\n",(long long)ap->orderid,retstr);
return(retstr);
} else return(clonestr("{\"error\":\"invalid exchange\"}"));
}
void instantdex_update(struct supernet_info *myinfo)
@ -653,65 +662,20 @@ void instantdex_update(struct supernet_info *myinfo)
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,maxaccept,base,rel,maxprice,basevolume)
{
struct instantdex_accept *ap;
myinfo = SuperNET_accountfind(json);
if ( remoteaddr == 0 )
return(instantdex_queueaccept(myinfo,exchanges777_find("bitcoin"),base,rel,maxprice,basevolume,-1,rel,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits));
return(instantdex_queueaccept(myinfo,&ap,exchanges777_find("bitcoin"),base,rel,maxprice,basevolume,-1,rel,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits));
else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,minaccept,base,rel,minprice,basevolume)
{
struct instantdex_accept *ap;
myinfo = SuperNET_accountfind(json);
if ( remoteaddr == 0 )
return(instantdex_queueaccept(myinfo,exchanges777_find("bitcoin"),base,rel,minprice,basevolume,1,base,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits));
else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
/*TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,BTCoffer,othercoin,otherassetid,maxprice,othervolume)
{
if ( remoteaddr == 0 )
return(instantdex_btcoffer(myinfo,exchanges777_find("bitcoin"),othercoin[0] != 0 ? othercoin : otherassetid,othervolume,maxprice));
return(instantdex_queueaccept(myinfo,&ap,exchanges777_find("bitcoin"),base,rel,minprice,basevolume,1,base,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits));
else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
STRING_AND_TWO_DOUBLES(InstantDEX,ALToffer,basecoin,minprice,basevolume)
{
int32_t hops = INSTANTDEX_HOPS; cJSON *argjson; char *str; struct instantdex_accept A;
if ( remoteaddr == 0 )
{
if ( iguana_coinfind(basecoin) == 0 )
return(clonestr("{\"error\":\"InstantDEX basecoin is not active, need to addcoin\"}"));
instantdex_acceptset(&A,basecoin,"BTC",INSTANTDEX_OFFERDURATION,0,1,minprice,basevolume,myinfo->myaddr.nxt64bits);
argjson = instantdex_acceptsendjson(&A);
if ( minprice > 0. )
{
if ( (str= InstantDEX_minaccept(IGUANA_CALLARGS,basecoin,"BTC",minprice,basevolume)) != 0 )
free(str);
}
return(instantdex_sendcmd(myinfo,argjson,"ALToffer",myinfo->ipaddr,hops));
} else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
STRING_AND_TWO_DOUBLES(InstantDEX,NXToffer,assetid,minprice,basevolume)
{
int32_t hops = INSTANTDEX_HOPS; cJSON *argjson; char *base,*str; struct instantdex_accept A;
if ( remoteaddr == 0 )
{
if ( assetid == 0 || assetid[0] == 0 || strcmp(assetid,"0") == 0 || strcmp(assetid,"NXT") == 0 || strcmp(assetid,"nxt") == 0 )
base = "NXT";
else if ( is_decimalstr(assetid) <= 0 )
return(clonestr("{\"error\":\"InstantDEX NXToffer illegal assetid\"}"));
else base = assetid;
instantdex_acceptset(&A,base,"BTC",INSTANTDEX_OFFERDURATION,0,1,minprice,basevolume,myinfo->myaddr.nxt64bits);
argjson = instantdex_acceptsendjson(&A);
if ( minprice > 0. )
{
if ( (str= InstantDEX_minaccept(IGUANA_CALLARGS,base,"BTC",minprice,basevolume)) != 0 )
free(str);
}
return(instantdex_sendcmd(myinfo,argjson,"NXToffer",myinfo->ipaddr,hops));
} else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
*/
#include "../includes/iguana_apiundefs.h"

51
iguana/swaps/iguana_BTCswap.c

@ -433,43 +433,49 @@ cJSON *instantdex_newjson(struct supernet_info *myinfo,struct bitcoin_swapinfo *
return(newjson);
}
char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exchange,char *othercoin,double othervolume,double price,int32_t dir) // Bob sending to network (Alice)
char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A) // Bob sending to network (Alice)
{
char *str; struct iguana_info *other; int32_t isbob = 1; struct bitcoin_swapinfo *swap;
struct instantdex_accept checkA,A,*ap = 0; cJSON *newjson; bits256 hash;
if ( othercoin == 0 || (other= iguana_coinfind(othercoin)) == 0 )
struct iguana_info *other; int32_t isbob = 1; struct bitcoin_swapinfo *swap;
cJSON *newjson; bits256 orderhash; struct instantdex_accept *ap = 0;
//orderhash = instantdex_acceptset(&A,othercoin,"BTC",INSTANTDEX_LOCKTIME*2,dir > 0 ? 1 : 0,-dir,price,othervolume,myinfo->myaddr.nxt64bits,nonce);
//A.orderid = orderhash.txid;
if ( strcmp(A->offer.rel,"BTC") != 0 )
{
printf("rel not BTC?!\n");
return(clonestr("{\"error\":\"invalid othercoin\"}"));
hash = instantdex_acceptset(&A,othercoin,"BTC",INSTANTDEX_LOCKTIME*2,dir < 0 ? 1 : 0,-dir,price,othervolume,myinfo->myaddr.nxt64bits);
newjson = cJSON_CreateObject();
if ( instantdex_acceptextract(&checkA,newjson) < 0 )
}
else if ( (other= iguana_coinfind(A->offer.base)) == 0 )
return(clonestr("{\"error\":\"invalid othercoin\"}"));
else if ( A->offer.price64 <= 0 || A->offer.basevolume64 <= 0 )
{
int32_t i;
for (i=0; i<sizeof(A); i++)
printf("%02x ",((uint8_t *)&A)[i]);
printf("instantdex_btcoffer checkA error\n");
printf("illegal price %.8f or volume %.8f\n",dstr(A->offer.price64),dstr(A->offer.basevolume64));
return(clonestr("{\"error\":\"illegal price or volume\"}"));
}
swap = calloc(1,sizeof(struct bitcoin_swapinfo)), swap->isbob = dir > 0, swap->choosei = swap->otherschoosei = -1;
if ( instantdex_pubkeyargs(swap,newjson,777+2,myinfo->persistent_priv,hash,0x02+isbob) != 4 )
isbob = A->offer.myside == 1;
newjson = cJSON_CreateObject();
swap = calloc(1,sizeof(struct bitcoin_swapinfo)), swap->isbob = isbob, swap->choosei = swap->otherschoosei = -1;
vcalc_sha256(0,orderhash.bytes,(uint8_t *)&A->offer,sizeof(A->offer));
if ( instantdex_pubkeyargs(swap,newjson,777+2,myinfo->persistent_priv,orderhash,0x02+isbob) != 777+2 )
{
printf("error from pubkeyargs\n");
return(clonestr("{\"error\":\"highly unlikely run of 02 pubkeys\"}"));
if ( price > SMALLVAL )
}
if ( A->offer.price64 != 0 )
{
if ( dir > 0 && (str= InstantDEX_maxaccept(myinfo,0,newjson,0,othercoin,"BTC",price,othervolume)) != 0 )
free(str);
else if ( dir < 0 && (str= InstantDEX_minaccept(myinfo,0,newjson,0,othercoin,"BTC",price,othervolume)) != 0 )
free(str);
if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,A.orderid,"*","*")) != 0 )
if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,A->orderid,"*","*")) != 0 )
{
swap->state++;
ap->info = swap;
printf(">>>>>>>>>> PENDING ORDER %llu\n",(long long)A.orderid);
printf(">>>>>>>>>> PENDING ORDER %llu\n",(long long)A->orderid);
}
}
if ( ap == 0 )
{
printf("couldnt find accept??\n");
printf("couldnt find accept?? dir.%d orderid.%llu\n",ap->offer.acceptdir,(long long)A->orderid);
free(swap);
return(clonestr("{\"error\":\"couldnt find order just created\"}"));
} else return(instantdex_sendcmd(myinfo,&ap->offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
}
else return(instantdex_sendcmd(myinfo,&ap->offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
}
char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,char *cmdstr,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *serdata,int32_t datalen) // receiving side
@ -541,7 +547,6 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
*ap = *A;
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
retstr = clonestr("{\"result\":\"added new order to orderbook\"}");
//retstr = instantdex_queueaccept(myinfo,exchange,A->offer.base,A->offer.rel,dstr(A->offer.price64),dstr(A->offer.basevolume64),A->offer.acceptdir,A->offer.myside == 0 ? A->offer.base : A->offer.rel,A->offer.expiration,acct777_nxt64bits(traderpub.txid));
}
}
else if ( strcmp(cmdstr,"step1") == 0 && swap->state == 1 ) // either

Loading…
Cancel
Save