Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
dc6c16b1cb
  1. 7
      crypto777/iguana_utils.c
  2. 23
      deprecated/obsolete.h
  3. 75
      iguana/exchanges/bitcoin.c
  4. 2
      iguana/exchanges777.h
  5. 4
      iguana/iguana_instantdex.c
  6. 15
      iguana/iguana_json.c
  7. 376
      iguana/swaps/iguana_BTCswap.c
  8. 2
      includes/iguana_apideclares.h
  9. 4
      includes/iguana_apidefs.h
  10. 1
      includes/iguana_apiundefs.h

7
crypto777/iguana_utils.c

@ -1001,7 +1001,12 @@ void sha256_sha256(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
void rmd160ofsha256(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
{
uint8_t sha256[32];
vcalc_sha256(0,sha256,(void *)msg,len);
if ( is_hexstr((char *)msg,len) > 0 )
{
decode_hex((uint8_t *)hexstr,len/2,(char *)msg);
vcalc_sha256(0,sha256,(void *)hexstr,len/2);
calc_rmd160(hexstr,buf,sha256,sizeof(sha256));
} else vcalc_sha256(0,sha256,(void *)msg,len);
calc_rmd160(hexstr,buf,sha256,sizeof(sha256));
}

23
deprecated/obsolete.h

@ -13384,5 +13384,28 @@ len = 0;
} else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
}
*/
if ( sendprivs != 0 )
{
printf("sendprivs.%d\n",sendprivs);
if ( swap->otherschoosei < 0 )
printf("instantdex_newjson otherschoosei < 0 when sendprivs != 0\n");
else
{
if ( privs == 0 && (privs= calloc(1,sizeof(*swap->privkeys))) == 0 )
printf("instantdex_newjson couldnt allocate hex\n");
else if ( hexstr == 0 && (hexstr= malloc(sizeof(*swap->privkeys) * 2 + 1)) == 0 )
printf("instantdex_newjson couldnt allocate hexstr\n");
else
{
memcpy(privs,swap->privkeys,sizeof(*swap->privkeys));
memset(privs[swap->otherschoosei].bytes,0,sizeof(*privs));
for (i=0; i<sizeof(swap->privkeys)/sizeof(*swap->privkeys); i++)
{
iguana_rwbignum(1,serialized,sizeof(privs[i]),privs[i].bytes);
memcpy(privs[i].bytes,serialized,sizeof(privs[i]));
}
}
}
}
#endif

75
iguana/exchanges/bitcoin.c

@ -990,9 +990,13 @@ bits256 iguana_parsetxobj(struct iguana_info *coin,int32_t *txstartp,uint8_t *se
int32_t i,numvins,numvouts,len = 0; cJSON *array=0; bits256 txid; char vpnstr[64];
memset(msg,0,sizeof(*msg));
vpnstr[0] = 0;
msg->version = juint(txobj,"version");
if ( (msg->version= juint(txobj,"version")) == 0 )
msg->version = 1;
if ( coin->chain->hastimestamp != 0 )
msg->timestamp = juint(txobj,"timestamp");
{
if ( (msg->timestamp= juint(txobj,"timestamp")) == 0 )
msg->timestamp = (uint32_t)time(NULL);
}
if ( (array= jarray(&numvins,txobj,"vin")) != 0 )
{
msg->tx_in = numvins;
@ -1617,3 +1621,70 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs bitcoin_funcs = EXCHANGE_FUNCS(bitcoin,EXCHANGE_NAME);
#include "exchange_undefs.h"
#include "../../includes/iguana_apidefs.h"
#include "../../includes/iguana_apideclares.h"
char *_setVsigner(struct iguana_info *coin,struct vin_info *V,int32_t ind,char *pubstr,char *wifstr)
{
uint8_t addrtype;
decode_hex(V->signers[ind].pubkey,(int32_t)strlen(pubstr)/2,pubstr);
btc_wif2priv(&addrtype,V->signers[ind].privkey.bytes,wifstr);
if ( addrtype != coin->chain->pubtype )
return(clonestr("{\"error\":\"invalid wifA\"}"));
else return(0);
}
int32_t bitcoin_txaddspend(struct iguana_info *coin,cJSON *txobj,char *destaddress,double destamount)
{
uint8_t outputscript[128],addrtype,rmd160[20]; int32_t scriptlen;
if ( bitcoin_validaddress(coin,destaddress) == 0 && destamount > 0. )
{
bitcoin_addr2rmd160(&addrtype,rmd160,destaddress);
scriptlen = bitcoin_standardspend(outputscript,0,rmd160);
bitcoin_addoutput(coin,txobj,outputscript,scriptlen,destamount * SATOSHIDEN);
return(0);
} else return(-1);
}
P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC)
{
struct vin_info V; uint8_t p2sh_rmd160[20],serialized[2096];
char msigaddr[64],*retstr; cJSON *retjson,*txobj; struct iguana_info *active;
bits256 signedtxid; char *signedtx; int scriptlens[1];
struct iguana_msgtx msgtx;
if ( (active= iguana_coinfind(activecoin)) == 0 )
return(clonestr("{\"error\":\"activecoin isnt active\"}"));
if ( M > N || N > 3 )
return(clonestr("{\"error\":\"illegal M or N\"}"));
memset(&V,0,sizeof(V));
txobj = bitcoin_createtx(active,0);
if ( destaddress[0] != 0 && destamount > 0. )
bitcoin_txaddspend(active,txobj,destaddress,destamount);
if ( destaddress2[0] != 0 && destamount2 > 0. )
bitcoin_txaddspend(active,txobj,destaddress2,destamount2);
bitcoin_addinput(active,txobj,vintxid,vinvout,0xffffffff);
if ( pubA[0] != 0 && (retstr= _setVsigner(active,&V,0,pubA,wifA)) != 0 )
return(retstr);
if ( N >= 2 && pubB[0] != 0 && (retstr= _setVsigner(active,&V,1,pubB,wifC)) != 0 )
return(retstr);
if ( N == 3 && pubC[0] != 0 && (retstr= _setVsigner(active,&V,2,pubC,wifC)) != 0 )
return(retstr);
V.M = M, V.N = N, V.type = IGUANA_SCRIPT_P2SH;
V.p2shlen = bitcoin_MofNspendscript(p2sh_rmd160,V.p2shscript,0,&V);
bitcoin_address(msigaddr,active->chain->p2shtype,V.p2shscript,V.p2shlen);
scriptlens[0] = 0;
retjson = cJSON_CreateObject();
if ( bitcoin_verifyvins(active,&signedtxid,&signedtx,scriptlens,&msgtx,serialized,sizeof(serialized),&V,0) == 0 )
{
jaddstr(retjson,"result","msigtx");
if ( signedtx != 0 )
jaddstr(retjson,"signedtx",signedtx), free(signedtx);
jaddbits256(retjson,"txid",signedtxid);
} else jaddstr(retjson,"error","couldnt sign tx");
jaddstr(retjson,"msigaddr",msigaddr);
return(jprint(retjson,1));
}
#include "../../includes/iguana_apiundefs.h"

2
iguana/exchanges777.h

@ -94,7 +94,7 @@ struct instantdex_offer { char base[24],rel[24]; uint64_t price64,basevolume64,o
struct instantdex_accept
{
struct queueitem DL; void *info;
uint64_t pendingvolume64,orderid,matchid; uint32_t dead;
uint64_t pendingvolume64,orderid,matchid; uint32_t dead; int32_t didstate;
struct instantdex_offer offer;
};

4
iguana/iguana_instantdex.c

@ -149,7 +149,7 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o
nxt64bits = acct777_nxt64bits(myinfo->myaddr.persistent);
reqstr = jprint(argjson,0);
slen = (int32_t)(strlen(reqstr) + 1);
datalen = (int32_t)sizeof(*msg) + slen + extralen + olen;
datalen = (int32_t)slen + extralen + olen;
msg = calloc(1,datalen);
for (i=0; i<sizeof(msg->cmd); i++)
if ( (msg->cmd[i]= cmdstr[i]) == 0 )
@ -586,7 +586,7 @@ char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char
{
orderhash = instantdex_rwoffer(0,&olen,serdata,&rawoffer);
newlen -= olen;
newlen -= ((long)msg->serialized - (long)msg);
//newlen -= ((long)msg->serialized - (long)msg);
serdata = &serdata[olen];
//printf("received orderhash.%llu olen.%d slen.%d newlen.%d\n",(long long)orderhash.txid,olen,slen,newlen);
} else olen = 0;

15
iguana/iguana_json.c

@ -71,6 +71,15 @@ cJSON *helparray3(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2) { jaddi(arra
cJSON *helparray4(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3) { jaddi(array,obj0); return(helparray3(array,obj1,obj2,obj3)); }
cJSON *helparray5(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4) { jaddi(array,obj0); return(helparray4(array,obj1,obj2,obj3,obj4)); }
cJSON *helparray6(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5) { jaddi(array,obj0); return(helparray5(array,obj1,obj2,obj3,obj4,obj5)); }
cJSON *helparray7(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6) { jaddi(array,obj0); return(helparray6(array,obj1,obj2,obj3,obj4,obj5,obj6)); }
cJSON *helparray8(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7) { jaddi(array,obj0); return(helparray7(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7)); }
cJSON *helparray9(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7,cJSON *obj9) { jaddi(array,obj0); return(helparray8(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj9)); }
cJSON *helparray10(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7,cJSON *obj9,cJSON *obj10) { jaddi(array,obj0); return(helparray9(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj9,obj10)); }
cJSON *helparray11(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7,cJSON *obj9,cJSON *obj10,cJSON *obj11) { jaddi(array,obj0); return(helparray10(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj9,obj10,obj11)); }
cJSON *helparray12(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7,cJSON *obj9,cJSON *obj10,cJSON *obj11,cJSON *obj12) { jaddi(array,obj0); return(helparray11(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj9,obj10,obj11,obj12)); }
cJSON *helparray13(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7,cJSON *obj9,cJSON *obj10,cJSON *obj11,cJSON *obj12,cJSON *obj13) { jaddi(array,obj0); return(helparray12(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj9,obj10,obj11,obj12,obj13)); }
cJSON *helparray14(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7,cJSON *obj9,cJSON *obj10,cJSON *obj11,cJSON *obj12,cJSON *obj13,cJSON *obj14) { jaddi(array,obj0); return(helparray13(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj9,obj10,obj11,obj12,obj13,obj14)); }
cJSON *helparray15(cJSON *array,cJSON *obj0,cJSON *obj1,cJSON *obj2,cJSON *obj3,cJSON *obj4,cJSON *obj5,cJSON *obj6,cJSON *obj7,cJSON *obj9,cJSON *obj10,cJSON *obj11,cJSON *obj12,cJSON *obj13,cJSON *obj14,cJSON *obj15) { jaddi(array,obj0); return(helparray14(array,obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj9,obj10,obj11,obj12,obj13,obj14,obj15)); }
cJSON *SuperNET_helpjson()
{
@ -126,6 +135,8 @@ cJSON *SuperNET_helpjson()
#define IGUANA_HELP_SAIS(agent,name,str,obj,val,str2) array = helpjson(IGUANA_ARGS,#agent,#name,helparray4(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#obj,"array"),helpitem(#val,"int"),helpitem(#str2,"string")))
#define IGUANA_HELP_SDSS(agent,name,str,amount,str2,str3) array = helpjson(IGUANA_ARGS,#agent,#name,helparray4(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#amount,"float"),helpitem(#str2,"string"),helpitem(#str3,"string")))
#define IGUANA_HELP_SHI_SDSD_II_SSSSSS(agent,name,str,hash,val,str2,amount,str3,amount2,val2,val3,str4,str5,str6,str7,str8,str9) array = helpjson(IGUANA_ARGS,#agent,#name,helparray15(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#hash,"hash"),helpitem(#val,"int"),helpitem(#str2,"string"),helpitem(#amount,"float"),helpitem(#str3,"string"),helpitem(#amount2,"float"),helpitem(#val2,"int"),helpitem(#val3,"int"),helpitem(#str4,"string"),helpitem(#str5,"string"),helpitem(#str6,"string"),helpitem(#str7,"string"),helpitem(#str8,"string"),helpitem(#str9,"string")))
// API functions
#define ZERO_ARGS IGUANA_HELP0
#define INT_ARG IGUANA_HELP_I
@ -168,6 +179,7 @@ cJSON *SuperNET_helpjson()
#define STRING_AND_DOUBLE IGUANA_HELP_SD
#define TWO_STRINGS_AND_TWO_DOUBLES IGUANA_HELP_SSDD
#define STRING_AND_TWO_DOUBLES IGUANA_HELP_SDD
#define P2SH_SPENDAPI IGUANA_HELP_SHI_SDSD_II_SSSSSS
#include "../includes/iguana_apideclares.h"
@ -901,6 +913,8 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define IGUANA_DISPATCH_SAIS(agent,name,str,array,val,str2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array),juint(json,#val),jstr(json,#str2)))
#define IGUANA_DISPATCH_SDSS(agent,name,str,amount,str2,str3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jdouble(json,#amount),jstr(json,#str2),jstr(json,#str3)))
#define IGUANA_DISPATCH_SHI_SDSD_II_SSSSSS(agent,name,str,hash,val,str2,amount,str3,amount2,val2,val3,str4,str5,str6,str7,str8,str9) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jbits256(json,#hash),jint(json,#val),jstr(json,#str2),jdouble(json,#amount),jstr(json,#str3),jdouble(json,#amount2),juint(json,#val2),juint(json,#val3),jstr(json,#str4),jstr(json,#str5),jstr(json,#str6),jstr(json,#str7),jstr(json,#str8),jstr(json,#str9)))
// API functions
#define ZERO_ARGS IGUANA_DISPATCH0
#define INT_ARG IGUANA_DISPATCH_I
@ -943,6 +957,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define STRING_AND_DOUBLE IGUANA_DISPATCH_SD
#define TWO_STRINGS_AND_TWO_DOUBLES IGUANA_DISPATCH_SSDD
#define STRING_AND_TWO_DOUBLES IGUANA_DISPATCH_SDD
#define P2SH_SPENDAPI IGUANA_DISPATCH_SHI_SDSD_II_SSSSSS
#include "../includes/iguana_apideclares.h"
//#undef IGUANA_ARGS

376
iguana/swaps/iguana_BTCswap.c

@ -33,9 +33,11 @@ Tier Nolan's approach is followed with the following changes:
struct bitcoin_swapinfo
{
bits256 privkeys[777],mypubs[2],otherpubs[2],pubBn,pubAm,dtxid,ptxid,aptxid,astxid,stxid,ftxid,othertrader;
uint64_t otherscut[777][2],deck[777][2];
bits256 privkeys[777],mypubs[2],otherpubs[2];
bits256 orderhash,privAm,pubAm,privBn,pubBn,dtxid,ptxid,aptxid,astxid,stxid,ftxid,othertrader;
uint64_t otherscut[777][2],deck[777][2],satoshis[2],insurance;
int32_t isbob,choosei,otherschoosei,state,cutverified,otherverifiedcut;
double minperc;
char altmsigaddr[64],*deposit,*payment,*altpayment,*altspend,*spendtx,*feetx;
};
@ -340,35 +342,15 @@ void instantdex_getpubs(struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newj
}
}
cJSON *instantdex_newjson(struct supernet_info *myinfo,struct bitcoin_swapinfo *swap,cJSON *argjson,bits256 hash,struct instantdex_accept *A,int32_t flag777,int32_t sendprivs)
void instantdex_privkeysextract(struct supernet_info *myinfo,struct bitcoin_swapinfo *swap,uint8_t *serdata,int32_t serdatalen)
{
cJSON *newjson; char serstr[sizeof(bits256)*2+1],*hexstr=0; int32_t i,wrongfirstbyte,errs;
bits256 hashpriv,pubi,otherpriv,*privs=0; uint8_t serialized[sizeof(bits256)],otherpubkey[33];
newjson = cJSON_CreateObject();//instantdex_acceptsendjson(A);
//printf("acceptsend.(%s)\n",jprint(newjson,0));
if ( swap->otherschoosei < 0 && jobj(argjson,"mychoosei") != 0 )
{
printf("otherschoosei.%d\n",swap->otherschoosei);
if ( (swap->otherschoosei= juint(argjson,"mychoosei")) >= sizeof(swap->otherscut)/sizeof(*swap->otherscut) )
swap->otherschoosei = -1;
}
if ( juint(argjson,"verified") != 0 )
swap->otherverifiedcut = 1;
//printf("otherverified.%d\n",swap->otherverifiedcut);
if ( jobj(argjson,"myprivs") != 0 && swap->cutverified == 0 )
{
printf("got privs\n");
if ( (privs= calloc(1,sizeof(*swap->privkeys))) == 0 )
printf("instantdex_newjson couldnt allocate hex\n");
else if ( (hexstr= jstr(argjson,"myprivs")) == 0 || strlen(hexstr) != sizeof(swap->privkeys)*2 )
printf("instantdex_newjson other's privkeys wrong size\n");
else
int32_t i,wrongfirstbyte,errs,len = 0; bits256 hashpriv,otherpriv,pubi; uint8_t otherpubkey[33];
printf("got instantdex_privkeysextract serdatalen.%d choosei.%d cutverified.%d\n",serdatalen,swap->choosei,swap->cutverified);
if ( swap->cutverified == 0 && swap->choosei >= 0 && serdatalen == sizeof(swap->privkeys) )
{
for (i=wrongfirstbyte=errs=0; i<sizeof(swap->privkeys)/sizeof(*swap->privkeys); i++)
{
memcpy(serstr,&hexstr[i * sizeof(bits256)],sizeof(bits256));
decode_hex(serialized,sizeof(bits256),serstr);
iguana_rwbignum(0,serialized,sizeof(otherpriv),otherpriv.bytes);
len += iguana_rwbignum(0,&serdata[len],sizeof(bits256),otherpriv.bytes);
if ( i == swap->choosei )
{
if ( bits256_nonz(otherpriv) != 0 )
@ -400,53 +382,176 @@ cJSON *instantdex_newjson(struct supernet_info *myinfo,struct bitcoin_swapinfo *
swap->cutverified = 1;
else printf("failed verification: wrong firstbyte.%d errs.%d\n",wrongfirstbyte,errs);
}
}
cJSON *instantdex_newjson(struct supernet_info *myinfo,struct bitcoin_swapinfo *swap,cJSON *argjson,bits256 hash,struct instantdex_accept *A,int32_t flag777)
{
cJSON *newjson;
newjson = cJSON_CreateObject();
//printf("acceptsend.(%s)\n",jprint(newjson,0));
if ( swap->otherschoosei < 0 && jobj(argjson,"mychoosei") != 0 )
{
printf("otherschoosei.%d\n",swap->otherschoosei);
if ( (swap->otherschoosei= juint(argjson,"mychoosei")) >= sizeof(swap->otherscut)/sizeof(*swap->otherscut) )
swap->otherschoosei = -1;
}
if ( juint(argjson,"verified") != 0 )
swap->otherverifiedcut = 1;
jaddnum(newjson,"verified",swap->otherverifiedcut);
//printf("otherverified.%d\n",swap->otherverifiedcut);
if ( instantdex_pubkeyargs(swap,newjson,2+flag777*777,myinfo->persistent_priv,hash,0x02 + swap->isbob) != 2+flag777*777 )
{
printf("error generating pubkeyargs\n");
return(0);
}
instantdex_getpubs(swap,argjson,newjson);
if ( sendprivs != 0 )
return(newjson);
}
char *instantdex_statemachine(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,char *cmdstr,struct bitcoin_swapinfo *swap,cJSON *argjson,uint8_t *serdata,int32_t serdatalen,struct iguana_info *altcoin,struct iguana_info *coinbtc)
{
uint32_t reftime; cJSON *newjson; char *retstr = 0;
reftime = (uint32_t)(A->offer.expiration - INSTANTDEX_LOCKTIME*2);
if ( strcmp(cmdstr,"step1") == 0 && swap->state == 1 ) // either
{
printf("sendprivs.%d\n",sendprivs);
if ( swap->otherschoosei < 0 )
printf("instantdex_newjson otherschoosei < 0 when sendprivs != 0\n");
printf("got step1, should have other's choosei\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,swap->orderhash,A,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step1 null newjson\"}"));
else if ( swap->otherschoosei < 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step1, no didnt choosei\"}"));
else
{
if ( privs == 0 && (privs= calloc(1,sizeof(*swap->privkeys))) == 0 )
printf("instantdex_newjson couldnt allocate hex\n");
else if ( hexstr == 0 && (hexstr= malloc(sizeof(*swap->privkeys) * 2 + 1)) == 0 )
printf("instantdex_newjson couldnt allocate hexstr\n");
if ( swap->isbob == 0 )
swap->privAm = swap->privkeys[swap->otherschoosei];
else swap->privBn = swap->privkeys[swap->otherschoosei];
memset(&swap->privkeys[swap->otherschoosei],0,sizeof(swap->privkeys[swap->otherschoosei]));
swap->state++;
if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 )
return(retstr);
if ( swap->isbob == 0 )
{
if ( (swap->feetx= instantdex_bobtx(myinfo,coinbtc,&swap->ftxid,swap->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->otherschoosei],reftime,swap->insurance,1)) != 0 )
{
jaddstr(newjson,"feetx",swap->feetx);
jaddbits256(newjson,"ftxid",swap->ftxid);
// broadcast to network
}
}
return(instantdex_sendcmd(myinfo,&A->offer,newjson,swap->isbob != 0 ? "BTCstep1" : "BTCstep2",swap->othertrader,INSTANTDEX_HOPS,swap->privkeys,sizeof(swap->privkeys)));
}
}
else if ( strcmp(cmdstr,"step2") == 0 && swap->isbob != 0 && swap->state == 2 ) // Bob
{
printf("got step2, should have other's privkeys\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,swap->orderhash,A,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step2 null newjson\"}"));
else
{
instantdex_privkeysextract(myinfo,swap,serdata,serdatalen);
if ( swap->cutverified == 0 || swap->otherverifiedcut == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step2, both sides didnt validate\"}"));
else
{
memcpy(privs,swap->privkeys,sizeof(*swap->privkeys));
memset(privs[swap->otherschoosei].bytes,0,sizeof(*privs));
for (i=0; i<sizeof(swap->privkeys)/sizeof(*swap->privkeys); i++)
swap->state++;
if ( (swap->deposit= instantdex_bobtx(myinfo,coinbtc,&swap->dtxid,swap->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->otherschoosei],reftime,swap->satoshis[swap->isbob],1)) != 0 )
{
iguana_rwbignum(1,serialized,sizeof(privs[i]),privs[i].bytes);
memcpy(privs[i].bytes,serialized,sizeof(privs[i]));
jaddstr(newjson,"deposit",swap->deposit);
jaddbits256(newjson,"dtxid",swap->dtxid);
//jaddbits256(newjson,"pubBn",bitcoin_pubkey33(pubkey,swap->pubBn));
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep3",swap->othertrader,INSTANTDEX_HOPS,0,0));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step2, cant create deposit\"}"));
}
init_hexbytes_noT(hexstr,privs[0].bytes,sizeof(swap->privkeys));
jaddstr(newjson,"myprivs",hexstr);
} //else return(clonestr("{\"error\":\"instantdex_BTCswap step2 invalid fee\"}"));
}
else if ( strcmp(cmdstr,"step3") == 0 && swap->isbob == 0 && swap->state == 2 ) // Alice
{
printf("Alice got step3 should have Bob's choosei\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,swap->orderhash,A,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3 null newjson\"}"));
else
{
instantdex_privkeysextract(myinfo,swap,serdata,serdatalen);
if ( swap->cutverified == 0 || swap->otherverifiedcut == 0 || bits256_nonz(swap->pubBn) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step3, both sides didnt validate\"}"));
else if ( instantdex_paymentverify(myinfo,coinbtc,swap,A,argjson,1) == 0 )
{
swap->state++;
//swap->pubAm = bitcoin_pubkey33(pubkey,swap->privkeys[swap->otherschoosei]);
if ( (swap->altpayment= instantdex_alicetx(myinfo,altcoin,swap->altmsigaddr,&swap->aptxid,swap->pubAm,swap->pubBn,swap->satoshis[swap->isbob])) != 0 )
{
jaddstr(newjson,"altpayment",swap->altpayment);
jaddstr(newjson,"altmsigaddr",swap->altmsigaddr);
jaddbits256(newjson,"aptxid",swap->aptxid);
jaddbits256(newjson,"pubAm",swap->pubAm);
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep4",swap->othertrader,INSTANTDEX_HOPS,0,0));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, error making altpay\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}"));
}
}
if ( privs != 0 )
free(privs);
if ( hexstr != 0 )
free(hexstr);
return(newjson);
else if ( strcmp(cmdstr,"step4") == 0 && swap->isbob != 0 && swap->state == 3 ) // Bob
{
printf("Bob got step4 should have Alice's altpayment\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,swap->orderhash,A,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Bob step4 null newjson\"}"));
else if ( bits256_nonz(swap->pubAm) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step4, no pubAm\"}"));
else if ( instantdex_altpaymentverify(myinfo,altcoin,swap,A,argjson) == 0 )
{
swap->state++;
if ( (swap->deposit= instantdex_bobtx(myinfo,coinbtc,&swap->ptxid,swap->mypubs[1],swap->otherpubs[0],swap->privkeys[swap->otherschoosei],reftime,swap->satoshis[swap->isbob],0)) != 0 )
{
jaddstr(newjson,"payment",swap->payment);
jaddbits256(newjson,"ptxid",swap->ptxid);
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep5",swap->othertrader,INSTANTDEX_HOPS,0,0));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step4, cant create payment\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}"));
}
else if ( strcmp(cmdstr,"step5") == 0 && swap->isbob == 0 && swap->state == 4 ) // Alice
{
printf("Alice got step5 should have Bob's payment\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,swap->orderhash,A,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Alice step5 null newjson\"}"));
else if ( instantdex_paymentverify(myinfo,coinbtc,swap,A,argjson,0) == 0 )
{
swap->state++;
/*if ( (swap->spendtx= instantdex_spendpayment(myinfo,coinbtc,&swap->stxid,swap,argjson,newjson)) != 0 )
{
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->A,newjson,"BTCstep6",swap->othertrader,INSTANTDEX_HOPS));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step5, cant spend payment\"}"));*/
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, invalid payment\"}"));
}
else if ( strcmp(cmdstr,"step6") == 0 ) // Bob
{
printf("Bob got step6 should have Alice's privkey\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,swap->orderhash,A,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6 null newjson\"}"));
/*else if ( instantdex_spendverify(myinfo,coinbtc,swap,A,argjson,0) == 0 )
{
if ( (swap->altspend= instantdex_spendaltpayment(myinfo,altcoin,&swap->astxid,swap,argjson,newjson)) != 0 )
{
jaddstr(newjson,"altspend",swap->altspend);
jaddbits256(newjson,"astxid",swap->astxid);
// broadcast to network
return(clonestr("{\"result\":\"Bob finished atomic swap\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, cant spend altpayment\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, invalid spend\"}"));*/
}
else retstr = clonestr("{\"error\":\"BTC swap got unrecognized command\"}");
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"BTC swap null retstr\"}");
if ( swap != 0 )
printf("BTCSWAP.(%s) (%s) isbob.%d state.%d verified.(%d %d)\n",retstr,cmdstr,swap->isbob,swap->state,swap->cutverified,swap->otherverifiedcut);
else printf("BTCSWAP.(%s)\n",retstr);
return(retstr);
}
char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A) // Bob sending to network (Alice)
{
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");
@ -486,11 +591,11 @@ char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exc
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
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 serdatalen) // receiving side
{
char *retstr=0; uint64_t satoshis[2]; int32_t reftime,offerdir = 0; double minperc;
uint64_t satoshis[2]; int32_t offerdir = 0; double minperc; uint64_t insurance,relsatoshis;
struct instantdex_accept *ap; struct bitcoin_swapinfo *swap = 0; bits256 orderhash,traderpub;
struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; uint8_t pubkey[33];
struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; char *retstr=0;
if ( exchange == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap null exchange ptr\"}"));
offerdir = instantdex_bidaskdir(A);
@ -500,20 +605,18 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
printf("other.%p coinbtc.%p (%s/%s)\n",altcoin,coinbtc,A->offer.base,A->offer.rel);
return(clonestr("{\"error\":\"instantdex_BTCswap cant find btc or other coin info\"}"));
}
reftime = (uint32_t)(A->offer.expiration - INSTANTDEX_LOCKTIME*2);
if ( strcmp(A->offer.rel,"BTC") != 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap offer non BTC rel\"}"));
vcalc_sha256(0,orderhash.bytes,(void *)&A->offer,sizeof(ap->offer));
if ( orderhash.txid != A->orderid )
return(clonestr("{\"error\":\"txid mismatches orderid\"}"));
satoshis[0] = A->offer.basevolume64;
satoshis[1] = instantdex_relsatoshis(A->offer.price64,A->offer.basevolume64);
swap = A->info;
if ( (swap= A->info) == 0 && strcmp(cmdstr,"offer") != 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap no swap info after offer\"}"));
relsatoshis = instantdex_relsatoshis(A->offer.price64,A->offer.basevolume64);
traderpub = jbits256(argjson,"traderpub");
if ( (minperc= jdouble(argjson,"p")) < INSTANTDEX_MINPERC )
minperc = INSTANTDEX_MINPERC;
if ( swap == 0 && strcmp(cmdstr,"offer") != 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap no swap info after offer\"}"));
insurance = (satoshis[1] * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee prevents papercut attack
printf("T.%d [%d] got offer.(%s/%s) %.8f vol %.8f %llu offerside.%d offerdir.%d swap.%p decksize.%ld %s\n",bits256_cmp(traderpub,myinfo->myaddr.persistent),swap!=0?swap->state:-1,A->offer.base,A->offer.rel,dstr(A->offer.price64),dstr(A->offer.basevolume64),(long long)A->orderid,A->offer.myside,A->offer.acceptdir,A->info,sizeof(swap->deck),jprint(argjson,0));
if ( strcmp(cmdstr,"offer") == 0 && A->info == 0 ) // sender is Bob, receiver is network (Alice)
{
@ -531,161 +634,46 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
}
if ( (A->info= swap) != 0 )
{
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,1,0)) == 0 )
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,1)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}"));
else
{
// verify feetx
instantdex_pendingnotice(myinfo,exchange,ap,A);
if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,datalen)) != 0 )
if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 )
{
return(retstr);
}
else
{
// generate feetx to send
printf(">>>> step1.(%s)\n",jprint(newjson,0));
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep1",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
}
}
}
} else return(clonestr("{\"error\":\"couldnt allocate swap info\"}"));
}
else
{
printf("no matching trade for %llu -> InstantDEX_minaccept\n",(long long)A->orderid);
if ( instantdex_offerfind(myinfo,exchange,0,0,A->orderid,"*","*") == 0 )
{
ap = calloc(1,sizeof(*ap));
*ap = *A;
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
retstr = clonestr("{\"result\":\"added new order to orderbook\"}");
}
}
else
{
if ( strcmp(cmdstr,"step1") == 0 && swap->state == 1 ) // either
{
printf("got step1, should have other's choosei\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,0,1)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step1 null newjson\"}"));
else if ( swap->otherschoosei < 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step1, no didnt choosei\"}"));
else
{
swap->state++;
if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,datalen)) != 0 )
return(retstr);
if ( swap->isbob == 0 )
{
int64_t insurance = (satoshis[1] * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee prevents dust attack
if ( (swap->feetx= instantdex_bobtx(myinfo,coinbtc,&swap->ftxid,swap->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->otherschoosei],reftime,insurance,1)) != 0 )
{
jaddstr(newjson,"feetx",swap->feetx);
jaddbits256(newjson,"ftxid",swap->ftxid);
// broadcast to network
}
}
return(instantdex_sendcmd(myinfo,&A->offer,newjson,swap->isbob != 0 ? "BTCstep1" : "BTCstep2",swap->othertrader,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
}
}
else if ( strcmp(cmdstr,"step2") == 0 && swap->isbob != 0 && swap->state == 2 ) // Bob
{
printf("got step2, should have other's privkeys\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,0,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step2 null newjson\"}"));
else if ( swap->cutverified == 0 || swap->otherverifiedcut == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step2, both sides didnt validate\"}"));
else //if ( instantdex_feeverify() == 0 )
{
swap->state++;
//char *instantdex_bobtx(myinfo,coin,&paytxid,pubA0,pubB0,privAm,reftime,relsatoshis,0);
if ( (swap->deposit= instantdex_bobtx(myinfo,coinbtc,&swap->dtxid,swap->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->otherschoosei],reftime,satoshis[swap->isbob],1)) != 0 )
{
jaddstr(newjson,"deposit",swap->deposit);
jaddbits256(newjson,"dtxid",swap->dtxid);
jaddbits256(newjson,"pubBn",bitcoin_pubkey33(pubkey,swap->privkeys[swap->otherschoosei]));
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep3",swap->othertrader,INSTANTDEX_HOPS,0,0));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step2, cant create deposit\"}"));
} //else return(clonestr("{\"error\":\"instantdex_BTCswap step2 invalid fee\"}"));
}
else if ( strcmp(cmdstr,"step3") == 0 && swap->isbob == 0 && swap->state == 2 ) // Alice
{
printf("Alice got step3 should have Bob's choosei\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,0,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3 null newjson\"}"));
else if ( swap->cutverified == 0 || swap->otherverifiedcut == 0 || bits256_nonz(swap->pubBn) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step3, both sides didnt validate\"}"));
else if ( instantdex_paymentverify(myinfo,coinbtc,swap,A,argjson,1) == 0 )
{
swap->state++;
//char *instantdex_alicetx(myinfo,altcoin,&alicetxid,pubAm,pubBn,satoshis);
swap->pubAm = bitcoin_pubkey33(pubkey,swap->privkeys[swap->otherschoosei]);
if ( (swap->altpayment= instantdex_alicetx(myinfo,altcoin,swap->altmsigaddr,&swap->aptxid,swap->pubAm,swap->pubBn,satoshis[swap->isbob])) != 0 )
{
jaddstr(newjson,"altpayment",swap->altpayment);
jaddstr(newjson,"altmsigaddr",swap->altmsigaddr);
jaddbits256(newjson,"aptxid",swap->aptxid);
jaddbits256(newjson,"pubAm",swap->pubAm);
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep4",swap->othertrader,INSTANTDEX_HOPS,0,0));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, error making altpay\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}"));
}
else if ( strcmp(cmdstr,"step4") == 0 && swap->isbob != 0 && swap->state == 3 ) // Bob
{
printf("Bob got step4 should have Alice's altpayment\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,0,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Bob step4 null newjson\"}"));
else if ( bits256_nonz(swap->pubAm) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap step4, no pubAm\"}"));
else if ( instantdex_altpaymentverify(myinfo,altcoin,swap,A,argjson) == 0 )
{
swap->state++;
if ( (swap->deposit= instantdex_bobtx(myinfo,coinbtc,&swap->ptxid,swap->mypubs[1],swap->otherpubs[0],swap->privkeys[swap->otherschoosei],reftime,satoshis[swap->isbob],0)) != 0 )
{
jaddstr(newjson,"payment",swap->payment);
jaddbits256(newjson,"ptxid",swap->ptxid);
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep5",swap->othertrader,INSTANTDEX_HOPS,0,0));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step4, cant create payment\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}"));
}
else if ( strcmp(cmdstr,"step5") == 0 && swap->isbob == 0 && swap->state == 4 ) // Alice
{
printf("Alice got step5 should have Bob's payment\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,0,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Alice step5 null newjson\"}"));
else if ( instantdex_paymentverify(myinfo,coinbtc,swap,A,argjson,0) == 0 )
{
swap->state++;
/*if ( (swap->spendtx= instantdex_spendpayment(myinfo,coinbtc,&swap->stxid,swap,argjson,newjson)) != 0 )
{
// broadcast to network
return(instantdex_sendcmd(myinfo,&A->A,newjson,"BTCstep6",swap->othertrader,INSTANTDEX_HOPS));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step5, cant spend payment\"}"));*/
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, invalid payment\"}"));
}
else if ( strcmp(cmdstr,"step6") == 0 ) // Bob
{
printf("Bob got step6 should have Alice's privkey\n");
if ( (newjson= instantdex_newjson(myinfo,swap,argjson,orderhash,A,0,0)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6 null newjson\"}"));
/*else if ( instantdex_spendverify(myinfo,coinbtc,swap,A,argjson,0) == 0 )
{
if ( (swap->altspend= instantdex_spendaltpayment(myinfo,altcoin,&swap->astxid,swap,argjson,newjson)) != 0 )
{
jaddstr(newjson,"altspend",swap->altspend);
jaddbits256(newjson,"astxid",swap->astxid);
// broadcast to network
return(clonestr("{\"result\":\"Bob finished atomic swap\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, cant spend altpayment\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, invalid spend\"}"));*/
}
else retstr = clonestr("{\"error\":\"BTC swap got unrecognized command\"}");
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"BTC swap null retstr\"}");
if ( swap != 0 )
printf("BTCSWAP.(%s) isbob.%d state.%d verified.(%d %d)\n",retstr,swap->isbob,swap->state,swap->cutverified,swap->otherverifiedcut);
else printf("BTCSWAP.(%s)\n",retstr);
return(retstr);
return(clonestr("{\"result\":\"added new order to orderbook\"}"));
} else return(clonestr("{\"result\":\"order was already in orderbook\"}"));
}
}
else if ( swap == 0 )
return(clonestr("{\"error\":\"no swap info\"}"));
swap->satoshis[0] = A->offer.basevolume64;
swap->satoshis[1] = relsatoshis;
swap->insurance = (relsatoshis * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee
swap->orderhash = orderhash;
if ( swap->minperc < minperc )
swap->minperc = minperc;
return(instantdex_statemachine(myinfo,exchange,A,cmdstr,swap,argjson,serdata,serdatalen,altcoin,coinbtc));
}
#ifdef oldway

2
includes/iguana_apideclares.h

@ -16,9 +16,9 @@
STRING_ARG(SuperNET,bitcoinrpc,setcoin);
ZERO_ARGS(SuperNET,myipaddr);
STRING_ARG(SuperNET,setmyipaddr,ipaddr);
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,minaccept,base,rel,minprice,basevolume);
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,maxaccept,base,rel,maxprice,basevolume);
P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC);
/*TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,BTCoffer,othercoin,otherassetid,maxprice,othervolume);
STRING_AND_TWO_DOUBLES(InstantDEX,ALToffer,basecoin,minprice,basevolume);

4
includes/iguana_apidefs.h

@ -10,7 +10,7 @@
#define IGUANA_CFUNC_SAA(agent,name,str,array,array2) char *agent ## _ ## name(IGUANA_ARGS,char *str,cJSON *array,cJSON *array2)
#define IGUANA_CFUNC_64A(agent,name,j64,array) char *agent ## _ ## name(IGUANA_ARGS,uint64_t j64,cJSON *array)
#define IGUANA_CFUNC_SHI_SDSD_II_SSSSSS(agent,name,str,hash,val,str2,amount,str3,amount2,val2,val3,str4,str5,str6,str7,str8,str9) char *agent ## _ ## name(IGUANA_ARGS,char *str,bits256 hash,int32_t val,char *str2,double amount,char *str3,double amount2,int32_t val2,int32_t val3,char *str4,char *str5,char *str6,char *str7,char *str8,char *str9)
#define IGUANA_CFUNC_IA(agent,name,val,array) char *agent ## _ ## name(IGUANA_ARGS,int32_t val,cJSON *array)
#define IGUANA_CFUNC_IAS(agent,name,val,array,str) char *agent ## _ ## name(IGUANA_ARGS,int32_t val,cJSON *array,char *str)
@ -90,3 +90,5 @@
#define THREE_STRINGS_AND_DOUBLE IGUANA_CFUNC_SSSD
#define TWO_STRINGS_AND_TWO_DOUBLES IGUANA_CFUNC_SSDD
#define STRING_AND_TWO_DOUBLES IGUANA_CFUNC_SDD
#define P2SH_SPENDAPI IGUANA_CFUNC_SHI_SDSD_II_SSSSSS

1
includes/iguana_apiundefs.h

@ -40,6 +40,7 @@
#undef FOUR_STRINGS
#undef TWO_STRINGS_AND_TWO_DOUBLES
#undef STRING_AND_TWO_DOUBLES
#undef P2SH_SPENDAPI
#undef IGUANA_ARGS
#undef IGUANA_CALLARGS

Loading…
Cancel
Save