You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1232 lines
56 KiB

9 years ago
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
9 years ago
// selftest supports against allpairs list
9 years ago
#include "exchanges777.h"
9 years ago
struct instantdex_stateinfo *BTC_states; int32_t BTC_numstates;
9 years ago
9 years ago
int64_t instantdex_BTCsatoshis(int64_t price,int64_t volume)
9 years ago
{
9 years ago
if ( volume > price )
return(price * dstr(volume));
else return(dstr(price) * volume);
}
9 years ago
9 years ago
int64_t instantdex_insurance(struct iguana_info *coin,int64_t amount)
9 years ago
{
9 years ago
return(amount * INSTANTDEX_INSURANCERATE + coin->chain->txfee); // insurance prevents attack
}
9 years ago
9 years ago
void instantdex_swapfree(struct instantdex_accept *A,struct bitcoin_swapinfo *swap)
9 years ago
{
9 years ago
if ( A != 0 )
free(A);
if ( swap != 0 )
{
if ( swap->deposit != 0 )
free(swap->deposit);
if ( swap->payment != 0 )
free(swap->payment);
if ( swap->altpayment != 0 )
free(swap->altpayment);
9 years ago
if ( swap->myfee != 0 )
free(swap->myfee);
if ( swap->otherfee != 0 )
free(swap->otherfee);
9 years ago
}
}
9 years ago
cJSON *instantdex_defaultprocess(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp)
9 years ago
{
uint8_t *serdata = *serdatap; int32_t serdatalen = *serdatalenp;
9 years ago
*serdatap = 0, *serdatalenp = 0;
if ( serdata != 0 && serdatalen > 0 )
{
serdata[serdatalen-1] = 0;
}
return(newjson);
}
9 years ago
//({"agent":"iguana","method":"addcoin","newcoin":"PPC","active":1,"maxpeers":128,"services":0,"poll":1,"RAM":4,"minoutput":100000,"minconfirms":3,"estblocktime":600,"path":"/data/ppcoin","conf":"/data/.ppcoin","txfee_satoshis":100000,"useaddmultisig":1,"hastimestamp":0,"userhome":"/data/SuperNET/iguana","pubval":"37","scriptval":"75","wiftype":"b7","netmagic":"e6e8e9e5","genesishash":"00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6","genesis":{"hashalgo":"sha256","version":1,"timestamp":1345084287,"nbits":"1d00ffff","nonce":2179302059,"merkleroot":"3c2d8f85fab4d17aac558cc648a1a58acff0de6deb890c29985690052c5993c2"},"p2p":9901,"rpc":9902})
9 years ago
cJSON *instantdex_defaulttimeout(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp)
9 years ago
{
9 years ago
uint8_t *serdata = *serdatap; int32_t serdatalen = *serdatalenp;
9 years ago
*serdatap = 0, *serdatalenp = 0;
if ( serdata != 0 && serdatalen > 0 )
{
serdata[serdatalen-1] = 0;
}
return(newjson);
}
9 years ago
struct instantdex_stateinfo instantdex_errorstate = { "error", 0,0, instantdex_defaultprocess, instantdex_defaulttimeout };
struct instantdex_stateinfo instantdex_timeoutstate = { "timeout", 1,0, instantdex_defaultprocess, instantdex_defaulttimeout };
9 years ago
struct instantdex_stateinfo *instantdex_statefind(struct instantdex_stateinfo *states,int32_t numstates,char *statename)
{
int32_t i; struct instantdex_stateinfo *state = 0;
if ( states != 0 && statename != 0 && numstates > 0 )
{
for (i=0; i<numstates; i++)
{
if ( (state= &states[i]) != 0 && strcmp(state->name,statename) == 0 )
return(state);
}
}
return(0);
}
9 years ago
void instantdex_stateinit(struct instantdex_stateinfo *states,int32_t numstates,struct instantdex_stateinfo *state,char *name,char *errorstr,char *timeoutstr,void *process_func,void *timeout_func)
{
struct instantdex_stateinfo *timeoutstate,*errorstate;
memset(state,0,sizeof(*state));
strcpy(state->name,name);
if ( (errorstate= instantdex_statefind(states,numstates,errorstr)) == 0 )
errorstate = &instantdex_errorstate;
9 years ago
state->errorind = errorstate->ind;
9 years ago
if ( (timeoutstate= instantdex_statefind(states,numstates,timeoutstr)) == 0 )
timeoutstate = &instantdex_timeoutstate;
9 years ago
else printf("TS.%s ",timeoutstr);
state->timeoutind = timeoutstate->ind;
9 years ago
if ( (state->process= process_func) == 0 )
state->process = instantdex_defaultprocess;
if ( (state->timeout= timeout_func) == 0 )
state->timeout = instantdex_defaulttimeout;
}
9 years ago
struct instantdex_stateinfo *instantdex_statecreate(struct instantdex_stateinfo *states,int32_t *numstatesp,char *name,cJSON *(*process_func)(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp),cJSON *(*timeout_func)(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp),char *timeoutstr,char *errorstr,int32_t initialstate)
9 years ago
{
9 years ago
struct instantdex_stateinfo S,*state = 0;
9 years ago
if ( (state= instantdex_statefind(states,*numstatesp,name)) == 0 )
{
states = realloc(states,sizeof(*states) * (*numstatesp + 1));
state = &states[*numstatesp];
9 years ago
instantdex_stateinit(states,*numstatesp,state,name,errorstr,timeoutstr,process_func,timeout_func);
9 years ago
state->initialstate = initialstate;
9 years ago
printf("STATES[%d] %s %p %p %d %d\n",*numstatesp,state->name,state->process,state->timeout,state->timeoutind,state->errorind);
state->ind = (*numstatesp)++;
9 years ago
}
else
{
instantdex_stateinit(states,*numstatesp,&S,name,errorstr,timeoutstr,process_func,timeout_func);
9 years ago
S.ind = state->ind;
9 years ago
S.initialstate = initialstate;
9 years ago
if ( memcmp(&S,state,sizeof(S) - sizeof(void *) - sizeof(int)) != 0 )
{
int32_t i;
for (i=0; i<sizeof(S); i++)
printf("%02x ",((uint8_t *)&S)[i]);
printf("S\n");
for (i=0; i<sizeof(S); i++)
printf("%02x ",((uint8_t *)state)[i]);
printf("state\n");
printf("%s %p %p %d %d vs %s %p %p %d %d\n",state->name,state->process,state->timeout,state->timeoutind,state->errorind,S.name,S.process,S.timeout,S.timeoutind,S.errorind);
9 years ago
printf("statecreate error!!! (%s) already exists\n",name);
9 years ago
}
9 years ago
}
9 years ago
return(states);
9 years ago
}
struct instantdex_event *instantdex_addevent(struct instantdex_stateinfo *states,int32_t numstates,char *statename,char *cmdstr,char *sendcmd,char *nextstatename)
{
struct instantdex_stateinfo *nextstate,*state;
if ( (state= instantdex_statefind(states,numstates,statename)) != 0 && (nextstate= instantdex_statefind(states,numstates,nextstatename)) != 0 )
{
if ( (state->events= realloc(state->events,(state->numevents + 1) * sizeof(*state->events))) != 0 )
{
9 years ago
memset(&state->events[state->numevents],0,sizeof(state->events[state->numevents]));
9 years ago
strcpy(state->events[state->numevents].cmdstr,cmdstr);
9 years ago
if ( sendcmd != 0 )
strcpy(state->events[state->numevents].sendcmd,sendcmd);
9 years ago
state->events[state->numevents].nextstateind = nextstate->ind;
9 years ago
state->numevents++;
}
return(state->events);
}
else
{
9 years ago
int32_t i;
for (i=0; i<numstates; i++)
printf("%s[%d] ",states[i].name,i);
9 years ago
printf("cant add event (%s -> %s) without existing state and nextstate\n",statename,nextstatename);
9 years ago
exit(-1);
9 years ago
return(0);
}
}
double instantdex_FSMtest(struct instantdex_stateinfo *states,int32_t numstates,int32_t maxiters)
9 years ago
{
int32_t i,most,r,r2,n,m=0,initials[100],nextstate=-1;
struct instantdex_stateinfo *state; struct instantdex_event *event; double sum = 0.;
if ( maxiters < 1 )
maxiters = 1;
for (i=n=most=0; i<numstates; i++)
if ( states[i].initialstate > 0 )
{
printf("initialstate[%d] %d %s\n",i,states[i].initialstate,states[i].name);
9 years ago
initials[n++] = i;
}
9 years ago
if ( n > 0 && n < sizeof(initials)/sizeof(*initials) )
{
for (i=0; i<maxiters; i++)
{
r = rand() % n;
state = &states[initials[r]];
if ( state->name[0] == 0 || state->ind >= numstates )
{
printf("illegal state.(%s) %d? ind.%d >= numstates.%d\n",state->name,nextstate,state->ind,numstates);
break;
}
9 years ago
m = 0;
while ( m++ < 1000 && state->initialstate >= 0 && state->numevents != 0 )
9 years ago
{
if ( (i % 1000000) == 0 )
fprintf(stderr,"%s ",state->name);
r2 = rand() % state->numevents;
event = &state->events[r2];
if ( (nextstate= event->nextstateind) < 0 )
break;
if ( event->nextstateind >= numstates )
{
printf("nextstateind overflow? %d vs %d\n",event->nextstateind,numstates);
9 years ago
break;
}
9 years ago
state = &states[event->nextstateind];
}
if ( m > most )
most = m;
sum += m;
if ( (i % 1000000) == 0 )
fprintf(stderr,"reached %s m.%d events most.%d ave %.2f\n",state->name,m,most,sum/(i+1));
9 years ago
}
}
fprintf(stderr," most.%d ave %.2f\n",most,sum/(i+1));
return(sum / maxiters);
9 years ago
}
9 years ago
cJSON *InstantDEX_argjson(char *reference,char *message,char *othercoinaddr,char *otherNXTaddr,int32_t iter,int32_t val,int32_t val2)
9 years ago
{
cJSON *argjson = cJSON_CreateObject();
if ( reference != 0 )
jaddstr(argjson,"refstr",reference);
if ( message != 0 && message[0] != 0 )
jaddstr(argjson,"message",message);
9 years ago
if ( othercoinaddr != 0 && othercoinaddr[0] != 0 )
jaddstr(argjson,"othercoinaddr",othercoinaddr);
if ( otherNXTaddr != 0 && otherNXTaddr[0] != 0 )
jaddstr(argjson,"otherNXTaddr",otherNXTaddr);
//jaddbits256(argjson,"basetxid",basetxid);
//jaddbits256(argjson,"reltxid",reltxid);
9 years ago
if ( iter != 3 )
{
if ( val == 0 )
val = INSTANTDEX_DURATION;
jaddnum(argjson,"duration",val);
jaddnum(argjson,"flags",val2);
}
else
{
if ( val > 0 )
jaddnum(argjson,"baseheight",val);
if ( val2 > 0 )
jaddnum(argjson,"relheight",val2);
}
return(argjson);
}
9 years ago
struct instantdex_msghdr *instantdex_msgcreate(struct supernet_info *myinfo,struct instantdex_msghdr *msg,int32_t datalen)
{
bits256 otherpubkey; uint64_t signerbits; uint32_t timestamp; uint8_t buf[sizeof(msg->sig)],*data;
memset(&msg->sig,0,sizeof(msg->sig));
datalen += (int32_t)(sizeof(*msg) - sizeof(msg->sig));
data = (void *)((long)msg + sizeof(msg->sig));
otherpubkey = acct777_msgpubkey(data,datalen);
timestamp = (uint32_t)time(NULL);
acct777_sign(&msg->sig,myinfo->privkey,otherpubkey,timestamp,data,datalen);
9 years ago
//printf("signed datalen.%d allocsize.%d crc.%x\n",datalen,msg->sig.allocsize,calc_crc32(0,data,datalen));
9 years ago
if ( (signerbits= acct777_validate(&msg->sig,acct777_msgprivkey(data,datalen),msg->sig.pubkey)) != 0 )
{
9 years ago
//int32_t i;
9 years ago
//char str[65],str2[65];
9 years ago
//for (i=0; i<datalen; i++)
// printf("%02x",data[i]);
9 years ago
//printf(">>>>>>>>>>>>>>>> validated [%ld] len.%d (%s + %s)\n",(long)data-(long)msg,datalen,bits256_str(str,acct777_msgprivkey(data,datalen)),bits256_str(str2,msg->sig.pubkey));
9 years ago
memset(buf,0,sizeof(buf));
acct777_rwsig(1,buf,&msg->sig);
memcpy(&msg->sig,buf,sizeof(buf));
return(msg);
} else printf("error validating instantdex msg\n");
return(0);
}
9 years ago
bits256 instantdex_rwoffer(int32_t rwflag,int32_t *lenp,uint8_t *serialized,struct instantdex_offer *offer)
9 years ago
{
9 years ago
bits256 orderhash; int32_t len = 0;
9 years ago
if ( rwflag == 1 )
9 years ago
{
9 years ago
vcalc_sha256(0,orderhash.bytes,(void *)offer,sizeof(*offer));
9 years ago
/*int32_t i;
9 years ago
for (i=0; i<sizeof(*offer); i++)
9 years ago
printf("%02x ",((uint8_t *)offer)[i]);
9 years ago
printf("rwoffer offer\n");*/
9 years ago
}
else
{
memset(offer,0,sizeof(*offer));
9 years ago
}
9 years ago
len += iguana_rwstr(rwflag,&serialized[len],sizeof(offer->base),offer->base);
len += iguana_rwstr(rwflag,&serialized[len],sizeof(offer->rel),offer->rel);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->price64),&offer->price64);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->basevolume64),&offer->basevolume64);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->offer64),&offer->offer64);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->expiration),&offer->expiration);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->nonce),&offer->nonce);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->myside),&offer->myside);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->acceptdir),&offer->acceptdir);
9 years ago
if ( rwflag == 0 )
9 years ago
{
9 years ago
vcalc_sha256(0,orderhash.bytes,(void *)offer,sizeof(*offer));
9 years ago
/*int32_t i;
9 years ago
for (i=0; i<len; i++)
9 years ago
printf("%02x ",serialized[i]);
9 years ago
printf("read rwoffer serialized\n");
for (i=0; i<sizeof(*offer); i++)
printf("%02x ",((uint8_t *)offer)[i]);
9 years ago
printf("rwoffer offer\n");*/
9 years ago
}
9 years ago
/*else
9 years ago
{
int32_t i;
for (i=0; i<len; i++)
printf("%02x ",serialized[i]);
printf("wrote rwoffer serialized\n");
9 years ago
}*/
9 years ago
*lenp = len;
9 years ago
return(orderhash);
9 years ago
}
9 years ago
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen)
9 years ago
{
9 years ago
char *reqstr,*hexstr,*retstr; struct instantdex_msghdr *msg; bits256 instantdexhash,orderhash;
int32_t i,olen,slen,datalen; uint8_t serialized[sizeof(*offer) + 2]; uint64_t nxt64bits;
9 years ago
instantdexhash = calc_categoryhashes(0,"InstantDEX",0);
category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY);
jaddstr(argjson,"cmd",cmdstr);
jaddstr(argjson,"agent","SuperNET");
jaddstr(argjson,"method","DHT");
9 years ago
jaddstr(argjson,"handle",myinfo->handle);
9 years ago
jaddbits256(argjson,"categoryhash",instantdexhash);
jaddbits256(argjson,"traderpub",myinfo->myaddr.persistent);
9 years ago
orderhash = instantdex_rwoffer(1,&olen,serialized,offer);
9 years ago
if ( 1 )
9 years ago
{
struct instantdex_offer checkoffer; bits256 checkhash; int32_t checklen;
checkhash = instantdex_rwoffer(0,&checklen,serialized,&checkoffer);
9 years ago
if ( checkhash.txid != orderhash.txid )
{
for (i=0; i<sizeof(checkoffer); i++)
printf("%02x ",((uint8_t *)&checkoffer)[i]);
printf("checklen.%d checktxid.%llu\n",checklen,(long long)checkhash.txid);
}
9 years ago
}
9 years ago
jadd64bits(argjson,"id",orderhash.txid);
9 years ago
nxt64bits = acct777_nxt64bits(myinfo->myaddr.persistent);
9 years ago
reqstr = jprint(argjson,0);
9 years ago
slen = (int32_t)(strlen(reqstr) + 1);
9 years ago
datalen = (int32_t)slen + extralen + olen;
9 years ago
msg = calloc(1,datalen + sizeof(*msg));
9 years ago
for (i=0; i<sizeof(msg->cmd); i++)
if ( (msg->cmd[i]= cmdstr[i]) == 0 )
break;
9 years ago
memcpy(msg->serialized,reqstr,slen);
memcpy(&msg->serialized[slen],serialized,olen);
9 years ago
//printf("extralen.%d datalen.%d slen.%d olen.%d\n",extralen,datalen,slen,olen);
9 years ago
if ( extralen > 0 )
memcpy(&msg->serialized[slen + olen],extraser,extralen);
9 years ago
free(reqstr);
9 years ago
if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 )
9 years ago
{
9 years ago
printf(">>>>>>>>>>>> instantdex send.(%s) datalen.%d allocsize.%d crc.%x\n",cmdstr,datalen,msg->sig.allocsize,calc_crc32(0,(void *)((long)msg + 8),datalen-8));
9 years ago
hexstr = malloc(msg->sig.allocsize*2 + 1);
9 years ago
init_hexbytes_noT(hexstr,(uint8_t *)msg,msg->sig.allocsize);
9 years ago
retstr = SuperNET_categorymulticast(myinfo,0,instantdexhash,desthash,hexstr,0,hops,1,argjson,0);
9 years ago
free_json(argjson), free(hexstr), free(msg);
9 years ago
return(retstr);
9 years ago
}
else
{
9 years ago
free_json(argjson), free(msg);
9 years ago
printf("cant msgcreate datalen.%d\n",datalen);
9 years ago
return(clonestr("{\"error\":\"couldnt create instantdex message\"}"));
}
}
many changes blockexplorer tab: needs to allow to input height, blockhash or txid. also please display images/BTC_blocks.jpg below the text as a w800 x h400 bitmap, which is active using the mouse api for coin management, below the active coins have a form that arbitrary json can be input with an add button to the right that will call &#34;addcoin&#34; API. this way I can test adding new coins dynamically. dont worry if it doesnt work, just as long as it submits the json to the C code. I am pretty sure I need to do some debugging of this peers management is not working for me at all. maybe it is due to bad internet. On initialization you need to read in the confs/BTCD_peers.txt from the native filesystem and save it into the chrome app filesystem. same thing for confs/BTCD_hdrs.txt. But this is only to be done if there isnt already such a file inside chrome. if there is, only do it upon a button invoked by the user. the reason is that the pexe is updating this file with the latest. Maybe it is nice to have an &#34;extract&#34; button that will copy out from the chrome storage into the native filesystem. There is also the manifest issue about localstorage vs chrome.localstorage. not sure what is needed to be done, but certainly a priority to get it so everything works as a chrome app. I know before it was making ramchain files inside the chrome filesystem, so it is probably things the GUI is doing. maybe in the settings tab, which has obsolete stuff that can be removed. anyway, the issue about files existing in the native filesystem -&gt; chrome and optionally extracting them is an issue for the confs files and .html template files used to autogenerate the port7778, maybe other files are affected. i think we need a way to have a list of hardcoded files that are just copied into chrome on startup if they dont exist already (or if possible copy over if the native version is bigger?) and buttons to extract them for debug tab: THREE_STRINGS(SuperNET,encryptjson,passphrase,permanentfile,anything); TWO_STRINGS(SuperNET,decryptjson,passphrase,permanentfile); at the top of page a way to put in passphrase and optional permanentfile along with arbitrary json. The standard form template has no easy way to describe to pass in everything as it is oriented to specific fields. but the encryptjson API saves all the fields, so the arbitrary json from the form needs to be combined at the same level as the &#34;agent&#34;, &#34;method&#34;, etc. I know, not the best, but internally it makes it easier. so {&#34;agent&#34;:&#34;SuperNET&#34;,&#34;method&#34;:&#34;encryptjson&#34;,&#34;passphrase&#34;:&#34;&lt;passphrase&gt;&#34;,&#34; permanentfile&#34;:&#34;&lt;filename&gt;&#34;,&#34;fromform&#34;:&#34;valuefromform&#34;,&#34;fromform2&#34;:&#34;valu efromform2&#34;,...rest of form at top level} then this will save it into a file with crazy number (it is a hash like txid) but given the same passphrase and filename, it will regenerate this hash so you dont actually have to store it, but it helps during debugging. for the filename, we must warn quite strongly to the user that if the file is ever lost or even changed in any way that the data will not be recoverable. also best to not allow the user to specify a file that does not exist. I think at this point chrome app version gets a bit tricky. we could simply push the native file into the chrome storage, but then an attacker who gets access to the computer could just get a list of these files and it really wont be much protection. So that means if a filename is specified, it needs to be copied into the chrome space, then immediately deleted... ok, this seems like not a good approach. let us make it so that the permanentfile option is not available from the chrome app, but only if the native version is running. that way we sidestep the issue of the pexe not having access to the specified file. Speaking of native vs pexe, on the startup page we should have a radio button that allows the user to select which the GUI will talk to. It should default based on a self test to the more likely value, but it is possible that the user wants to use the native version, even if the pexe is running. another thing to have on the startup page is a simple login: THREE_STRINGS(SuperNET,login,passphrase,permanentfile,handle); ZERO_ARGS(SuperNET,logout); ZERO_ARGS(SuperNET,activehandle); the handle is a human readable name that is associated with the passphrase/permanentfile. There can only be one active account (though it will be possible to associate different accounts with tradebots). use the activehandle API to find out who is logged in and the associated addresses and pubkeys The above is not yet tested so if it doesnt work, dont fret, just let me know. Once set the handle can be displayed in various places to let the user know which account is logged in. The standard 12 dictionary word passphrases should be used, but any string can be sent in as the password for Pangea: INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_ARG(pangea,start,tablehash); // by host only HASH_ARG(pangea,status,tablehash); HASH_ARG(pangea,call,tablehash); HASH_ARG(pangea,check,tablehash); HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_ARG(pangea,fold,tablehash); HASH_AND_STRING(pangea,mode,tablehash,modestr); HASH_ARG(pangea,history,tablehash); HASH_AND_INT(pangea,handhistory,tablehash,hand); The first thing that is done is a &#34;host&#34; by any node. the &#34;params&#34; should be an arbitrary json (like encryptjson) as it needs to be at the top level and it has quite a few different parameters still subject to change. The lobby API will just display all the hosted tables. once a table exists, players can join and then buyin. the buyin is denominated in chips, each chip&#39;s value is determined by the host&#39;s initial parameters. once there are enough players joined with adequate buyin&#39;s verified, the host will be able to do a start. if done before it will (eventually) give an error. for now it will just proceed. The host and players that have joined a tablehash, need to do regular status calls to see if the game has started. Probably just once per 5 or even 10 seconds is fine before the start. Once the game starts (the status will have this info) then once per second polling is needed. Then when it is your turn (as indicated by status) you need to do one of the 5 actions (fold, call, check, raise, bet). do not worry if you dont understand what all these do, just allow the user to do any of these. I guess it is possible to submit it ahead of time. I will support internally remembering the most recent action done prior to it being your turn. once it is your turn and an action is sent to the table, it is too late to change. The last API calls are for getting handhistory where hand is 0 to N-1, being the numbering of the hands played at that table. if just history, all the history for all hands at the table is coming back, so it could be quite big. probably I will make it a summary, but for the GUI just display the returned values. the mode is to change some poker specific modes, so just allow there to be a string entered. do not worry about understanding the pokerness of the API, just the overall flow: host -&gt; creates, join/buyin -&gt; fills up player slots, start -&gt; starts the game status -&gt; to determine when the game starts (or if it is cancelled) and once started actions -&gt; game specific but basically just (button + arg) that is the user input results are via status for current game and history for past ones please try to do the above logic in a generic way so it can be reused for other games. The basic flow should be the same for almost all multiplayer turn based games and even for multiplayer realtime games For InstantDEX: on the apikeypair/userid there needs to be two modes. one for when there is no stored apikey and the current form is fine, just need to make it wider as most apikeys are quite long. Now once there is an apikey saved all that is needed is the passphrase to unlock it. So here is where the encrptjson/decryptjson is used. When saving the apikey for the first time, it can be: a) not saved -&gt; nothing extra to do b) saved without password -&gt; you can just save to a file and use it to load it back in. use confs dir confs/instantdex.exchange.api or something like that c) saved with password (optional filename for native) -&gt; probably best to save in the confs dir to indicate that there is an encrypted file for this, so just that and not the actual passphrase in the file with the above, when the exchange is selected, you can see if the confs file exists and if it has the plaintext, just populate the field, if not, then indicate that a passphrase is needed. if the user provides the passphrase, then decryptjson and populate the fields and autosubmit. A special case is to encrypt the apikeys with the passphrase used when logging in. This is only available if the checkbox to &#34;remember passphrase during session&#34; is set on the main iguana login screen. (i forgot to mention that checkbox!) So the login passphrase is stored in memory, then the GUI simply uses that + encryptjson for storing/decrypting. I would imagine that storing in the confs file that it is encrypted using &#34;handle&#34;&#39;s account login might be a good way to differentiate between this mode of password usage. OK, so we now have the insecure plaintext, the decent using handle&#39;s passphrase and paranoid different passphrase for each exchange (with additional permanentfile for native versions) &#34;SUPPORT&#34; -&gt; &#34;SUPPORTS&#34; just a typo and &#34;allpairs&#34; API is missing from the selection Might as well add a &#34;tradebots&#34; tab: THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission); STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission); THREE_STRINGS(tradebot,unmonitor,exchange,base,rel); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,accumulate,exchange,base,rel,pr ice,volume,duration); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,divest,exchange,base,rel,price, volume,duration); STRING_ARG(tradebot,activebots,exchange); TWO_STRINGS(tradebot,status,exchange,botid); TWO_STRINGS(tradebot,pause,exchange,botid); TWO_STRINGS(tradebot,stop,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid); the above are API for exchange specific bots, most should be self-explanatory. bots are created via &#34;accumulate&#34; or &#34;divest&#34; API call. it returns botid. once created, you can do status, pause, stop, resume to a botid. and an activebots API call lists all the active bots for an exchange. duration is in seconds the &#34;monitor&#34; API starts background monitoring of a specific base/rel, &#34;unmonitor&#34; stops this. &#34;monitorall&#34; just does a monitor to the entire list of &#34;allpairs&#34; for that exchange. Keep in mind that doing a monitorall will not add load to an exchange as the request to each exchange is governed by pollgap, but if you have 3 things monitored, it will take 3*pollgap + time each one takes to execute. and if N are monitored it is N*pollgap + time of each, with the &#34;time of each&#34; possibly taking a very long time. And one final request for today: Bitmap tab. It should be an active bitmap using mouse api. either a dropdown to select the bitmap or a form entry. then the rest of the page (resize the bitmap to the page size) being the active bitmap. So on a small screen the bitmap is smaller x/y dimensions and larger on larger screens. plz make sure the proper dimensions are communicated to the pexe via API if it ever is changed. @vineet.bhargav86: I changed the &#34;passphrase&#34; fieldname to &#34;password&#34; for the encryptjson/decryptjson related API. The reason is that the password is like a wallet password and is only local, so it doesnt need to be as high entropy as passphrase. I also added a field to the login API as I realized that the 12 word &#34;passphrase&#34; is the payload and usually wont be sent in: FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase); using &#34;abiglongpassword&#34; for the passphrase -&gt; {&#34;pubkey&#34;:&#34;6c469ba10b40b3eb9d1dba569d7f929d55a29d8f97cd5425907ef2f38f906 209&#34;,&#34;RS&#34;:&#34;NXT-KGV9-DXX8-TM86-DXR96&#34;,&#34;NXT&#34;:&#34;12834974574569896807&#34;,&#34;btcpu bkey&#34;:&#34;024e7641dc947b211bc30fe3339765258902794687b227121fc217284f9d8503c 8&#34;,&#34;rmd160&#34;:&#34;33453c24914db7b77069b7ea24df44f6be145938&#34;,&#34;BTC&#34;:&#34;15g6QK2dSd iW9ZTQEnnJxKrSph6uP7uU23&#34;,&#34;BTCD&#34;:&#34;RDxHUpuv3TX5DZpbhxmS3rBeaxZW1fvYvC&#34;,&#34;r esult&#34;:&#34;success&#34;,&#34;handle&#34;:&#34;test&#34;,&#34;tag&#34;:&#34;14805226009240621255&#34;} and if you use that to log into NXT, it gives the same address. The BTC and BTCD addresses are all derived from the same privkey so they are all interchangeable with the NXT address. The user can therefore select which coin&#39;s addressing they are most comfortable with I also added an &#34;allin&#34; action API for pangea. all the action API will autocalculate the number of chips if passed in 0 for numchips ***************** security issue ******** please dont use the GET URL method when dealing with passphrase!!! Those URL&#39;s tend to get logged and available in browser histories. so anything dealing with the actual passphrase needs to use the postCall form or POST
9 years ago
int32_t instantdex_updatesources(struct exchange_info *exchange,struct exchange_quote *sortbuf,int32_t n,int32_t max,int32_t ind,int32_t dir,struct exchange_quote *quotes,int32_t numquotes)
9 years ago
{
int32_t i; struct exchange_quote *quote;
9 years ago
//printf("instantdex_updatesources update dir.%d numquotes.%d\n",dir,numquotes);
9 years ago
for (i=0; i<numquotes; i++)
{
quote = &quotes[i << 1];
9 years ago
//printf("n.%d ind.%d i.%d dir.%d price %.8f vol %.8f\n",n,ind,i,dir,quote->price,quote->volume);
if ( quote->price > SMALLVAL )
{
9 years ago
sortbuf[n] = *quote;
sortbuf[n].val = ind;
many changes blockexplorer tab: needs to allow to input height, blockhash or txid. also please display images/BTC_blocks.jpg below the text as a w800 x h400 bitmap, which is active using the mouse api for coin management, below the active coins have a form that arbitrary json can be input with an add button to the right that will call &#34;addcoin&#34; API. this way I can test adding new coins dynamically. dont worry if it doesnt work, just as long as it submits the json to the C code. I am pretty sure I need to do some debugging of this peers management is not working for me at all. maybe it is due to bad internet. On initialization you need to read in the confs/BTCD_peers.txt from the native filesystem and save it into the chrome app filesystem. same thing for confs/BTCD_hdrs.txt. But this is only to be done if there isnt already such a file inside chrome. if there is, only do it upon a button invoked by the user. the reason is that the pexe is updating this file with the latest. Maybe it is nice to have an &#34;extract&#34; button that will copy out from the chrome storage into the native filesystem. There is also the manifest issue about localstorage vs chrome.localstorage. not sure what is needed to be done, but certainly a priority to get it so everything works as a chrome app. I know before it was making ramchain files inside the chrome filesystem, so it is probably things the GUI is doing. maybe in the settings tab, which has obsolete stuff that can be removed. anyway, the issue about files existing in the native filesystem -&gt; chrome and optionally extracting them is an issue for the confs files and .html template files used to autogenerate the port7778, maybe other files are affected. i think we need a way to have a list of hardcoded files that are just copied into chrome on startup if they dont exist already (or if possible copy over if the native version is bigger?) and buttons to extract them for debug tab: THREE_STRINGS(SuperNET,encryptjson,passphrase,permanentfile,anything); TWO_STRINGS(SuperNET,decryptjson,passphrase,permanentfile); at the top of page a way to put in passphrase and optional permanentfile along with arbitrary json. The standard form template has no easy way to describe to pass in everything as it is oriented to specific fields. but the encryptjson API saves all the fields, so the arbitrary json from the form needs to be combined at the same level as the &#34;agent&#34;, &#34;method&#34;, etc. I know, not the best, but internally it makes it easier. so {&#34;agent&#34;:&#34;SuperNET&#34;,&#34;method&#34;:&#34;encryptjson&#34;,&#34;passphrase&#34;:&#34;&lt;passphrase&gt;&#34;,&#34; permanentfile&#34;:&#34;&lt;filename&gt;&#34;,&#34;fromform&#34;:&#34;valuefromform&#34;,&#34;fromform2&#34;:&#34;valu efromform2&#34;,...rest of form at top level} then this will save it into a file with crazy number (it is a hash like txid) but given the same passphrase and filename, it will regenerate this hash so you dont actually have to store it, but it helps during debugging. for the filename, we must warn quite strongly to the user that if the file is ever lost or even changed in any way that the data will not be recoverable. also best to not allow the user to specify a file that does not exist. I think at this point chrome app version gets a bit tricky. we could simply push the native file into the chrome storage, but then an attacker who gets access to the computer could just get a list of these files and it really wont be much protection. So that means if a filename is specified, it needs to be copied into the chrome space, then immediately deleted... ok, this seems like not a good approach. let us make it so that the permanentfile option is not available from the chrome app, but only if the native version is running. that way we sidestep the issue of the pexe not having access to the specified file. Speaking of native vs pexe, on the startup page we should have a radio button that allows the user to select which the GUI will talk to. It should default based on a self test to the more likely value, but it is possible that the user wants to use the native version, even if the pexe is running. another thing to have on the startup page is a simple login: THREE_STRINGS(SuperNET,login,passphrase,permanentfile,handle); ZERO_ARGS(SuperNET,logout); ZERO_ARGS(SuperNET,activehandle); the handle is a human readable name that is associated with the passphrase/permanentfile. There can only be one active account (though it will be possible to associate different accounts with tradebots). use the activehandle API to find out who is logged in and the associated addresses and pubkeys The above is not yet tested so if it doesnt work, dont fret, just let me know. Once set the handle can be displayed in various places to let the user know which account is logged in. The standard 12 dictionary word passphrases should be used, but any string can be sent in as the password for Pangea: INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_ARG(pangea,start,tablehash); // by host only HASH_ARG(pangea,status,tablehash); HASH_ARG(pangea,call,tablehash); HASH_ARG(pangea,check,tablehash); HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_ARG(pangea,fold,tablehash); HASH_AND_STRING(pangea,mode,tablehash,modestr); HASH_ARG(pangea,history,tablehash); HASH_AND_INT(pangea,handhistory,tablehash,hand); The first thing that is done is a &#34;host&#34; by any node. the &#34;params&#34; should be an arbitrary json (like encryptjson) as it needs to be at the top level and it has quite a few different parameters still subject to change. The lobby API will just display all the hosted tables. once a table exists, players can join and then buyin. the buyin is denominated in chips, each chip&#39;s value is determined by the host&#39;s initial parameters. once there are enough players joined with adequate buyin&#39;s verified, the host will be able to do a start. if done before it will (eventually) give an error. for now it will just proceed. The host and players that have joined a tablehash, need to do regular status calls to see if the game has started. Probably just once per 5 or even 10 seconds is fine before the start. Once the game starts (the status will have this info) then once per second polling is needed. Then when it is your turn (as indicated by status) you need to do one of the 5 actions (fold, call, check, raise, bet). do not worry if you dont understand what all these do, just allow the user to do any of these. I guess it is possible to submit it ahead of time. I will support internally remembering the most recent action done prior to it being your turn. once it is your turn and an action is sent to the table, it is too late to change. The last API calls are for getting handhistory where hand is 0 to N-1, being the numbering of the hands played at that table. if just history, all the history for all hands at the table is coming back, so it could be quite big. probably I will make it a summary, but for the GUI just display the returned values. the mode is to change some poker specific modes, so just allow there to be a string entered. do not worry about understanding the pokerness of the API, just the overall flow: host -&gt; creates, join/buyin -&gt; fills up player slots, start -&gt; starts the game status -&gt; to determine when the game starts (or if it is cancelled) and once started actions -&gt; game specific but basically just (button + arg) that is the user input results are via status for current game and history for past ones please try to do the above logic in a generic way so it can be reused for other games. The basic flow should be the same for almost all multiplayer turn based games and even for multiplayer realtime games For InstantDEX: on the apikeypair/userid there needs to be two modes. one for when there is no stored apikey and the current form is fine, just need to make it wider as most apikeys are quite long. Now once there is an apikey saved all that is needed is the passphrase to unlock it. So here is where the encrptjson/decryptjson is used. When saving the apikey for the first time, it can be: a) not saved -&gt; nothing extra to do b) saved without password -&gt; you can just save to a file and use it to load it back in. use confs dir confs/instantdex.exchange.api or something like that c) saved with password (optional filename for native) -&gt; probably best to save in the confs dir to indicate that there is an encrypted file for this, so just that and not the actual passphrase in the file with the above, when the exchange is selected, you can see if the confs file exists and if it has the plaintext, just populate the field, if not, then indicate that a passphrase is needed. if the user provides the passphrase, then decryptjson and populate the fields and autosubmit. A special case is to encrypt the apikeys with the passphrase used when logging in. This is only available if the checkbox to &#34;remember passphrase during session&#34; is set on the main iguana login screen. (i forgot to mention that checkbox!) So the login passphrase is stored in memory, then the GUI simply uses that + encryptjson for storing/decrypting. I would imagine that storing in the confs file that it is encrypted using &#34;handle&#34;&#39;s account login might be a good way to differentiate between this mode of password usage. OK, so we now have the insecure plaintext, the decent using handle&#39;s passphrase and paranoid different passphrase for each exchange (with additional permanentfile for native versions) &#34;SUPPORT&#34; -&gt; &#34;SUPPORTS&#34; just a typo and &#34;allpairs&#34; API is missing from the selection Might as well add a &#34;tradebots&#34; tab: THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission); STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission); THREE_STRINGS(tradebot,unmonitor,exchange,base,rel); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,accumulate,exchange,base,rel,pr ice,volume,duration); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,divest,exchange,base,rel,price, volume,duration); STRING_ARG(tradebot,activebots,exchange); TWO_STRINGS(tradebot,status,exchange,botid); TWO_STRINGS(tradebot,pause,exchange,botid); TWO_STRINGS(tradebot,stop,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid); the above are API for exchange specific bots, most should be self-explanatory. bots are created via &#34;accumulate&#34; or &#34;divest&#34; API call. it returns botid. once created, you can do status, pause, stop, resume to a botid. and an activebots API call lists all the active bots for an exchange. duration is in seconds the &#34;monitor&#34; API starts background monitoring of a specific base/rel, &#34;unmonitor&#34; stops this. &#34;monitorall&#34; just does a monitor to the entire list of &#34;allpairs&#34; for that exchange. Keep in mind that doing a monitorall will not add load to an exchange as the request to each exchange is governed by pollgap, but if you have 3 things monitored, it will take 3*pollgap + time each one takes to execute. and if N are monitored it is N*pollgap + time of each, with the &#34;time of each&#34; possibly taking a very long time. And one final request for today: Bitmap tab. It should be an active bitmap using mouse api. either a dropdown to select the bitmap or a form entry. then the rest of the page (resize the bitmap to the page size) being the active bitmap. So on a small screen the bitmap is smaller x/y dimensions and larger on larger screens. plz make sure the proper dimensions are communicated to the pexe via API if it ever is changed. @vineet.bhargav86: I changed the &#34;passphrase&#34; fieldname to &#34;password&#34; for the encryptjson/decryptjson related API. The reason is that the password is like a wallet password and is only local, so it doesnt need to be as high entropy as passphrase. I also added a field to the login API as I realized that the 12 word &#34;passphrase&#34; is the payload and usually wont be sent in: FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase); using &#34;abiglongpassword&#34; for the passphrase -&gt; {&#34;pubkey&#34;:&#34;6c469ba10b40b3eb9d1dba569d7f929d55a29d8f97cd5425907ef2f38f906 209&#34;,&#34;RS&#34;:&#34;NXT-KGV9-DXX8-TM86-DXR96&#34;,&#34;NXT&#34;:&#34;12834974574569896807&#34;,&#34;btcpu bkey&#34;:&#34;024e7641dc947b211bc30fe3339765258902794687b227121fc217284f9d8503c 8&#34;,&#34;rmd160&#34;:&#34;33453c24914db7b77069b7ea24df44f6be145938&#34;,&#34;BTC&#34;:&#34;15g6QK2dSd iW9ZTQEnnJxKrSph6uP7uU23&#34;,&#34;BTCD&#34;:&#34;RDxHUpuv3TX5DZpbhxmS3rBeaxZW1fvYvC&#34;,&#34;r esult&#34;:&#34;success&#34;,&#34;handle&#34;:&#34;test&#34;,&#34;tag&#34;:&#34;14805226009240621255&#34;} and if you use that to log into NXT, it gives the same address. The BTC and BTCD addresses are all derived from the same privkey so they are all interchangeable with the NXT address. The user can therefore select which coin&#39;s addressing they are most comfortable with I also added an &#34;allin&#34; action API for pangea. all the action API will autocalculate the number of chips if passed in 0 for numchips ***************** security issue ******** please dont use the GET URL method when dealing with passphrase!!! Those URL&#39;s tend to get logged and available in browser histories. so anything dealing with the actual passphrase needs to use the postCall form or POST
9 years ago
sortbuf[n].exchangebits = exchange->exchangebits;
9 years ago
//printf("sortbuf[%d] <-\n",n*2);
9 years ago
if ( ++n >= max )
break;
9 years ago
}
9 years ago
}
9 years ago
return(n);
9 years ago
}
9 years ago
double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *sortbuf,int32_t max,double *totalvolp,char *base,char *rel,double basevolume,cJSON *argjson)
9 years ago
{
9 years ago
char *str; double totalvol,pricesum; uint32_t timestamp;
9 years ago
struct exchange_quote quote; int32_t i,n,dir,num,depth = 100;
9 years ago
struct exchange_info *exchange; struct exchange_request *req,*active[64];
9 years ago
timestamp = (uint32_t)time(NULL);
9 years ago
if ( basevolume < 0. )
basevolume = -basevolume, dir = -1;
9 years ago
else dir = 1;
memset(sortbuf,0,sizeof(*sortbuf) * max);
9 years ago
if ( base != 0 && rel != 0 && basevolume > SMALLVAL )
9 years ago
{
9 years ago
for (i=num=0; i<myinfo->numexchanges && num < sizeof(active)/sizeof(*active); i++)
{
9 years ago
if ( (exchange= myinfo->tradingexchanges[i]) != 0 )
{
9 years ago
if ( (req= exchanges777_baserelfind(exchange,base,rel,'M')) == 0 )
{
if ( (str= exchanges777_Qprices(exchange,base,rel,30,1,depth,argjson,1,exchange->commission)) != 0 )
free(str);
req = exchanges777_baserelfind(exchange,base,rel,'M');
}
if ( req == 0 )
{
if ( (*exchange->issue.supports)(exchange,base,rel,argjson) != 0 )
printf("unexpected null req.(%s %s) %s\n",base,rel,exchange->name);
}
else
{
9 years ago
//printf("active.%s\n",exchange->name);
9 years ago
active[num++] = req;
}
}
9 years ago
}
for (i=n=0; i<num; i++)
{
9 years ago
if ( dir < 0 && active[i]->numbids > 0 )
many changes blockexplorer tab: needs to allow to input height, blockhash or txid. also please display images/BTC_blocks.jpg below the text as a w800 x h400 bitmap, which is active using the mouse api for coin management, below the active coins have a form that arbitrary json can be input with an add button to the right that will call &#34;addcoin&#34; API. this way I can test adding new coins dynamically. dont worry if it doesnt work, just as long as it submits the json to the C code. I am pretty sure I need to do some debugging of this peers management is not working for me at all. maybe it is due to bad internet. On initialization you need to read in the confs/BTCD_peers.txt from the native filesystem and save it into the chrome app filesystem. same thing for confs/BTCD_hdrs.txt. But this is only to be done if there isnt already such a file inside chrome. if there is, only do it upon a button invoked by the user. the reason is that the pexe is updating this file with the latest. Maybe it is nice to have an &#34;extract&#34; button that will copy out from the chrome storage into the native filesystem. There is also the manifest issue about localstorage vs chrome.localstorage. not sure what is needed to be done, but certainly a priority to get it so everything works as a chrome app. I know before it was making ramchain files inside the chrome filesystem, so it is probably things the GUI is doing. maybe in the settings tab, which has obsolete stuff that can be removed. anyway, the issue about files existing in the native filesystem -&gt; chrome and optionally extracting them is an issue for the confs files and .html template files used to autogenerate the port7778, maybe other files are affected. i think we need a way to have a list of hardcoded files that are just copied into chrome on startup if they dont exist already (or if possible copy over if the native version is bigger?) and buttons to extract them for debug tab: THREE_STRINGS(SuperNET,encryptjson,passphrase,permanentfile,anything); TWO_STRINGS(SuperNET,decryptjson,passphrase,permanentfile); at the top of page a way to put in passphrase and optional permanentfile along with arbitrary json. The standard form template has no easy way to describe to pass in everything as it is oriented to specific fields. but the encryptjson API saves all the fields, so the arbitrary json from the form needs to be combined at the same level as the &#34;agent&#34;, &#34;method&#34;, etc. I know, not the best, but internally it makes it easier. so {&#34;agent&#34;:&#34;SuperNET&#34;,&#34;method&#34;:&#34;encryptjson&#34;,&#34;passphrase&#34;:&#34;&lt;passphrase&gt;&#34;,&#34; permanentfile&#34;:&#34;&lt;filename&gt;&#34;,&#34;fromform&#34;:&#34;valuefromform&#34;,&#34;fromform2&#34;:&#34;valu efromform2&#34;,...rest of form at top level} then this will save it into a file with crazy number (it is a hash like txid) but given the same passphrase and filename, it will regenerate this hash so you dont actually have to store it, but it helps during debugging. for the filename, we must warn quite strongly to the user that if the file is ever lost or even changed in any way that the data will not be recoverable. also best to not allow the user to specify a file that does not exist. I think at this point chrome app version gets a bit tricky. we could simply push the native file into the chrome storage, but then an attacker who gets access to the computer could just get a list of these files and it really wont be much protection. So that means if a filename is specified, it needs to be copied into the chrome space, then immediately deleted... ok, this seems like not a good approach. let us make it so that the permanentfile option is not available from the chrome app, but only if the native version is running. that way we sidestep the issue of the pexe not having access to the specified file. Speaking of native vs pexe, on the startup page we should have a radio button that allows the user to select which the GUI will talk to. It should default based on a self test to the more likely value, but it is possible that the user wants to use the native version, even if the pexe is running. another thing to have on the startup page is a simple login: THREE_STRINGS(SuperNET,login,passphrase,permanentfile,handle); ZERO_ARGS(SuperNET,logout); ZERO_ARGS(SuperNET,activehandle); the handle is a human readable name that is associated with the passphrase/permanentfile. There can only be one active account (though it will be possible to associate different accounts with tradebots). use the activehandle API to find out who is logged in and the associated addresses and pubkeys The above is not yet tested so if it doesnt work, dont fret, just let me know. Once set the handle can be displayed in various places to let the user know which account is logged in. The standard 12 dictionary word passphrases should be used, but any string can be sent in as the password for Pangea: INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_ARG(pangea,start,tablehash); // by host only HASH_ARG(pangea,status,tablehash); HASH_ARG(pangea,call,tablehash); HASH_ARG(pangea,check,tablehash); HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_ARG(pangea,fold,tablehash); HASH_AND_STRING(pangea,mode,tablehash,modestr); HASH_ARG(pangea,history,tablehash); HASH_AND_INT(pangea,handhistory,tablehash,hand); The first thing that is done is a &#34;host&#34; by any node. the &#34;params&#34; should be an arbitrary json (like encryptjson) as it needs to be at the top level and it has quite a few different parameters still subject to change. The lobby API will just display all the hosted tables. once a table exists, players can join and then buyin. the buyin is denominated in chips, each chip&#39;s value is determined by the host&#39;s initial parameters. once there are enough players joined with adequate buyin&#39;s verified, the host will be able to do a start. if done before it will (eventually) give an error. for now it will just proceed. The host and players that have joined a tablehash, need to do regular status calls to see if the game has started. Probably just once per 5 or even 10 seconds is fine before the start. Once the game starts (the status will have this info) then once per second polling is needed. Then when it is your turn (as indicated by status) you need to do one of the 5 actions (fold, call, check, raise, bet). do not worry if you dont understand what all these do, just allow the user to do any of these. I guess it is possible to submit it ahead of time. I will support internally remembering the most recent action done prior to it being your turn. once it is your turn and an action is sent to the table, it is too late to change. The last API calls are for getting handhistory where hand is 0 to N-1, being the numbering of the hands played at that table. if just history, all the history for all hands at the table is coming back, so it could be quite big. probably I will make it a summary, but for the GUI just display the returned values. the mode is to change some poker specific modes, so just allow there to be a string entered. do not worry about understanding the pokerness of the API, just the overall flow: host -&gt; creates, join/buyin -&gt; fills up player slots, start -&gt; starts the game status -&gt; to determine when the game starts (or if it is cancelled) and once started actions -&gt; game specific but basically just (button + arg) that is the user input results are via status for current game and history for past ones please try to do the above logic in a generic way so it can be reused for other games. The basic flow should be the same for almost all multiplayer turn based games and even for multiplayer realtime games For InstantDEX: on the apikeypair/userid there needs to be two modes. one for when there is no stored apikey and the current form is fine, just need to make it wider as most apikeys are quite long. Now once there is an apikey saved all that is needed is the passphrase to unlock it. So here is where the encrptjson/decryptjson is used. When saving the apikey for the first time, it can be: a) not saved -&gt; nothing extra to do b) saved without password -&gt; you can just save to a file and use it to load it back in. use confs dir confs/instantdex.exchange.api or something like that c) saved with password (optional filename for native) -&gt; probably best to save in the confs dir to indicate that there is an encrypted file for this, so just that and not the actual passphrase in the file with the above, when the exchange is selected, you can see if the confs file exists and if it has the plaintext, just populate the field, if not, then indicate that a passphrase is needed. if the user provides the passphrase, then decryptjson and populate the fields and autosubmit. A special case is to encrypt the apikeys with the passphrase used when logging in. This is only available if the checkbox to &#34;remember passphrase during session&#34; is set on the main iguana login screen. (i forgot to mention that checkbox!) So the login passphrase is stored in memory, then the GUI simply uses that + encryptjson for storing/decrypting. I would imagine that storing in the confs file that it is encrypted using &#34;handle&#34;&#39;s account login might be a good way to differentiate between this mode of password usage. OK, so we now have the insecure plaintext, the decent using handle&#39;s passphrase and paranoid different passphrase for each exchange (with additional permanentfile for native versions) &#34;SUPPORT&#34; -&gt; &#34;SUPPORTS&#34; just a typo and &#34;allpairs&#34; API is missing from the selection Might as well add a &#34;tradebots&#34; tab: THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission); STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission); THREE_STRINGS(tradebot,unmonitor,exchange,base,rel); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,accumulate,exchange,base,rel,pr ice,volume,duration); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,divest,exchange,base,rel,price, volume,duration); STRING_ARG(tradebot,activebots,exchange); TWO_STRINGS(tradebot,status,exchange,botid); TWO_STRINGS(tradebot,pause,exchange,botid); TWO_STRINGS(tradebot,stop,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid); the above are API for exchange specific bots, most should be self-explanatory. bots are created via &#34;accumulate&#34; or &#34;divest&#34; API call. it returns botid. once created, you can do status, pause, stop, resume to a botid. and an activebots API call lists all the active bots for an exchange. duration is in seconds the &#34;monitor&#34; API starts background monitoring of a specific base/rel, &#34;unmonitor&#34; stops this. &#34;monitorall&#34; just does a monitor to the entire list of &#34;allpairs&#34; for that exchange. Keep in mind that doing a monitorall will not add load to an exchange as the request to each exchange is governed by pollgap, but if you have 3 things monitored, it will take 3*pollgap + time each one takes to execute. and if N are monitored it is N*pollgap + time of each, with the &#34;time of each&#34; possibly taking a very long time. And one final request for today: Bitmap tab. It should be an active bitmap using mouse api. either a dropdown to select the bitmap or a form entry. then the rest of the page (resize the bitmap to the page size) being the active bitmap. So on a small screen the bitmap is smaller x/y dimensions and larger on larger screens. plz make sure the proper dimensions are communicated to the pexe via API if it ever is changed. @vineet.bhargav86: I changed the &#34;passphrase&#34; fieldname to &#34;password&#34; for the encryptjson/decryptjson related API. The reason is that the password is like a wallet password and is only local, so it doesnt need to be as high entropy as passphrase. I also added a field to the login API as I realized that the 12 word &#34;passphrase&#34; is the payload and usually wont be sent in: FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase); using &#34;abiglongpassword&#34; for the passphrase -&gt; {&#34;pubkey&#34;:&#34;6c469ba10b40b3eb9d1dba569d7f929d55a29d8f97cd5425907ef2f38f906 209&#34;,&#34;RS&#34;:&#34;NXT-KGV9-DXX8-TM86-DXR96&#34;,&#34;NXT&#34;:&#34;12834974574569896807&#34;,&#34;btcpu bkey&#34;:&#34;024e7641dc947b211bc30fe3339765258902794687b227121fc217284f9d8503c 8&#34;,&#34;rmd160&#34;:&#34;33453c24914db7b77069b7ea24df44f6be145938&#34;,&#34;BTC&#34;:&#34;15g6QK2dSd iW9ZTQEnnJxKrSph6uP7uU23&#34;,&#34;BTCD&#34;:&#34;RDxHUpuv3TX5DZpbhxmS3rBeaxZW1fvYvC&#34;,&#34;r esult&#34;:&#34;success&#34;,&#34;handle&#34;:&#34;test&#34;,&#34;tag&#34;:&#34;14805226009240621255&#34;} and if you use that to log into NXT, it gives the same address. The BTC and BTCD addresses are all derived from the same privkey so they are all interchangeable with the NXT address. The user can therefore select which coin&#39;s addressing they are most comfortable with I also added an &#34;allin&#34; action API for pangea. all the action API will autocalculate the number of chips if passed in 0 for numchips ***************** security issue ******** please dont use the GET URL method when dealing with passphrase!!! Those URL&#39;s tend to get logged and available in browser histories. so anything dealing with the actual passphrase needs to use the postCall form or POST
9 years ago
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,1,active[i]->bidasks,active[i]->numbids);
9 years ago
else if ( dir > 0 && active[i]->numasks > 0 )
many changes blockexplorer tab: needs to allow to input height, blockhash or txid. also please display images/BTC_blocks.jpg below the text as a w800 x h400 bitmap, which is active using the mouse api for coin management, below the active coins have a form that arbitrary json can be input with an add button to the right that will call &#34;addcoin&#34; API. this way I can test adding new coins dynamically. dont worry if it doesnt work, just as long as it submits the json to the C code. I am pretty sure I need to do some debugging of this peers management is not working for me at all. maybe it is due to bad internet. On initialization you need to read in the confs/BTCD_peers.txt from the native filesystem and save it into the chrome app filesystem. same thing for confs/BTCD_hdrs.txt. But this is only to be done if there isnt already such a file inside chrome. if there is, only do it upon a button invoked by the user. the reason is that the pexe is updating this file with the latest. Maybe it is nice to have an &#34;extract&#34; button that will copy out from the chrome storage into the native filesystem. There is also the manifest issue about localstorage vs chrome.localstorage. not sure what is needed to be done, but certainly a priority to get it so everything works as a chrome app. I know before it was making ramchain files inside the chrome filesystem, so it is probably things the GUI is doing. maybe in the settings tab, which has obsolete stuff that can be removed. anyway, the issue about files existing in the native filesystem -&gt; chrome and optionally extracting them is an issue for the confs files and .html template files used to autogenerate the port7778, maybe other files are affected. i think we need a way to have a list of hardcoded files that are just copied into chrome on startup if they dont exist already (or if possible copy over if the native version is bigger?) and buttons to extract them for debug tab: THREE_STRINGS(SuperNET,encryptjson,passphrase,permanentfile,anything); TWO_STRINGS(SuperNET,decryptjson,passphrase,permanentfile); at the top of page a way to put in passphrase and optional permanentfile along with arbitrary json. The standard form template has no easy way to describe to pass in everything as it is oriented to specific fields. but the encryptjson API saves all the fields, so the arbitrary json from the form needs to be combined at the same level as the &#34;agent&#34;, &#34;method&#34;, etc. I know, not the best, but internally it makes it easier. so {&#34;agent&#34;:&#34;SuperNET&#34;,&#34;method&#34;:&#34;encryptjson&#34;,&#34;passphrase&#34;:&#34;&lt;passphrase&gt;&#34;,&#34; permanentfile&#34;:&#34;&lt;filename&gt;&#34;,&#34;fromform&#34;:&#34;valuefromform&#34;,&#34;fromform2&#34;:&#34;valu efromform2&#34;,...rest of form at top level} then this will save it into a file with crazy number (it is a hash like txid) but given the same passphrase and filename, it will regenerate this hash so you dont actually have to store it, but it helps during debugging. for the filename, we must warn quite strongly to the user that if the file is ever lost or even changed in any way that the data will not be recoverable. also best to not allow the user to specify a file that does not exist. I think at this point chrome app version gets a bit tricky. we could simply push the native file into the chrome storage, but then an attacker who gets access to the computer could just get a list of these files and it really wont be much protection. So that means if a filename is specified, it needs to be copied into the chrome space, then immediately deleted... ok, this seems like not a good approach. let us make it so that the permanentfile option is not available from the chrome app, but only if the native version is running. that way we sidestep the issue of the pexe not having access to the specified file. Speaking of native vs pexe, on the startup page we should have a radio button that allows the user to select which the GUI will talk to. It should default based on a self test to the more likely value, but it is possible that the user wants to use the native version, even if the pexe is running. another thing to have on the startup page is a simple login: THREE_STRINGS(SuperNET,login,passphrase,permanentfile,handle); ZERO_ARGS(SuperNET,logout); ZERO_ARGS(SuperNET,activehandle); the handle is a human readable name that is associated with the passphrase/permanentfile. There can only be one active account (though it will be possible to associate different accounts with tradebots). use the activehandle API to find out who is logged in and the associated addresses and pubkeys The above is not yet tested so if it doesnt work, dont fret, just let me know. Once set the handle can be displayed in various places to let the user know which account is logged in. The standard 12 dictionary word passphrases should be used, but any string can be sent in as the password for Pangea: INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_ARG(pangea,start,tablehash); // by host only HASH_ARG(pangea,status,tablehash); HASH_ARG(pangea,call,tablehash); HASH_ARG(pangea,check,tablehash); HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_ARG(pangea,fold,tablehash); HASH_AND_STRING(pangea,mode,tablehash,modestr); HASH_ARG(pangea,history,tablehash); HASH_AND_INT(pangea,handhistory,tablehash,hand); The first thing that is done is a &#34;host&#34; by any node. the &#34;params&#34; should be an arbitrary json (like encryptjson) as it needs to be at the top level and it has quite a few different parameters still subject to change. The lobby API will just display all the hosted tables. once a table exists, players can join and then buyin. the buyin is denominated in chips, each chip&#39;s value is determined by the host&#39;s initial parameters. once there are enough players joined with adequate buyin&#39;s verified, the host will be able to do a start. if done before it will (eventually) give an error. for now it will just proceed. The host and players that have joined a tablehash, need to do regular status calls to see if the game has started. Probably just once per 5 or even 10 seconds is fine before the start. Once the game starts (the status will have this info) then once per second polling is needed. Then when it is your turn (as indicated by status) you need to do one of the 5 actions (fold, call, check, raise, bet). do not worry if you dont understand what all these do, just allow the user to do any of these. I guess it is possible to submit it ahead of time. I will support internally remembering the most recent action done prior to it being your turn. once it is your turn and an action is sent to the table, it is too late to change. The last API calls are for getting handhistory where hand is 0 to N-1, being the numbering of the hands played at that table. if just history, all the history for all hands at the table is coming back, so it could be quite big. probably I will make it a summary, but for the GUI just display the returned values. the mode is to change some poker specific modes, so just allow there to be a string entered. do not worry about understanding the pokerness of the API, just the overall flow: host -&gt; creates, join/buyin -&gt; fills up player slots, start -&gt; starts the game status -&gt; to determine when the game starts (or if it is cancelled) and once started actions -&gt; game specific but basically just (button + arg) that is the user input results are via status for current game and history for past ones please try to do the above logic in a generic way so it can be reused for other games. The basic flow should be the same for almost all multiplayer turn based games and even for multiplayer realtime games For InstantDEX: on the apikeypair/userid there needs to be two modes. one for when there is no stored apikey and the current form is fine, just need to make it wider as most apikeys are quite long. Now once there is an apikey saved all that is needed is the passphrase to unlock it. So here is where the encrptjson/decryptjson is used. When saving the apikey for the first time, it can be: a) not saved -&gt; nothing extra to do b) saved without password -&gt; you can just save to a file and use it to load it back in. use confs dir confs/instantdex.exchange.api or something like that c) saved with password (optional filename for native) -&gt; probably best to save in the confs dir to indicate that there is an encrypted file for this, so just that and not the actual passphrase in the file with the above, when the exchange is selected, you can see if the confs file exists and if it has the plaintext, just populate the field, if not, then indicate that a passphrase is needed. if the user provides the passphrase, then decryptjson and populate the fields and autosubmit. A special case is to encrypt the apikeys with the passphrase used when logging in. This is only available if the checkbox to &#34;remember passphrase during session&#34; is set on the main iguana login screen. (i forgot to mention that checkbox!) So the login passphrase is stored in memory, then the GUI simply uses that + encryptjson for storing/decrypting. I would imagine that storing in the confs file that it is encrypted using &#34;handle&#34;&#39;s account login might be a good way to differentiate between this mode of password usage. OK, so we now have the insecure plaintext, the decent using handle&#39;s passphrase and paranoid different passphrase for each exchange (with additional permanentfile for native versions) &#34;SUPPORT&#34; -&gt; &#34;SUPPORTS&#34; just a typo and &#34;allpairs&#34; API is missing from the selection Might as well add a &#34;tradebots&#34; tab: THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission); STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission); THREE_STRINGS(tradebot,unmonitor,exchange,base,rel); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,accumulate,exchange,base,rel,pr ice,volume,duration); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,divest,exchange,base,rel,price, volume,duration); STRING_ARG(tradebot,activebots,exchange); TWO_STRINGS(tradebot,status,exchange,botid); TWO_STRINGS(tradebot,pause,exchange,botid); TWO_STRINGS(tradebot,stop,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid); the above are API for exchange specific bots, most should be self-explanatory. bots are created via &#34;accumulate&#34; or &#34;divest&#34; API call. it returns botid. once created, you can do status, pause, stop, resume to a botid. and an activebots API call lists all the active bots for an exchange. duration is in seconds the &#34;monitor&#34; API starts background monitoring of a specific base/rel, &#34;unmonitor&#34; stops this. &#34;monitorall&#34; just does a monitor to the entire list of &#34;allpairs&#34; for that exchange. Keep in mind that doing a monitorall will not add load to an exchange as the request to each exchange is governed by pollgap, but if you have 3 things monitored, it will take 3*pollgap + time each one takes to execute. and if N are monitored it is N*pollgap + time of each, with the &#34;time of each&#34; possibly taking a very long time. And one final request for today: Bitmap tab. It should be an active bitmap using mouse api. either a dropdown to select the bitmap or a form entry. then the rest of the page (resize the bitmap to the page size) being the active bitmap. So on a small screen the bitmap is smaller x/y dimensions and larger on larger screens. plz make sure the proper dimensions are communicated to the pexe via API if it ever is changed. @vineet.bhargav86: I changed the &#34;passphrase&#34; fieldname to &#34;password&#34; for the encryptjson/decryptjson related API. The reason is that the password is like a wallet password and is only local, so it doesnt need to be as high entropy as passphrase. I also added a field to the login API as I realized that the 12 word &#34;passphrase&#34; is the payload and usually wont be sent in: FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase); using &#34;abiglongpassword&#34; for the passphrase -&gt; {&#34;pubkey&#34;:&#34;6c469ba10b40b3eb9d1dba569d7f929d55a29d8f97cd5425907ef2f38f906 209&#34;,&#34;RS&#34;:&#34;NXT-KGV9-DXX8-TM86-DXR96&#34;,&#34;NXT&#34;:&#34;12834974574569896807&#34;,&#34;btcpu bkey&#34;:&#34;024e7641dc947b211bc30fe3339765258902794687b227121fc217284f9d8503c 8&#34;,&#34;rmd160&#34;:&#34;33453c24914db7b77069b7ea24df44f6be145938&#34;,&#34;BTC&#34;:&#34;15g6QK2dSd iW9ZTQEnnJxKrSph6uP7uU23&#34;,&#34;BTCD&#34;:&#34;RDxHUpuv3TX5DZpbhxmS3rBeaxZW1fvYvC&#34;,&#34;r esult&#34;:&#34;success&#34;,&#34;handle&#34;:&#34;test&#34;,&#34;tag&#34;:&#34;14805226009240621255&#34;} and if you use that to log into NXT, it gives the same address. The BTC and BTCD addresses are all derived from the same privkey so they are all interchangeable with the NXT address. The user can therefore select which coin&#39;s addressing they are most comfortable with I also added an &#34;allin&#34; action API for pangea. all the action API will autocalculate the number of chips if passed in 0 for numchips ***************** security issue ******** please dont use the GET URL method when dealing with passphrase!!! Those URL&#39;s tend to get logged and available in browser histories. so anything dealing with the actual passphrase needs to use the postCall form or POST
9 years ago
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,-1,&active[i]->bidasks[1],active[i]->numasks);
}
9 years ago
//printf("dir.%d %s/%s numX.%d n.%d\n",dir,base,rel,num,n);
if ( dir < 0 )
revsort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
else sort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
9 years ago
for (totalvol=pricesum=i=0; i<n && totalvol < basevolume; i++)
9 years ago
{
9 years ago
quote = sortbuf[i];
//printf("n.%d i.%d price %.8f %.8f %.8f\n",n,i,dstr(sortbuf[i].satoshis),sortbuf[i].price,quote.volume);
if ( quote.satoshis != 0 )
9 years ago
{
9 years ago
pricesum += (quote.price * quote.volume);
totalvol += quote.volume;
9 years ago
printf("i.%d of %d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",i,n,sortbuf[i].price,quote.volume,active[quote.val]->exchange->name,pricesum/totalvol,totalvol);
9 years ago
}
}
if ( totalvol > 0. )
9 years ago
{
many changes blockexplorer tab: needs to allow to input height, blockhash or txid. also please display images/BTC_blocks.jpg below the text as a w800 x h400 bitmap, which is active using the mouse api for coin management, below the active coins have a form that arbitrary json can be input with an add button to the right that will call &#34;addcoin&#34; API. this way I can test adding new coins dynamically. dont worry if it doesnt work, just as long as it submits the json to the C code. I am pretty sure I need to do some debugging of this peers management is not working for me at all. maybe it is due to bad internet. On initialization you need to read in the confs/BTCD_peers.txt from the native filesystem and save it into the chrome app filesystem. same thing for confs/BTCD_hdrs.txt. But this is only to be done if there isnt already such a file inside chrome. if there is, only do it upon a button invoked by the user. the reason is that the pexe is updating this file with the latest. Maybe it is nice to have an &#34;extract&#34; button that will copy out from the chrome storage into the native filesystem. There is also the manifest issue about localstorage vs chrome.localstorage. not sure what is needed to be done, but certainly a priority to get it so everything works as a chrome app. I know before it was making ramchain files inside the chrome filesystem, so it is probably things the GUI is doing. maybe in the settings tab, which has obsolete stuff that can be removed. anyway, the issue about files existing in the native filesystem -&gt; chrome and optionally extracting them is an issue for the confs files and .html template files used to autogenerate the port7778, maybe other files are affected. i think we need a way to have a list of hardcoded files that are just copied into chrome on startup if they dont exist already (or if possible copy over if the native version is bigger?) and buttons to extract them for debug tab: THREE_STRINGS(SuperNET,encryptjson,passphrase,permanentfile,anything); TWO_STRINGS(SuperNET,decryptjson,passphrase,permanentfile); at the top of page a way to put in passphrase and optional permanentfile along with arbitrary json. The standard form template has no easy way to describe to pass in everything as it is oriented to specific fields. but the encryptjson API saves all the fields, so the arbitrary json from the form needs to be combined at the same level as the &#34;agent&#34;, &#34;method&#34;, etc. I know, not the best, but internally it makes it easier. so {&#34;agent&#34;:&#34;SuperNET&#34;,&#34;method&#34;:&#34;encryptjson&#34;,&#34;passphrase&#34;:&#34;&lt;passphrase&gt;&#34;,&#34; permanentfile&#34;:&#34;&lt;filename&gt;&#34;,&#34;fromform&#34;:&#34;valuefromform&#34;,&#34;fromform2&#34;:&#34;valu efromform2&#34;,...rest of form at top level} then this will save it into a file with crazy number (it is a hash like txid) but given the same passphrase and filename, it will regenerate this hash so you dont actually have to store it, but it helps during debugging. for the filename, we must warn quite strongly to the user that if the file is ever lost or even changed in any way that the data will not be recoverable. also best to not allow the user to specify a file that does not exist. I think at this point chrome app version gets a bit tricky. we could simply push the native file into the chrome storage, but then an attacker who gets access to the computer could just get a list of these files and it really wont be much protection. So that means if a filename is specified, it needs to be copied into the chrome space, then immediately deleted... ok, this seems like not a good approach. let us make it so that the permanentfile option is not available from the chrome app, but only if the native version is running. that way we sidestep the issue of the pexe not having access to the specified file. Speaking of native vs pexe, on the startup page we should have a radio button that allows the user to select which the GUI will talk to. It should default based on a self test to the more likely value, but it is possible that the user wants to use the native version, even if the pexe is running. another thing to have on the startup page is a simple login: THREE_STRINGS(SuperNET,login,passphrase,permanentfile,handle); ZERO_ARGS(SuperNET,logout); ZERO_ARGS(SuperNET,activehandle); the handle is a human readable name that is associated with the passphrase/permanentfile. There can only be one active account (though it will be possible to associate different accounts with tradebots). use the activehandle API to find out who is logged in and the associated addresses and pubkeys The above is not yet tested so if it doesnt work, dont fret, just let me know. Once set the handle can be displayed in various places to let the user know which account is logged in. The standard 12 dictionary word passphrases should be used, but any string can be sent in as the password for Pangea: INT_AND_ARRAY(pangea,host,minplayers,params); ZERO_ARGS(pangea,lobby); HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_ARG(pangea,start,tablehash); // by host only HASH_ARG(pangea,status,tablehash); HASH_ARG(pangea,call,tablehash); HASH_ARG(pangea,check,tablehash); HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_ARG(pangea,fold,tablehash); HASH_AND_STRING(pangea,mode,tablehash,modestr); HASH_ARG(pangea,history,tablehash); HASH_AND_INT(pangea,handhistory,tablehash,hand); The first thing that is done is a &#34;host&#34; by any node. the &#34;params&#34; should be an arbitrary json (like encryptjson) as it needs to be at the top level and it has quite a few different parameters still subject to change. The lobby API will just display all the hosted tables. once a table exists, players can join and then buyin. the buyin is denominated in chips, each chip&#39;s value is determined by the host&#39;s initial parameters. once there are enough players joined with adequate buyin&#39;s verified, the host will be able to do a start. if done before it will (eventually) give an error. for now it will just proceed. The host and players that have joined a tablehash, need to do regular status calls to see if the game has started. Probably just once per 5 or even 10 seconds is fine before the start. Once the game starts (the status will have this info) then once per second polling is needed. Then when it is your turn (as indicated by status) you need to do one of the 5 actions (fold, call, check, raise, bet). do not worry if you dont understand what all these do, just allow the user to do any of these. I guess it is possible to submit it ahead of time. I will support internally remembering the most recent action done prior to it being your turn. once it is your turn and an action is sent to the table, it is too late to change. The last API calls are for getting handhistory where hand is 0 to N-1, being the numbering of the hands played at that table. if just history, all the history for all hands at the table is coming back, so it could be quite big. probably I will make it a summary, but for the GUI just display the returned values. the mode is to change some poker specific modes, so just allow there to be a string entered. do not worry about understanding the pokerness of the API, just the overall flow: host -&gt; creates, join/buyin -&gt; fills up player slots, start -&gt; starts the game status -&gt; to determine when the game starts (or if it is cancelled) and once started actions -&gt; game specific but basically just (button + arg) that is the user input results are via status for current game and history for past ones please try to do the above logic in a generic way so it can be reused for other games. The basic flow should be the same for almost all multiplayer turn based games and even for multiplayer realtime games For InstantDEX: on the apikeypair/userid there needs to be two modes. one for when there is no stored apikey and the current form is fine, just need to make it wider as most apikeys are quite long. Now once there is an apikey saved all that is needed is the passphrase to unlock it. So here is where the encrptjson/decryptjson is used. When saving the apikey for the first time, it can be: a) not saved -&gt; nothing extra to do b) saved without password -&gt; you can just save to a file and use it to load it back in. use confs dir confs/instantdex.exchange.api or something like that c) saved with password (optional filename for native) -&gt; probably best to save in the confs dir to indicate that there is an encrypted file for this, so just that and not the actual passphrase in the file with the above, when the exchange is selected, you can see if the confs file exists and if it has the plaintext, just populate the field, if not, then indicate that a passphrase is needed. if the user provides the passphrase, then decryptjson and populate the fields and autosubmit. A special case is to encrypt the apikeys with the passphrase used when logging in. This is only available if the checkbox to &#34;remember passphrase during session&#34; is set on the main iguana login screen. (i forgot to mention that checkbox!) So the login passphrase is stored in memory, then the GUI simply uses that + encryptjson for storing/decrypting. I would imagine that storing in the confs file that it is encrypted using &#34;handle&#34;&#39;s account login might be a good way to differentiate between this mode of password usage. OK, so we now have the insecure plaintext, the decent using handle&#39;s passphrase and paranoid different passphrase for each exchange (with additional permanentfile for native versions) &#34;SUPPORT&#34; -&gt; &#34;SUPPORTS&#34; just a typo and &#34;allpairs&#34; API is missing from the selection Might as well add a &#34;tradebots&#34; tab: THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission); STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission); THREE_STRINGS(tradebot,unmonitor,exchange,base,rel); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,accumulate,exchange,base,rel,pr ice,volume,duration); THREE_STRINGS_AND_THREE_DOUBLES(tradebot,divest,exchange,base,rel,price, volume,duration); STRING_ARG(tradebot,activebots,exchange); TWO_STRINGS(tradebot,status,exchange,botid); TWO_STRINGS(tradebot,pause,exchange,botid); TWO_STRINGS(tradebot,stop,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid); the above are API for exchange specific bots, most should be self-explanatory. bots are created via &#34;accumulate&#34; or &#34;divest&#34; API call. it returns botid. once created, you can do status, pause, stop, resume to a botid. and an activebots API call lists all the active bots for an exchange. duration is in seconds the &#34;monitor&#34; API starts background monitoring of a specific base/rel, &#34;unmonitor&#34; stops this. &#34;monitorall&#34; just does a monitor to the entire list of &#34;allpairs&#34; for that exchange. Keep in mind that doing a monitorall will not add load to an exchange as the request to each exchange is governed by pollgap, but if you have 3 things monitored, it will take 3*pollgap + time each one takes to execute. and if N are monitored it is N*pollgap + time of each, with the &#34;time of each&#34; possibly taking a very long time. And one final request for today: Bitmap tab. It should be an active bitmap using mouse api. either a dropdown to select the bitmap or a form entry. then the rest of the page (resize the bitmap to the page size) being the active bitmap. So on a small screen the bitmap is smaller x/y dimensions and larger on larger screens. plz make sure the proper dimensions are communicated to the pexe via API if it ever is changed. @vineet.bhargav86: I changed the &#34;passphrase&#34; fieldname to &#34;password&#34; for the encryptjson/decryptjson related API. The reason is that the password is like a wallet password and is only local, so it doesnt need to be as high entropy as passphrase. I also added a field to the login API as I realized that the 12 word &#34;passphrase&#34; is the payload and usually wont be sent in: FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase); using &#34;abiglongpassword&#34; for the passphrase -&gt; {&#34;pubkey&#34;:&#34;6c469ba10b40b3eb9d1dba569d7f929d55a29d8f97cd5425907ef2f38f906 209&#34;,&#34;RS&#34;:&#34;NXT-KGV9-DXX8-TM86-DXR96&#34;,&#34;NXT&#34;:&#34;12834974574569896807&#34;,&#34;btcpu bkey&#34;:&#34;024e7641dc947b211bc30fe3339765258902794687b227121fc217284f9d8503c 8&#34;,&#34;rmd160&#34;:&#34;33453c24914db7b77069b7ea24df44f6be145938&#34;,&#34;BTC&#34;:&#34;15g6QK2dSd iW9ZTQEnnJxKrSph6uP7uU23&#34;,&#34;BTCD&#34;:&#34;RDxHUpuv3TX5DZpbhxmS3rBeaxZW1fvYvC&#34;,&#34;r esult&#34;:&#34;success&#34;,&#34;handle&#34;:&#34;test&#34;,&#34;tag&#34;:&#34;14805226009240621255&#34;} and if you use that to log into NXT, it gives the same address. The BTC and BTCD addresses are all derived from the same privkey so they are all interchangeable with the NXT address. The user can therefore select which coin&#39;s addressing they are most comfortable with I also added an &#34;allin&#34; action API for pangea. all the action API will autocalculate the number of chips if passed in 0 for numchips ***************** security issue ******** please dont use the GET URL method when dealing with passphrase!!! Those URL&#39;s tend to get logged and available in browser histories. so anything dealing with the actual passphrase needs to use the postCall form or POST
9 years ago
*totalvolp = totalvol;
9 years ago
return(pricesum / totalvol);
9 years ago
}
9 years ago
}
9 years ago
*totalvolp = 0;
9 years ago
return(0);
}
9 years ago
double instantdex_avehbla(struct supernet_info *myinfo,double retvals[4],char *base,char *rel,double basevolume)
{
double avebid,aveask,bidvol,askvol; struct exchange_quote sortbuf[256]; cJSON *argjson;
argjson = cJSON_CreateObject();
aveask = instantdex_aveprice(myinfo,sortbuf,sizeof(sortbuf)/sizeof(*sortbuf),&askvol,base,rel,basevolume,argjson);
avebid = instantdex_aveprice(myinfo,sortbuf,sizeof(sortbuf)/sizeof(*sortbuf),&bidvol,base,rel,-basevolume,argjson);
free_json(argjson);
retvals[0] = avebid, retvals[1] = bidvol, retvals[2] = aveask, retvals[3] = askvol;
if ( avebid > SMALLVAL && aveask > SMALLVAL )
return((avebid + aveask) * .5);
else return(0);
}
int32_t instantdex_bidaskdir(struct instantdex_offer *offer)
9 years ago
{
if ( offer->myside == 0 && offer->acceptdir > 0 ) // base
9 years ago
return(-1);
else if ( offer->myside == 1 && offer->acceptdir < 0 ) // rel
9 years ago
return(1);
9 years ago
else return(0);
}
9 years ago
cJSON *instantdex_offerjson(struct instantdex_offer *offer,uint64_t orderid)
9 years ago
{
int32_t dir; cJSON *item = cJSON_CreateObject();
9 years ago
jadd64bits(item,"orderid",orderid);
jadd64bits(item,"offerer",offer->offer64);
if ( (dir= instantdex_bidaskdir(offer)) > 0 )
9 years ago
jaddstr(item,"type","bid");
else if ( dir < 0 )
jaddstr(item,"type","ask");
else
{
jaddstr(item,"type","strange");
jaddnum(item,"acceptdir",offer->acceptdir);
jaddnum(item,"myside",offer->myside);
}
jaddstr(item,"base",offer->base);
jaddstr(item,"rel",offer->rel);
jaddnum(item,"timestamp",offer->expiration);
jaddnum(item,"price",dstr(offer->price64));
jaddnum(item,"volume",dstr(offer->basevolume64));
9 years ago
jaddnum(item,"minperc",offer->minperc);
jaddnum(item,"nonce",offer->nonce);
jaddnum(item,"expiresin",offer->expiration - time(NULL));
return(item);
}
cJSON *instantdex_acceptjson(struct instantdex_accept *ap)
{
cJSON *item = cJSON_CreateObject();
jadd64bits(item,"orderid",ap->orderid);
9 years ago
jaddnum(item,"pendingvolume",dstr(ap->pendingvolume64));
if ( ap->dead != 0 )
jadd64bits(item,"dead",ap->dead);
9 years ago
jadd(item,"offer",instantdex_offerjson(&ap->offer,ap->orderid));
9 years ago
return(item);
}
void instantdex_statetxjson(cJSON *array,char *name,struct bitcoin_statetx *tx)
{
cJSON *item;
if ( tx != 0 )
{
9 years ago
item = cJSON_CreateObject();
jaddbits256(item,"txid",tx->txid);
jaddnum(item,"inputsum",dstr(tx->inputsum));
jaddnum(item,"amount",dstr(tx->amount));
jaddnum(item,"change",dstr(tx->change));
jaddnum(item,"txfee",dstr(tx->inputsum) - dstr(tx->amount) - dstr(tx->change));
jaddnum(item,"confirms",dstr(tx->numconfirms));
jaddstr(item,"destaddr",tx->destaddr);
jaddstr(item,"txbytes",tx->txbytes);
jadd(array,name,item);
}
9 years ago
}
9 years ago
cJSON *instantdex_statemachinejson(struct bitcoin_swapinfo *swap)
{
9 years ago
cJSON *retjson,*txs; int32_t isbob,mydir,otherdir;
retjson = cJSON_CreateObject();
if ( swap != 0 )
{
9 years ago
mydir = instantdex_bidaskdir(&swap->mine.offer);
otherdir = instantdex_bidaskdir(&swap->other.offer);
isbob = instantdex_isbob(swap);
jaddnum(retjson,"isbob",isbob);
jaddnum(retjson,"mydir",mydir);
jaddnum(retjson,"otherdir",otherdir);
jaddnum(retjson,"expiration",swap->expiration);
jaddnum(retjson,"insurance",dstr(swap->insurance));
jaddnum(retjson,"baseamount",dstr(swap->altsatoshis));
jaddnum(retjson,"BTCamount",dstr(swap->BTCsatoshis));
jaddnum(retjson,"expiration",swap->expiration);
if ( swap->dead != 0 )
jadd64bits(retjson,"dead",swap->dead);
jaddbits256(retjson,"privAm",swap->privAm);
jaddbits256(retjson,"pubAm",swap->pubAm);
jaddbits256(retjson,"privBn",swap->privBn);
jaddbits256(retjson,"pubBn",swap->pubBn);
9 years ago
jaddbits256(retjson,"myorderhash",swap->myorderhash);
jaddnum(retjson,"choosei",swap->choosei);
jaddnum(retjson,"cutverified",swap->cutverified);
jaddbits256(retjson,"othertrader",swap->othertrader);
9 years ago
jaddbits256(retjson,"otherorderhash",swap->otherorderhash);
jaddnum(retjson,"otherchoosei",swap->otherchoosei);
jaddnum(retjson,"otherverifiedcut",swap->otherverifiedcut);
if ( isbob == 0 )
{
jaddbits256(retjson,"pubA0",swap->mypubs[0]);
jaddbits256(retjson,"pubA1",swap->mypubs[1]);
jaddbits256(retjson,"pubB0",swap->otherpubs[0]);
jaddbits256(retjson,"pubB1",swap->otherpubs[1]);
}
else
{
jaddbits256(retjson,"pubB0",swap->mypubs[0]);
jaddbits256(retjson,"pubB1",swap->mypubs[1]);
jaddbits256(retjson,"pubA0",swap->otherpubs[0]);
jaddbits256(retjson,"pubA1",swap->otherpubs[1]);
}
9 years ago
if ( mydir > 0 && otherdir < 0 )
{
jadd64bits(retjson,"bidid",swap->mine.orderid);
jadd64bits(retjson,"askid",swap->other.orderid);
}
else if ( mydir < 0 && otherdir > 0 )
{
jadd64bits(retjson,"askid",swap->mine.orderid);
jadd64bits(retjson,"bidid",swap->other.orderid);
}
if ( swap->matched64 == swap->mine.orderid )
{
jadd(retjson,"initiator",instantdex_acceptjson(&swap->other));
jadd(retjson,"matched",instantdex_acceptjson(&swap->mine));
}
else if ( swap->matched64 == swap->other.orderid )
{
jadd(retjson,"initiator",instantdex_acceptjson(&swap->mine));
jadd(retjson,"matched",instantdex_acceptjson(&swap->other));
}
else jaddstr(retjson,"initiator","illegal initiator missing");
if ( swap->state != 0 )
jaddstr(retjson,"state",swap->state->name);
txs = cJSON_CreateObject();
9 years ago
instantdex_statetxjson(txs,"deposit",swap->deposit);
instantdex_statetxjson(txs,"payment",swap->payment);
instantdex_statetxjson(txs,"altpayment",swap->altpayment);
instantdex_statetxjson(txs,"myfee",swap->myfee);
instantdex_statetxjson(txs,"otherfee",swap->otherfee);
jadd(retjson,"txs",txs);
jaddstr(retjson,"status",swap->status);
}
return(retjson);
}
9 years ago
cJSON *instantdex_historyjson(struct bitcoin_swapinfo *swap)
{
// need to make sure accepts are put onto history queue when they are completed or deaded
// also to make permanent copy (somewhere)
9 years ago
return(instantdex_statemachinejson(swap));
}
9 years ago
struct bitcoin_swapinfo *instantdex_historyfind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid)
{
9 years ago
struct bitcoin_swapinfo PAD,*swap,*retswap = 0; uint32_t now;
now = (uint32_t)time(NULL);
memset(&PAD,0,sizeof(PAD));
queue_enqueue("historyQ",&exchange->historyQ,&PAD.DL,0);
9 years ago
while ( (swap= queue_dequeue(&exchange->historyQ,0)) != 0 && swap != &PAD )
{
9 years ago
if ( orderid == swap->mine.orderid )
retswap = swap;
queue_enqueue("historyQ",&exchange->historyQ,&swap->DL,0);
}
9 years ago
return(retswap);
}
9 years ago
struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid,int32_t requeueflag)
9 years ago
{
9 years ago
struct bitcoin_swapinfo PAD,*swap,*retswap = 0; uint32_t now;
9 years ago
now = (uint32_t)time(NULL);
memset(&PAD,0,sizeof(PAD));
9 years ago
queue_enqueue("statemachineQ",&exchange->statemachineQ,&PAD.DL,0);
9 years ago
while ( (swap= queue_dequeue(&exchange->statemachineQ,0)) != 0 && swap != &PAD )
9 years ago
{
9 years ago
if ( now < swap->expiration && swap->mine.dead == 0 && swap->other.dead == 0 )
9 years ago
{
9 years ago
if ( orderid == swap->mine.orderid || orderid == swap->other.orderid )
9 years ago
{
9 years ago
if ( retswap != 0 && requeueflag == 0 )
queue_enqueue("statemachineQ",&exchange->statemachineQ,&retswap->DL,0);
retswap = swap;
9 years ago
}
9 years ago
}
else
{
9 years ago
strcpy(swap->status,"expired");
9 years ago
printf("expired pending, need to take action, send timeout event\n");
9 years ago
queue_enqueue("historyQ",&exchange->historyQ,&swap->DL,0);
9 years ago
continue;
9 years ago
}
9 years ago
if ( swap != retswap || requeueflag != 0 )
queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0);
9 years ago
}
9 years ago
//printf("found statemachine.%p\n",retswap);
9 years ago
return(retswap);
9 years ago
}
struct instantdex_accept *instantdex_offerfind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t requeue)
9 years ago
{
9 years ago
struct instantdex_accept PAD,*ap,*retap = 0; uint32_t now; cJSON *item,*offerobj; char *type;
9 years ago
now = (uint32_t)time(NULL);
memset(&PAD,0,sizeof(PAD));
9 years ago
queue_enqueue("acceptableQ",&exchange->acceptableQ,&PAD.DL,0);
while ( (ap= queue_dequeue(&exchange->acceptableQ,0)) != 0 && ap != &PAD )
9 years ago
{
9 years ago
if ( now < ap->offer.expiration && ap->dead == 0 )
9 years ago
{
9 years ago
//printf("%d %d find cmps %d %d %d %d %d %d me.%llu vs %llu o.%llu | vs %llu\n",instantdex_bidaskdir(&ap->offer),ap->offer.expiration-now,strcmp(base,"*") == 0,strcmp(base,ap->offer.base) == 0,strcmp(rel,"*") == 0,strcmp(rel,ap->offer.rel) == 0,orderid == 0,orderid == ap->orderid,(long long)myinfo->myaddr.nxt64bits,(long long)ap->offer.offer64,(long long)ap->orderid,(long long)orderid);
9 years ago
if ( (strcmp(base,"*") == 0 || strcmp(base,ap->offer.base) == 0) && (strcmp(rel,"*") == 0 || strcmp(rel,ap->offer.rel) == 0) && (orderid == 0 || orderid == ap->orderid) )
9 years ago
{
9 years ago
if ( requeue == 0 && retap != 0 )
queue_enqueue("acceptableQ",&exchange->acceptableQ,&retap->DL,0);
9 years ago
retap = ap;
}
9 years ago
if ( (item= instantdex_acceptjson(ap)) != 0 )
{
9 years ago
//printf("item.(%s)\n",jprint(item,0));
9 years ago
if ( (offerobj= jobj(item,"offer")) != 0 && (type= jstr(offerobj,"type")) != 0 )
9 years ago
{
if ( strcmp(type,"bid") == 0 && bids != 0 )
9 years ago
jaddi(bids,jduplicate(offerobj));
9 years ago
else if ( strcmp(type,"ask") == 0 && asks != 0 )
9 years ago
jaddi(asks,jduplicate(offerobj));
9 years ago
}
9 years ago
free_json(item);
} else printf("error generating acceptjson.%llu\n",(long long)ap->orderid);
9 years ago
if ( ap != retap || requeue != 0 )
{
9 years ago
//printf("requeue.%p\n",ap);
9 years ago
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
}
9 years ago
} else free(ap);
}
return(retap);
}
9 years ago
struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,double minperc)
9 years ago
{
9 years ago
struct instantdex_accept PAD,*ap,*retap = 0; double aveprice;//,retvals[4];
9 years ago
uint64_t minvol,bestprice64 = 0; uint32_t now; int32_t offerdir;
9 years ago
aveprice = 0;//instantdex_avehbla(myinfo,retvals,A->offer.base,A->offer.rel,dstr(A->offer.basevolume64));
9 years ago
now = (uint32_t)time(NULL);
memset(&PAD,0,sizeof(PAD));
queue_enqueue("acceptableQ",&exchange->acceptableQ,&PAD.DL,0);
offerdir = instantdex_bidaskdir(&A->offer);
9 years ago
minvol = (A->offer.basevolume64 * minperc * .01);
printf("offerdir.%d (%s/%s) minperc %.3f minvol %.8f vs %.8f\n",offerdir,A->offer.base,A->offer.rel,minperc,dstr(minvol),dstr(A->offer.basevolume64));
9 years ago
while ( (ap= queue_dequeue(&exchange->acceptableQ,0)) != 0 && ap != &PAD )
{
9 years ago
if ( now > ap->offer.expiration || ap->dead != 0 || A->offer.offer64 == ap->offer.offer64 )
9 years ago
{
9 years ago
//printf("now.%u skip expired %u/dead.%u or my order orderid.%llu from %llu\n",now,ap->offer.expiration,ap->dead,(long long)ap->orderid,(long long)ap->offer.offer64);
9 years ago
}
else if ( strcmp(ap->offer.base,A->offer.base) != 0 || strcmp(ap->offer.rel,A->offer.rel) != 0 )
{
9 years ago
//printf("skip mismatched.(%s/%s) orderid.%llu from %llu\n",ap->offer.base,ap->offer.rel,(long long)ap->orderid,(long long)ap->offer.offer64);
9 years ago
}
else if ( offerdir*instantdex_bidaskdir(&ap->offer) > 0 )
{
9 years ago
//printf("skip same direction %d orderid.%llu from %llu\n",instantdex_bidaskdir(&ap->offer),(long long)ap->orderid,(long long)ap->offer.offer64);
9 years ago
}
else if ( minvol > ap->offer.basevolume64 - ap->pendingvolume64 )
{
9 years ago
//printf("skip too small order %.8f vs %.8f orderid.%llu from %llu\n",dstr(minvol),dstr(ap->offer.basevolume64)-dstr(ap->pendingvolume64),(long long)ap->orderid,(long long)ap->offer.offer64);
9 years ago
}
else if ( (offerdir > 0 && ap->offer.price64 > A->offer.price64) || (offerdir < 0 && ap->offer.price64 < A->offer.price64) )
{
9 years ago
//printf("skip out of band dir.%d offer %.8f vs %.8f orderid.%llu from %llu\n",offerdir,dstr(ap->offer.price64),dstr(A->offer.price64),(long long)ap->orderid,(long long)ap->offer.offer64);
9 years ago
}
else
{
if ( bestprice64 == 0 || (offerdir > 0 && ap->offer.price64 < bestprice64) || (offerdir < 0 && ap->offer.price64 > bestprice64) )
9 years ago
{
9 years ago
printf(">>>> MATCHED better price dir.%d offer %.8f vs %.8f orderid.%llu from %llu\n",offerdir,dstr(ap->offer.price64),dstr(A->offer.price64),(long long)ap->orderid,(long long)ap->offer.offer64);
9 years ago
bestprice64 = ap->offer.price64;
if ( retap != 0 )
queue_enqueue("acceptableQ",&exchange->acceptableQ,&retap->DL,0);
retap = ap;
9 years ago
}
9 years ago
}
if ( ap != retap )
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
else free(ap);
9 years ago
}
9 years ago
return(retap);
9 years ago
}
9 years ago
// NXTrequest:
// sends NXT assetid, volume and desired
// request:
// other node sends (othercoin, othercoinaddr, otherNXT and reftx that expires well before phasedtx)
// proposal:
// NXT node submits phasedtx that refers to it, but it wont confirm
// approve:
// other node verifies unconfirmed has phasedtx and broadcasts cltv, also to NXT node, releases trigger
// confirm:
// NXT node verifies bitcoin txbytes has proper payment and cashes in with onetimepubkey
// BTC* node approves phased tx with onetimepubkey
9 years ago
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,uint8_t minperc)
9 years ago
{
bits256 hash;
memset(ap,0,sizeof(*ap));
9 years ago
safecopy(ap->offer.base,base,sizeof(ap->offer.base));
safecopy(ap->offer.rel,rel,sizeof(ap->offer.rel));
9 years ago
if ( nonce == 0 )
OS_randombytes((uint8_t *)&ap->offer.nonce,sizeof(ap->offer.nonce));
else ap->offer.nonce = nonce;
9 years ago
if ( duration < 1000000000 )
9 years ago
ap->offer.expiration = (uint32_t)time(NULL) + duration;
else ap->offer.expiration = duration;
ap->offer.offer64 = offerbits;
ap->offer.myside = myside;
ap->offer.acceptdir = acceptdir;
9 years ago
ap->offer.minperc = minperc;
9 years ago
ap->offer.price64 = price * SATOSHIDEN;
ap->offer.basevolume64 = volume * SATOSHIDEN;
vcalc_sha256(0,hash.bytes,(void *)&ap->offer,sizeof(ap->offer));
9 years ago
ap->orderid = hash.txid;
9 years ago
//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);
9 years ago
return(hash);
}
9 years ago
int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson)
{
9 years ago
char *base,*rel; bits256 hash,traderpub; double price,volume; int32_t baserel,acceptdir,minperc;
9 years ago
memset(ap,0,sizeof(*ap));
if ( (base= jstr(argjson,"base")) != 0 )
{
volume = jdouble(argjson,"volume");
9 years ago
if ( (minperc= juint(argjson,"minperc")) < INSTANTDEX_MINPERC )
minperc = INSTANTDEX_MINPERC;
else if ( minperc > 100 )
minperc = 100;
9 years ago
if ( (rel= jstr(argjson,"rel")) != 0 )
9 years ago
safecopy(ap->offer.rel,rel,sizeof(ap->offer.rel));
9 years ago
if ( (price= jdouble(argjson,"maxprice")) > SMALLVAL )
{
baserel = 1;
acceptdir = -1;
}
else if ( (price= jdouble(argjson,"minprice")) > SMALLVAL )
{
baserel = 0;
acceptdir = 1;
} else return(-1);
//printf("price %f vol %f baserel.%d acceptdir.%d\n",price,volume,baserel,acceptdir);
traderpub = jbits256(argjson,"traderpub");
9 years ago
hash = instantdex_acceptset(ap,base,rel,INSTANTDEX_LOCKTIME*2,baserel,acceptdir,price,volume,traderpub.txid,0,minperc);
9 years ago
}
else
{
if ( (base= jstr(argjson,"b")) != 0 )
9 years ago
safecopy(ap->offer.base,base,sizeof(ap->offer.base));
9 years ago
if ( (rel= jstr(argjson,"r")) != 0 )
9 years ago
safecopy(ap->offer.rel,rel,sizeof(ap->offer.rel));
ap->offer.nonce = juint(argjson,"n");
ap->offer.expiration = juint(argjson,"e");
ap->offer.myside = juint(argjson,"s");
ap->offer.acceptdir = jint(argjson,"d");
ap->offer.offer64 = j64bits(argjson,"o");
ap->offer.price64 = j64bits(argjson,"p");
ap->offer.basevolume64 = j64bits(argjson,"v");
9 years ago
if ( (ap->offer.minperc= juint(argjson,"m")) < INSTANTDEX_MINPERC )
ap->offer.minperc = INSTANTDEX_MINPERC;
9 years ago
vcalc_sha256(0,hash.bytes,(void *)&ap->offer,sizeof(ap->offer));
9 years ago
ap->orderid = j64bits(argjson,"id");
}
if ( hash.txid != ap->orderid )
{
int32_t i;
for (i=0; i<sizeof(*ap); i++)
printf("%02x ",((uint8_t *)ap)[i]);
printf("instantdex_acceptextract warning %llu != %llu\n",(long long)hash.txid,(long long)ap->orderid);
return(-1);
}
return(0);
}
9 years ago
#include "swaps/iguana_BTCswap.c"
#include "swaps/iguana_ALTswap.c"
#include "swaps/iguana_NXTswap.c"
#include "swaps/iguana_PAXswap.c"
9 years ago
struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *myap,struct instantdex_accept *otherap,int32_t aminitiator,cJSON *argjson,char *statename)
9 years ago
{
9 years ago
struct bitcoin_swapinfo *swap = 0; struct iguana_info *coinbtc,*altcoin;
swap = calloc(1,sizeof(struct bitcoin_swapinfo));
9 years ago
swap->state = instantdex_statefind(BTC_states,BTC_numstates,statename);
9 years ago
swap->mine = *myap, swap->other = *otherap;
if ( (swap->isinitiator= aminitiator) != 0 )
9 years ago
{
9 years ago
swap->matched64 = otherap->orderid;
swap->expiration = otherap->offer.expiration;
9 years ago
}
else
{
9 years ago
swap->matched64 = myap->orderid;
swap->expiration = myap->offer.expiration;
9 years ago
}
9 years ago
swap->choosei = swap->otherchoosei = -1;
strcpy(swap->status,"pending");
vcalc_sha256(0,swap->myorderhash.bytes,(void *)&swap->mine.offer,sizeof(swap->mine.offer));
vcalc_sha256(0,swap->otherorderhash.bytes,(void *)&swap->other.offer,sizeof(swap->other.offer));
swap->mypubkey = myinfo->myaddr.persistent;
swap->othertrader = jbits256(argjson,"traderpub");
swap->altsatoshis = myap->offer.basevolume64;
swap->BTCsatoshis = instantdex_BTCsatoshis(myap->offer.price64,myap->offer.basevolume64);
if ( (coinbtc= iguana_coinfind("BTC")) == 0 || (altcoin= iguana_coinfind(swap->mine.offer.base)) == 0 )
9 years ago
{
9 years ago
printf("cant find BTC or %s\n",swap->mine.offer.base);
return(0);
9 years ago
}
9 years ago
swap->insurance = (swap->BTCsatoshis * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee);
swap->altpremium = (swap->altsatoshis * INSTANTDEX_INSURANCERATE + altcoin->chain->txfee);
if ( myap->offer.myside != instantdex_isbob(swap) || otherap->offer.myside == instantdex_isbob(swap) )
9 years ago
{
9 years ago
printf("isbob error.(%d %d) %d\n",myap->offer.myside,otherap->offer.myside,instantdex_isbob(swap));
return(0);
9 years ago
}
9 years ago
return(swap);
9 years ago
}
9 years ago
char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *myap,cJSON *argjson)
9 years ago
{
9 years ago
char *retstr = 0; struct instantdex_accept *otherap; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0;
9 years ago
*txidp = myap->orderid;
if ( (otherap= instantdex_acceptable(myinfo,exchange,myap,myap->offer.minperc)) == 0 )
9 years ago
{
9 years ago
printf("add.%llu to acceptableQ\n",(long long)myap->orderid);
if ( (retstr= instantdex_sendcmd(myinfo,&myap->offer,argjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,0,0)) != 0 )
free(retstr);
queue_enqueue("acceptableQ",&exchange->acceptableQ,&myap->DL,0);
return(jprint(instantdex_offerjson(&myap->offer,myap->orderid),1));
9 years ago
}
9 years ago
else
9 years ago
{
9 years ago
isbob = myap->offer.myside;
swap = bitcoin_swapinit(myinfo,exchange,myap,otherap,1,argjson,isbob != 0 ? "BOB_sentoffer" : "ALICE_sentoffer");
9 years ago
printf("STATEMACHINEQ.(%llu / %llu)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid);
9 years ago
queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0);
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 )
return(clonestr("{\"error\":\"instantdex_checkoffer null newjson\"}"));
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
9 years ago
}
9 years ago
return(retstr);
9 years ago
}
9 years ago
char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *myap,struct instantdex_accept *otherap,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *serdata,int32_t serdatalen) // receiving side
9 years ago
{
9 years ago
struct bitcoin_swapinfo *swap = 0; bits256 traderpub; struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; char *retstr=0; int32_t isbob;
9 years ago
coinbtc = iguana_coinfind("BTC");
traderpub = jbits256(argjson,"traderpub");
if ( bits256_cmp(traderpub,myinfo->myaddr.persistent) == 0 )
{
9 years ago
printf("got my own gotoffer packet orderid.%llu/%llu\n",(long long)myap->orderid,(long long)otherap->orderid);
9 years ago
return(clonestr("{\"result\":\"got my own packet\"}"));
}
9 years ago
if ( 0 )
9 years ago
{
int32_t i;
9 years ago
for (i=0; i<sizeof(otherap->offer); i++)
printf("%02x ",((uint8_t *)&otherap->offer)[i]);
printf("gotoffer.%llu\n",(long long)otherap->orderid);
9 years ago
}
9 years ago
printf(">>>>>>>>> GOTOFFER T.%d got (%s/%s) %.8f vol %.8f %llu offerside.%d offerdir.%d decksize.%ld/datalen.%d\n",bits256_cmp(traderpub,myinfo->myaddr.persistent),myap->offer.base,myap->offer.rel,dstr(myap->offer.price64),dstr(myap->offer.basevolume64),(long long)myap->orderid,myap->offer.myside,myap->offer.acceptdir,sizeof(swap->deck),serdatalen);
9 years ago
if ( exchange == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap null exchange ptr\"}"));
9 years ago
if ( (altcoin= iguana_coinfind(myap->offer.base)) == 0 || coinbtc == 0 )
9 years ago
return(clonestr("{\"error\":\"instantdex_BTCswap cant find btc or other coin info\"}"));
9 years ago
if ( strcmp(myap->offer.rel,"BTC") != 0 )
9 years ago
return(clonestr("{\"error\":\"instantdex_BTCswap offer non BTC rel\"}"));
9 years ago
if ( myap->offer.expiration < (time(NULL) + INSTANTDEX_DURATION) || otherap->offer.expiration < (time(NULL) + INSTANTDEX_DURATION) )
9 years ago
return(clonestr("{\"error\":\"instantdex_BTCswap offer too close to expiration\"}"));
9 years ago
isbob = myap->offer.myside;
swap = bitcoin_swapinit(myinfo,exchange,myap,otherap,0,argjson,isbob != 0 ? "BOB_sentoffer" : "ALICE_sentoffer");
9 years ago
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 )
9 years ago
{
printf("error parsing argjson\n");
9 years ago
return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}"));
9 years ago
}
9 years ago
else //if ( (retstr= instantdex_addfeetx(myinfo,newjson,ap,swap,"BOB_gotoffer","ALICE_gotoffer")) == 0 )
9 years ago
{
9 years ago
queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0);
9 years ago
if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 )
9 years ago
return(retstr);
9 years ago
else
9 years ago
{
9 years ago
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCdeckC",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
9 years ago
}
9 years ago
}
9 years ago
return(retstr);
}
9 years ago
char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,struct instantdex_offer *offer,bits256 orderhash,uint8_t *serdata,int32_t serdatalen)
9 years ago
{
9 years ago
char cmdstr[16],*retstr; struct exchange_info *exchange; struct instantdex_accept A,*ap = 0; bits256 traderpub; cJSON *newjson; struct bitcoin_swapinfo *swap;
9 years ago
if ( BTC_states == 0 )
BTC_states = BTC_initFSM(&BTC_numstates);
9 years ago
exchange = exchanges777_find("bitcoin");
9 years ago
memset(cmdstr,0,sizeof(cmdstr)), memcpy(cmdstr,msg->cmd,sizeof(msg->cmd));
if ( argjson != 0 )
{
9 years ago
traderpub = jbits256(argjson,"traderpub");
9 years ago
memset(&A,0,sizeof(A));
9 years ago
if ( j64bits(argjson,"id") != orderhash.txid )
{
printf("orderhash %llu mismatch id.%llu\n",(long long)orderhash.txid,(long long)j64bits(argjson,"id"));
return(clonestr("{\"error\":\"orderhash mismatch\"}"));
}
9 years ago
A.offer = *offer;
9 years ago
A.orderid = orderhash.txid;
9 years ago
printf("got.(%s) for %llu offer64.%llu\n",cmdstr,(long long)A.orderid,(long long)A.offer.offer64);
9 years ago
if ( (A.offer.minperc= jdouble(argjson,"p")) < INSTANTDEX_MINPERC )
A.offer.minperc = INSTANTDEX_MINPERC;
else if ( A.offer.minperc > 100 )
A.offer.minperc = 100;
if ( strcmp(cmdstr,"BTCoffer") == 0 ) // incoming
9 years ago
{
9 years ago
printf("BTCoffer state\n");
9 years ago
if ( (ap= instantdex_acceptable(myinfo,exchange,&A,A.offer.minperc)) != 0 )
9 years ago
{
9 years ago
if ( (retstr= instantdex_gotoffer(myinfo,exchange,ap,&A,msg,argjson,remoteaddr,signerbits,serdata,serdatalen)) != 0 ) // adds to statemachine if no error
9 years ago
{
9 years ago
printf("from GOTOFFER.(%s)\n",retstr);
return(retstr);
} else return(clonestr("{\"error\":\"gotoffer error\"}"));
9 years ago
}
else
{
9 years ago
printf("no matching trade for %s %llu -> InstantDEX_minaccept isbob.%d\n",cmdstr,(long long)A.orderid,A.offer.myside);
9 years ago
if ( instantdex_offerfind(myinfo,exchange,0,0,A.orderid,"*","*",1) == 0 )
{
ap = calloc(1,sizeof(*ap));
*ap = A;
9 years ago
printf("acceptableQ <- %llu\n",(long long)ap->orderid);
9 years ago
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
return(clonestr("{\"result\":\"added new order to orderbook\"}"));
} else return(clonestr("{\"result\":\"order was already in orderbook\"}"));
}
9 years ago
}
9 years ago
else if ( (swap= instantdex_statemachinefind(myinfo,exchange,A.orderid,1)) != 0 )
9 years ago
{
9 years ago
//printf("found existing state machine %llu\n",(long long)A.orderid);
9 years ago
newjson = instantdex_parseargjson(myinfo,exchange,swap,argjson,0);
9 years ago
if ( serdatalen == sizeof(swap->otherdeck) && swap->choosei < 0 && (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 )
{
printf("error choosei\n");
return(retstr);
}
9 years ago
return(instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,cmdstr,argjson,newjson,serdata,serdatalen));
9 years ago
}
9 years ago
else
9 years ago
{
9 years ago
printf("cant find existing order.%llu that matches\n",(long long)A.orderid);
return(clonestr("{\"error\":\"cant find matching order\"}"));
9 years ago
}
9 years ago
}
9 years ago
return(clonestr("{\"error\":\"request needs argjson\"}"));
9 years ago
}
char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char *remoteaddr)
{
9 years ago
struct instantdex_msghdr *msg = ptr; int32_t i,olen,slen,num,datalen,newlen,flag = 0;
uint8_t *serdata; struct supernet_info *myinfos[64]; struct instantdex_offer rawoffer;
9 years ago
uint64_t signerbits; uint8_t tmp[sizeof(msg->sig)]; char *retstr = 0;
bits256 orderhash,traderpub; cJSON *retjson,*item,*argjson = 0;
9 years ago
if ( BTC_states == 0 )
BTC_states = BTC_initFSM(&BTC_numstates);
9 years ago
datalen = len - (int32_t)sizeof(msg->sig);
9 years ago
serdata = (void *)((long)msg + sizeof(msg->sig));
9 years ago
//printf("a signed datalen.%d allocsize.%d crc.%x\n",datalen,msg->sig.allocsize,calc_crc32(0,serdata,datalen));
9 years ago
acct777_rwsig(0,(void *)&msg->sig,(void *)tmp);
memcpy(&msg->sig,tmp,sizeof(msg->sig));
9 years ago
// printf("b signed datalen.%d allocsize.%d crc.%x\n",datalen,msg->sig.allocsize,calc_crc32(0,serdata,datalen));
9 years ago
if ( remoteaddr != 0 && remoteaddr[0] == 0 && strcmp("127.0.0.1",remoteaddr) == 0 && ((uint8_t *)msg)[len-1] == 0 && (argjson= cJSON_Parse((char *)msg)) != 0 )
{
9 years ago
printf("string instantdex_hexmsg RESULT.(%s)\n",jprint(argjson,0));
9 years ago
free_json(argjson);
9 years ago
return(clonestr("{\"error\":\"string base packets deprecated\"}"));
9 years ago
}
9 years ago
else if ( (signerbits= acct777_validate(&msg->sig,acct777_msgprivkey(serdata,datalen),msg->sig.pubkey)) != 0 || 1 )
9 years ago
{
flag++;
9 years ago
//printf("InstantDEX_hexmsg <<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(msg->sig),(long)serdata-(long)msg,datalen,msg->sig.timestamp,msg->sig.allocsize,(char *)msg->serialized,serdata[datalen-1]);
9 years ago
newlen = (int32_t)(msg->sig.allocsize - ((long)msg->serialized - (long)msg));
9 years ago
serdata = msg->serialized;
9 years ago
//printf("newlen.%d diff.%ld alloc.%d datalen.%d\n",newlen,((long)msg->serialized - (long)msg),msg->sig.allocsize,datalen);
9 years ago
if ( (argjson= cJSON_Parse((char *)serdata)) != 0 )
9 years ago
{
9 years ago
slen = (int32_t)strlen((char *)serdata) + 1;
serdata = &serdata[slen];
9 years ago
newlen -= slen;
9 years ago
}
9 years ago
if ( newlen > 0 )
9 years ago
{
9 years ago
orderhash = instantdex_rwoffer(0,&olen,serdata,&rawoffer);
9 years ago
newlen -= olen;
9 years ago
//newlen -= ((long)msg->serialized - (long)msg);
9 years ago
serdata = &serdata[olen];
9 years ago
//printf("received orderhash.%llu olen.%d slen.%d newlen.%d\n",(long long)orderhash.txid,olen,slen,newlen);
9 years ago
} else olen = 0;
9 years ago
if ( newlen <= 0 )
9 years ago
serdata = 0, newlen = 0;
if ( serdata != 0 || argjson != 0 )
9 years ago
{
9 years ago
//printf("CALL instantdex_parse.(%s)\n",argjson!=0?jprint(argjson,0):"");
9 years ago
retjson = cJSON_CreateArray();
if ( (num= SuperNET_MYINFOS(myinfos,sizeof(myinfos)/sizeof(*myinfos))) == 0 )
{
myinfos[0] = myinfo;
num = 1;
}
for (i=0; i<num; i++)
{
myinfo = myinfos[i];
//char str[65]; printf("i.%d of %d: %s\n",i,num,bits256_str(str,myinfo->myaddr.persistent));
9 years ago
traderpub = jbits256(argjson,"traderpub");
if ( bits256_cmp(traderpub,myinfo->myaddr.persistent) == 0 )
continue;
9 years ago
if ( (retstr= instantdex_parse(myinfo,msg,argjson,remoteaddr,signerbits,&rawoffer,orderhash,serdata,newlen)) != 0 )
9 years ago
{
item = cJSON_CreateObject();
jaddstr(item,"result",retstr);
if ( myinfo->handle[0] != 0 )
jaddstr(item,"handle",myinfo->handle);
jaddbits256(item,"traderpub",myinfo->myaddr.persistent);
jaddi(retjson,item);
}
}
retstr = jprint(retjson,1);
9 years ago
}
9 years ago
} else printf("sig err datalen.%d\n",datalen);
9 years ago
if ( argjson != 0 )
free_json(argjson);
return(retstr);
}
9 years ago
char *instantdex_createaccept(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,int32_t queueflag,uint8_t minperc)
9 years ago
{
9 years ago
struct instantdex_accept *ap; int32_t myside; char *retstr;
*aptrp = 0;
9 years ago
if ( exchange != 0 )
{
9 years ago
*aptrp = ap = calloc(1,sizeof(*ap));
9 years ago
if ( strcmp(mysidestr,base) == 0 )
myside = 0;
else if ( strcmp(mysidestr,rel) == 0 )
myside = 1;
9 years ago
else
{
myside = -1;
printf("myside.(%s) != base.%s or rel.%s\n",mysidestr,base,rel);
}
9 years ago
instantdex_acceptset(ap,base,rel,duration,myside,acceptdir,price,basevolume,offerer,0,minperc);
9 years ago
if ( queueflag != 0 )
9 years ago
{
printf("acceptableQ <- %llu\n",(long long)ap->orderid);
9 years ago
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
9 years ago
}
9 years ago
retstr = jprint(instantdex_acceptjson(ap),1);
9 years ago
//printf("acceptableQ %llu (%s)\n",(long long)ap->orderid,retstr);
9 years ago
return(retstr);
} else return(clonestr("{\"error\":\"invalid exchange\"}"));
9 years ago
}
9 years ago
void instantdex_update(struct supernet_info *myinfo)
{
9 years ago
struct instantdex_msghdr *pm; struct category_msg *m; bits256 instantdexhash; char *str,remote[64]; queue_t *Q; struct queueitem *item;
9 years ago
instantdexhash = calc_categoryhashes(0,"InstantDEX",0);
9 years ago
//char str2[65]; printf("instantdexhash.(%s)\n",bits256_str(str2,instantdexhash));
9 years ago
if ( (Q= category_Q(instantdexhash,myinfo->myaddr.persistent)) != 0 && queue_size(Q) > 0 && (item= Q->list) != 0 )
{
m = (void *)item;
9 years ago
m = queue_dequeue(Q,0);
9 years ago
pm = (struct instantdex_msghdr *)m->msg;
//printf("loop cmd.(%s)\n",pm->cmd);
//if ( m->remoteipbits == 0 && (m= queue_dequeue(Q,0)) )
9 years ago
{
9 years ago
//if ( (void *)m == (void *)item )
9 years ago
{
pm = (struct instantdex_msghdr *)m->msg;
if ( m->remoteipbits != 0 )
expand_ipbits(remote,m->remoteipbits);
else remote[0] = 0;
if ( (str= InstantDEX_hexmsg(myinfo,pm,m->len,remote)) != 0 )
free(str);
9 years ago
} //else printf("instantdex_update: unexpected m.%p changed item.%p\n",m,item);
9 years ago
free(m);
}
}
9 years ago
}
9 years ago
#include "../includes/iguana_apidefs.h"
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,maxaccept,base,rel,maxprice,basevolume)
9 years ago
{
9 years ago
struct instantdex_accept *ap; char *retstr; struct exchange_info *exchange; uint64_t txid;
9 years ago
myinfo = SuperNET_accountfind(json);
9 years ago
if ( remoteaddr == 0 && (exchange= exchanges777_find("bitcoin")) != 0 )
{
retstr = instantdex_createaccept(myinfo,&ap,exchange,base,rel,maxprice,basevolume,-1,rel,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits,1,juint(json,"minperc"));
return(instantdex_checkoffer(myinfo,&txid,exchange,ap,json));
} else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
9 years ago
}
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,minaccept,base,rel,minprice,basevolume)
{
9 years ago
struct instantdex_accept *ap; char *retstr; struct exchange_info *exchange; uint64_t txid;
9 years ago
myinfo = SuperNET_accountfind(json);
9 years ago
if ( remoteaddr == 0 && (exchange= exchanges777_find("bitcoin")) != 0 )
{
retstr = instantdex_createaccept(myinfo,&ap,exchanges777_find("bitcoin"),base,rel,minprice,basevolume,1,base,INSTANTDEX_OFFERDURATION,myinfo->myaddr.nxt64bits,1,juint(json,"minperc"));
return(instantdex_checkoffer(myinfo,&txid,exchange,ap,json));
} else return(clonestr("{\"error\":\"InstantDEX API request only local usage!\"}"));
9 years ago
}
9 years ago
THREE_STRINGS_AND_DOUBLE(atomic,offer,base,rel,orderid,basevolume)
{
if ( remoteaddr == 0 )
{
return(clonestr("{\"result\":\"atomic API request is not yet\"}"));
} else return(clonestr("{\"error\":\"atomic API request only local usage!\"}"));
}
TWO_STRINGS(atomic,accept,myorderid,otherid)
{
if ( remoteaddr == 0 )
{
return(clonestr("{\"result\":\"atomic API request is not yet\"}"));
} else return(clonestr("{\"error\":\"atomic API request only local usage!\"}"));
}
THREE_STRINGS(atomic,approve,myorderid,otherid,txname)
{
if ( remoteaddr == 0 )
{
return(clonestr("{\"result\":\"atomic API request is not yet\"}"));
} else return(clonestr("{\"error\":\"atomic API request only local usage!\"}"));
}
THREE_STRINGS(atomic,claim,myorderid,otherid,txname)
{
if ( remoteaddr == 0 )
{
return(clonestr("{\"result\":\"atomic API request is not yet\"}"));
} else return(clonestr("{\"error\":\"atomic API request only local usage!\"}"));
}
9 years ago
#include "../includes/iguana_apiundefs.h"