Browse Source

encrypt/decrypt json with file

release/v0.1
jl777 9 years ago
parent
commit
84a91ce299
  1. 3
      crypto777/OS_portable.h
  2. 42
      crypto777/iguana_OS.c
  3. 32
      crypto777/iguana_utils.c
  4. 7
      iguana/SuperNET.c
  5. 6
      iguana/SuperNET.h
  6. 11
      iguana/SuperNET_category.c
  7. 378
      iguana/SuperNET_keys.c
  8. 31
      iguana/exchanges/bitfinex.c
  9. 27
      iguana/exchanges/bitstamp.c
  10. 69
      iguana/exchanges/bittrex.c
  11. 77
      iguana/exchanges/btc38.c
  12. 28
      iguana/exchanges/btce.c
  13. 27
      iguana/exchanges/coinbase.c
  14. 25
      iguana/exchanges/exchange_supports.h
  15. 32
      iguana/exchanges/exchange_undefs.h
  16. 27
      iguana/exchanges/huobi.c
  17. 30
      iguana/exchanges/lakebtc.c
  18. 28
      iguana/exchanges/okcoin.c
  19. 57
      iguana/exchanges/poloniex.c
  20. 27
      iguana/exchanges/quadriga.c
  21. 3
      iguana/exchanges777.h
  22. 33
      iguana/iguana_exchanges.c
  23. 26
      iguana/iguana_instantdex.c
  24. 6
      iguana/iguana_json.c
  25. 10
      iguana/iguana_rpc.c
  26. 238
      iguana/main.c
  27. 12
      iguana/pnacl/Release/iguana.nmf
  28. BIN
      iguana/pnacl/Release/iguana.pexe
  29. 5
      includes/iguana_apideclares.h

3
crypto777/OS_portable.h

@ -247,6 +247,9 @@ int32_t init_hexbytes_noT(char *hexbytes,uint8_t *message,long len);
uint16_t parse_ipaddr(char *ipaddr,char *ip_port);
int32_t bitweight(uint64_t x);
unsigned char _decode_hex(char *hex);
char *uppercase_str(char *buf,char *str);
char *lowercase_str(char *buf,char *str);
int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr);
long _stripwhite(char *buf,int accept);
int32_t is_DST(int32_t datenum);

42
crypto777/iguana_OS.c

@ -783,6 +783,7 @@ void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep)
{
fclose(fp);
*lenp = 0;
printf("OS_loadfile null size.(%s)\n",fname);
return(0);
}
if ( filesize > buflen-1 )
@ -801,7 +802,8 @@ void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep)
}
fclose(fp);
*lenp = filesize;
}
//printf("loaded.(%s)\n",buf);
} //else printf("OS_loadfile couldnt load.(%s)\n",fname);
return(buf);
}
@ -836,4 +838,40 @@ void OS_init()
decode_hex(GENESIS_PRIVKEY.bytes,sizeof(GENESIS_PRIVKEY),GENESIS_PRIVKEYSTR);
SaM_PrepareIndices();
return(OS_portable_init());
}
}
int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr)
{
if ( dispstr != 0 && dispstr[0] != 0 )
fprintf(stderr,"%s",dispstr);
line[0] = 0;
#ifndef _WIN32
if ( waitflag == 0 )
{
static char prevline[1024];
struct timeval timeout;
fd_set fdset;
int32_t s;
line[0] = 0;
FD_ZERO(&fdset);
FD_SET(STDIN_FILENO,&fdset);
timeout.tv_sec = 0, timeout.tv_usec = 10000;
if ( (s= select(1,&fdset,NULL,NULL,&timeout)) < 0 )
fprintf(stderr,"wait_for_input: error select s.%d\n",s);
else
{
if ( FD_ISSET(STDIN_FILENO,&fdset) > 0 && fgets(line,max,stdin) == line )
{
line[strlen(line)-1] = 0;
if ( line[0] == 0 || (line[0] == '.' && line[1] == 0) )
strcpy(line,prevline);
else strcpy(prevline,line);
}
}
return((int32_t)strlen(line));
}
#endif
fgets(line,max,stdin);
line[strlen(line)-1] = 0;
return((int32_t)strlen(line));
}

32
crypto777/iguana_utils.c

@ -338,15 +338,6 @@ int32_t init_hexbytes_noT(char *hexbytes,unsigned char *message,long len)
return((int32_t)len*2+1);
}
void touppercase(char *str)
{
int32_t i;
if ( str == 0 || str[0] == 0 )
return;
for (i=0; str[i]!=0; i++)
str[i] = toupper(((int32_t)str[i]));
}
long _stripwhite(char *buf,int accept)
{
int32_t i,j,c;
@ -494,6 +485,15 @@ int32_t sortds(double *buf,uint32_t num,int32_t size)
}
*/
void touppercase(char *str)
{
int32_t i;
if ( str == 0 || str[0] == 0 )
return;
for (i=0; str[i]!=0; i++)
str[i] = toupper(((int32_t)str[i]));
}
void tolowercase(char *str)
{
int32_t i;
@ -503,6 +503,20 @@ void tolowercase(char *str)
str[i] = tolower(((int32_t)str[i]));
}
char *uppercase_str(char *buf,char *str)
{
strcpy(buf,str);
touppercase(buf);
return(buf);
}
char *lowercase_str(char *buf,char *str)
{
strcpy(buf,str);
tolowercase(buf);
return(buf);
}
int32_t is_decimalstr(char *str)
{
int32_t i;

7
iguana/SuperNET.c

@ -900,8 +900,9 @@ ZERO_ARGS(SuperNET,keypair)
TWOHASHES_AND_STRING(SuperNET,decipher,privkey,srcpubkey,cipherstr)
{
int32_t cipherlen,msglen; char *retstr; cJSON *retjson; void *ptr = 0; uint8_t *cipher,*message,space[8192];
cipherlen = (int32_t)strlen(cipherstr) >> 1;
int32_t cipherlen=0,msglen; char *retstr; cJSON *retjson; void *ptr = 0; uint8_t *cipher,*message,space[8192];
if ( cipherstr != 0 )
cipherlen = (int32_t)strlen(cipherstr) >> 1;
if ( cipherlen < crypto_box_NONCEBYTES )
return(clonestr("{\"error\":\"cipher is too short\"}"));
cipher = calloc(1,cipherlen);
@ -934,7 +935,7 @@ TWOHASHES_AND_STRING(SuperNET,cipher,privkey,destpubkey,message)
onetimeflag = memcmp(origprivkey.bytes,privkey.bytes,sizeof(privkey));
if ( onetimeflag != 0 )
{
jaddbits256(retjson,"onetime_privkey",privkey);
//jaddbits256(retjson,"onetime_privkey",privkey);
jaddbits256(retjson,"onetime_pubkey",destpubkey);
if ( onetimeflag == 2 )
jaddstr(retjson,"warning","onetime keypair was used to broadcast");

6
iguana/SuperNET.h

@ -24,6 +24,7 @@
#define SUPERNET_GETPEERSTR "{\"agent\":\"SuperNET\",\"method\":\"getpeers\",\"plaintext\":1}"
#define SUPERNET_STOPSTR "{\"agent\":\"SuperNET\",\"method\":\"stop\",\"plaintext\":1}"
#define SUPERNET_MAXEXCHANGES 64
#define SUPERNET_LBPORT 7770
#define SUPERNET_PUBPORT 7771
#define SUPERNET_PORTP2P 7770
@ -83,7 +84,8 @@ struct supernet_info
int32_t LBsock,PUBsock,reqsock,subsock,networktimeout,maxdelay;
uint16_t LBport,PUBport,reqport,subport;
struct nn_pollfd pfd[SUPERNET_MAXAGENTS]; //struct relay_info active;
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ; int32_t numagents;
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ; int32_t numagents,numexchanges;
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES];
};
/*struct supernet_endpoint
@ -156,6 +158,8 @@ char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag
bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory);
struct category_chain *category_chain_functions(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,int32_t hashlen,int32_t addrlen,void *hash_func,void *stake_func,void *hit_func,void *default_func);
#define category_default_latest() (*cchain->default_func)(cchain,'L',0,0,0,0,zero)
void category_init(struct supernet_info *myinfo);
char *SuperNET_keysinit(struct supernet_info *myinfo,char *jsonstr);
#endif

11
iguana/SuperNET_category.c

@ -329,3 +329,14 @@ char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag
free(hexmsg);
return(retstr);
}
void category_init(struct supernet_info *myinfo)
{
bits256 pangeahash;
//exchanges777_init(0);
category_subscribe(myinfo,GENESIS_PUBKEY,GENESIS_PUBKEY);
pangeahash = calc_categoryhashes(0,"pangea",0);
category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY);
category_processfunc(pangeahash,pangea_hexmsg);
category_chain_functions(myinfo,pangeahash,GENESIS_PUBKEY,sizeof(bits256),sizeof(bits256),0,0,0,0);
}

378
iguana/SuperNET_keys.c

@ -0,0 +1,378 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
#include "iguana777.h"
bits256 SuperNET_wallet2shared(bits256 wallethash,bits256 wallet2priv)
{
bits256 wallet2shared,seed,wallet2pub;
wallet2pub = curve25519(wallet2priv,curve25519_basepoint9());
seed = curve25519_shared(wallethash,wallet2pub);
vcalc_sha256(0,wallet2shared.bytes,seed.bytes,sizeof(bits256));
return(wallet2shared);
}
bits256 SuperNET_wallet2priv(char *wallet2fname,bits256 wallethash)
{
char *wallet2str; uint32_t r,i,crc; long allocsize; bits256 wallet2priv;
wallet2priv = GENESIS_PRIVKEY;
if ( (wallet2str= OS_filestr(&allocsize,wallet2fname)) != 0 )
{
r = crc = calc_crc32(0,wallet2str,(int32_t)allocsize);
r %= 32;
for (i=0; i<allocsize; i++)
wallet2str[i] ^= wallethash.bytes[(i + r) % 32];
vcalc_sha256(0,wallet2priv.bytes,(void *)wallet2str,(int32_t)allocsize);
free(wallet2str);
//char str[65]; printf("wallet2priv.(%s) from.(%s) crc.%u and passphrase r.%d len.%ld\n",bits256_str(str,wallet2priv),wallet2fname,crc,r,allocsize);
} else printf("SuperNET_wallet2priv cant open (%s)\n",wallet2fname);
return(wallet2priv);
}
char *SuperNET_parsemainargs(struct supernet_info *myinfo,bits256 *wallethashp,bits256 *wallet2privp,char *argjsonstr)
{
cJSON *json; uint8_t secretbuf[512]; char *wallet2fname,*coinargs=0,*secret;
bits256 wallethash,wallet2priv; int32_t len;
wallethash = wallet2priv = GENESIS_PRIVKEY;
if ( argjsonstr != 0 && (json= cJSON_Parse(argjsonstr)) != 0 )
{
printf("ARGSTR.(%s)\n",argjsonstr);
if ( jobj(json,"numhelpers") != 0 )
IGUANA_NUMHELPERS = juint(json,"numhelpers");
if ( (secret= jstr(json,"wallet")) != 0 )
{
len = (int32_t)strlen(secret);
if ( is_hexstr(secret,0) != 0 && len == 128 )
{
len >>= 1;
decode_hex(secretbuf,len,secret);
} else vcalc_sha256(0,secretbuf,(void *)secret,len), len = sizeof(bits256);
memcpy(wallethash.bytes,secretbuf,sizeof(wallethash));
//printf("wallethash.(%s)\n",bits256_str(str,wallethash));
if ( (wallet2fname= jstr(json,"2fafile")) != 0 )
wallet2priv = SuperNET_wallet2priv(wallet2fname,wallethash);
}
if ( jobj(json,"coins") != 0 )
coinargs = argjsonstr;
free_json(json);
}
*wallethashp = wallethash, *wallet2privp = wallet2priv;
return(coinargs);
}
bits256 SuperNET_linehash(char *_line)
{
int32_t i,j; bits256 hash;
/*if ( _line[strlen(_line)-1] == '\'' && strncmp(_line,match,len) == 0 )
{
_line[strlen(_line)-1] = 0;
_line += len;
}
printf("%02x %02x %02x %02x %02x\n",0xff & _line[0],0xff & _line[1],0xff & _line[2],0xff & _line[3],0xff & _line[4]);*/
for (i=j=0; _line[i]!=0; i++)
{
if ( (uint8_t)_line[i] == 0xe2 && (uint8_t)_line[i+1] == 0x80 )
{
if ( (uint8_t)_line[i+2] == 0x99 )
_line[j++] = '\'', i += 2;
else if ( (uint8_t)_line[i+2] == 0x9c || (uint8_t)_line[i+2] == 0x9d )
_line[j++] = '"', i += 2;
else _line[j++] = _line[i];
}
else _line[j++] = _line[i];
//else if ( (uint8_t)_line[i] == 0x9c )
// _line[i] = '"';
}
_line[j++] = 0;
if ( j == sizeof(bits256)*2 && is_hexstr(_line,j) == j )
decode_hex(hash.bytes,sizeof(hash),_line);
else vcalc_sha256(0,hash.bytes,(void *)_line,j);
//char str[65]; printf("line -> (%s)\n",bits256_str(str,hash));
return(hash);
}
int32_t SuperNET_savejsonfile(char *fname,bits256 privkey,bits256 destpubkey,cJSON *json)
{
char *confstr,*ciphered; FILE *fp;
confstr = jprint(json,0);
if ( bits256_nonz(privkey) != 0 && bits256_cmp(privkey,GENESIS_PUBKEY) != 0 )
{
//sprintf(fname,"confs/iguana.%llu",(long long)wallet2shared.txid);
if ( (ciphered= SuperNET_cipher(0,0,json,0,privkey,destpubkey,confstr)) != 0 )
{
//printf("save (%s) <- (%s)\n",fname,ciphered);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(ciphered,1,strlen(ciphered)+1,fp);
fclose(fp);
}
free(ciphered);
} else printf("error ciphering.(%s) (%s)\n",fname,confstr);
}
else
{
//sprintf(fname,"confs/iguana.conf");
//printf("save (%s) <- (%s)\n",fname,confstr);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(confstr,1,strlen(confstr)+1,fp);
fclose(fp);
}
}
free(confstr);
return(0);
}
int32_t SuperNET_userkeys(char *passphrase,int32_t passsize,char *fname2fa,int32_t fnamesize)
{
#ifndef __PNACL
//if ( (bits256_nonz(*wallethashp) == 0 || bits256_cmp(*wallethashp,GENESIS_PRIVKEY) == 0) && (bits256_nonz(*wallet2privp) == 0 || bits256_cmp(*wallet2privp,GENESIS_PRIVKEY) == 0) )
{
sleep(1);
printf("\n\n********************************\n");
if ( OS_getline(1,passphrase,passsize-1,"passphrase: ") > 0 )
;
if ( OS_getline(1,fname2fa,fnamesize-1,"enter filename of a file that you will NEVER lose: ") > 0 )
;
return(0);
}
#endif
return(-1);
}
cJSON *SuperNET_decryptedjson(char *passphrase,int32_t passsize,bits256 wallethash,char *fname2fa,int32_t fnamesize,bits256 wallet2priv)
{
long allocsize; cJSON *filejson,*msgjson=0,*json=0; char *confstr=0,*deciphered,fname[512],str[65];
bits256 wallet2shared,wallet2pub; int32_t first,second;
msgjson = 0;
first = (bits256_nonz(wallethash) != 0 && bits256_cmp(wallethash,GENESIS_PRIVKEY) != 0);
second = (bits256_nonz(wallet2priv) != 0 && bits256_cmp(wallet2priv,GENESIS_PRIVKEY) != 0);
if ( first == 0 && second == 0 && passphrase != 0 && fname2fa != 0 )
{
if ( passphrase[0] == 0 && fname2fa[0] == 0 )
SuperNET_userkeys(passphrase,passsize,fname2fa,fnamesize);
wallethash = SuperNET_linehash(passphrase);
SuperNET_linehash(fname2fa); // maps special chars
wallet2priv = SuperNET_wallet2priv(fname2fa,wallethash);
//char str[65],str2[65]; printf("(%s + %s) -> wallethash.%s 2.(%s)\n",passphrase,fname2fa,bits256_str(str,wallethash),bits256_str(str2,wallet2priv));
}
first = (bits256_nonz(wallethash) != 0 && bits256_cmp(wallethash,GENESIS_PRIVKEY) != 0);
second = (bits256_nonz(wallet2priv) != 0 && bits256_cmp(wallet2priv,GENESIS_PRIVKEY) != 0);
if ( first != 0 || second != 0 )
{
if ( bits256_nonz(wallethash) == 0 )
wallethash = GENESIS_PRIVKEY;
wallet2shared = SuperNET_wallet2shared(wallethash,wallet2priv);
wallet2pub = curve25519(wallet2shared,curve25519_basepoint9());
sprintf(fname,"confs/%s",bits256_str(str,wallet2pub));
//printf("fname.(%s) wallet2shared.%s\n",fname,bits256_str(str,wallet2pub));
if ( (confstr= OS_filestr(&allocsize,fname)) != 0 )
{
if ( (filejson= cJSON_Parse(confstr)) != 0 )
{
if ( (deciphered= SuperNET_decipher(0,0,0,0,wallet2shared,curve25519(wallethash,curve25519_basepoint9()),jstr(filejson,"result"))) != 0 )
{
if ( (json= cJSON_Parse(deciphered)) == 0 )
printf("cant decipher (%s) [%s]\n",fname,confstr);
else
{
if ( (msgjson= cJSON_Parse(jstr(json,"message"))) == 0 )
printf("no message in (%s)\n",jprint(json,0));
}
free(deciphered);
}
free_json(filejson);
}
} else printf("couldnt load (%s)\n",fname);
}
else
{
sprintf(fname,"confs/iguana.conf");
if ( (confstr= OS_filestr(&allocsize,fname)) != 0 )
{
if ( (json= cJSON_Parse(confstr)) != 0 )
msgjson = json;
} else printf("couldnt open (%s)\n",fname);
}
if ( msgjson != 0 )
msgjson = jduplicate(msgjson);
if ( json != 0 )
free_json(json);
return(msgjson);
}
int32_t SuperNET_encryptjson(char *destfname,char *passphrase,int32_t passsize,char *fname2fa,int32_t fnamesize,cJSON *argjson)
{
bits256 wallethash,wallet2priv,wallet2shared,wallet2pub; char str[65];
wallethash = wallet2priv = GENESIS_PRIVKEY;
if ( passphrase == 0 || passphrase[0] == 0 || fname2fa == 0 || fname2fa[0] == 0 )
SuperNET_userkeys(passphrase,passsize,fname2fa,fnamesize);
wallethash = SuperNET_linehash(passphrase);
SuperNET_linehash(fname2fa); // maps special chars
wallet2priv = SuperNET_wallet2priv(fname2fa,wallethash);
//char str2[65]; printf("ENCRYPT.[%s %s] (%s) 2.%s\n",passphrase,fname2fa,bits256_str(str,wallethash),bits256_str(str2,wallet2priv));
wallet2shared = SuperNET_wallet2shared(wallethash,wallet2priv);
wallet2pub = curve25519(wallet2shared,curve25519_basepoint9());
sprintf(destfname,"confs/%s",bits256_str(str,wallet2pub));
//printf("shared.%llx -> pub.%s\n",(long long)wallet2shared.txid,bits256_str(str,wallet2pub));
SuperNET_savejsonfile(destfname,wallethash,wallet2pub,argjson);
return(0);
}
void SuperNET_parsemyinfo(struct supernet_info *myinfo,cJSON *msgjson)
{
char *ipaddr,*secret,str[65]; bits256 checkhash,acct;
if ( msgjson != 0 )
{
if ( (ipaddr= jstr(msgjson,"ipaddr")) != 0 && is_ipaddr(ipaddr) != 0 )
strcpy(myinfo->ipaddr,ipaddr);
if ( (secret= jstr(msgjson,"secret")) != 0 )
{
myinfo->myaddr.nxt64bits = conv_NXTpassword(myinfo->persistent_priv.bytes,myinfo->myaddr.persistent.bytes,(uint8_t *)secret,(int32_t)strlen(secret));
}
else
{
myinfo->persistent_priv = jbits256(msgjson,"persistent_priv");
if ( bits256_nonz(myinfo->persistent_priv) == 0 )
{
printf("null persistent_priv? generate new one\n");
OS_randombytes(myinfo->persistent_priv.bytes,sizeof(myinfo->privkey));
}
myinfo->myaddr.persistent = jbits256(msgjson,"persistent_pub");
checkhash = curve25519(myinfo->persistent_priv,curve25519_basepoint9());
}
if ( memcmp(checkhash.bytes,myinfo->myaddr.persistent.bytes,sizeof(checkhash)) != 0 )
{
printf("persistent pubkey mismatches one in iguana.conf\n");
myinfo->myaddr.persistent = checkhash;
} else printf("persistent VALIDATED persistentpub.(%s)\n",bits256_str(str,checkhash));
}
if ( bits256_nonz(myinfo->persistent_priv) == 0 )
{
OS_randombytes(myinfo->persistent_priv.bytes,sizeof(myinfo->persistent_priv));
myinfo->myaddr.persistent = curve25519(myinfo->persistent_priv,curve25519_basepoint9());
}
vcalc_sha256(0,acct.bytes,(void *)myinfo->myaddr.persistent.bytes,sizeof(bits256));
myinfo->myaddr.nxt64bits = acct.txid;
RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits);
}
char *SuperNET_keysinit(struct supernet_info *myinfo,char *argjsonstr)
{
long allocsize; cJSON *msgjson,*json=0; uint32_t r; bits256 wallethash,wallet2priv; int32_t len,c;
char str[65],str2[65],destfname[1024],fname2fa[2048],passphrase[8192],*ipaddr,*coinargs=0;
passphrase[0] = fname2fa[0] = 0;
wallethash = wallet2priv = GENESIS_PRIVKEY;
coinargs = SuperNET_parsemainargs(myinfo,&wallethash,&wallet2priv,argjsonstr);
//printf("wallethash.%s 2.(%s)\n",bits256_str(str,wallethash),bits256_str(str2,wallet2priv));
if ( (msgjson= SuperNET_decryptedjson(passphrase,sizeof(passphrase),wallethash,fname2fa,sizeof(fname2fa),wallet2priv)) != 0 )
{
SuperNET_parsemyinfo(myinfo,msgjson);
free_json(msgjson);
}
else
{
if ( bits256_nonz(myinfo->persistent_priv) == 0 )
{
OS_randombytes(myinfo->persistent_priv.bytes,sizeof(myinfo->persistent_priv));
myinfo->myaddr.persistent = curve25519(myinfo->persistent_priv,curve25519_basepoint9());
}
json = cJSON_CreateObject();
jaddstr(json,"ipaddr",myinfo->ipaddr);
jaddbits256(json,"persistent_priv",myinfo->persistent_priv);
jaddbits256(json,"persistent_pub",myinfo->myaddr.persistent);
OS_randombytes((void *)&r,sizeof(r));
jadd64bits(json,"rand",r);
//printf("call SuperNET_encryptjson\n");
SuperNET_encryptjson(destfname,passphrase,sizeof(passphrase),fname2fa,sizeof(fname2fa),json);
//printf("save.(%s)\n",jprint(json,0));
free_json(json);
}
if ( myinfo->ipaddr[0] == 0 )
{
if ( (ipaddr= OS_filestr(&allocsize,"ipaddr")) != 0 )
{
printf("got ipaddr.(%s)\n",ipaddr);
len = (int32_t)strlen(ipaddr) - 1;
while ( len > 8 && ((c= ipaddr[len]) == '\r' || c == '\n' || c == ' ' || c == '\t') )
ipaddr[len] = 0, len--;
printf("got ipaddr.(%s) %x\n",ipaddr,is_ipaddr(ipaddr));
if ( is_ipaddr(ipaddr) != 0 )
{
strcpy(myinfo->ipaddr,ipaddr);
myinfo->myaddr.selfipbits = (uint32_t)calc_ipbits(ipaddr);
}
free(ipaddr);
}
}
if ( myinfo->myaddr.selfipbits == 0 )
{
strcpy(myinfo->ipaddr,"127.0.0.1");
myinfo->myaddr.selfipbits = (uint32_t)calc_ipbits(myinfo->ipaddr);
}
OS_randombytes(myinfo->privkey.bytes,sizeof(myinfo->privkey));
myinfo->myaddr.pubkey = curve25519(myinfo->privkey,curve25519_basepoint9());
printf("(%s) %s %llu session(%s %s) persistent.%llx %llx\n",myinfo->ipaddr,myinfo->myaddr.NXTADDR,(long long)myinfo->myaddr.nxt64bits,bits256_str(str,myinfo->privkey),bits256_str(str2,myinfo->myaddr.pubkey),(long long)myinfo->persistent_priv.txid,(long long)myinfo->myaddr.persistent.txid);
return(coinargs);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
THREE_STRINGS(InstantDEX,encryptjson,passphrase,permanentfile,anything)
{
char destfname[4096],pass[8192],fname2[1023]; cJSON *argjson,*retjson = cJSON_CreateObject();
safecopy(pass,passphrase,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2));
argjson = jduplicate(json);
//printf("argjson.(%s)\n",jprint(argjson,0));
jdelete(argjson,"agent");
jdelete(argjson,"method");
jdelete(argjson,"passphrase");
jdelete(argjson,"permanentfile");
jdelete(argjson,"timestamp");
jdelete(argjson,"tag");
if ( SuperNET_encryptjson(destfname,pass,sizeof(pass),fname2,sizeof(fname2),argjson) == 0 )
{
jaddstr(retjson,"result","success");
jaddstr(retjson,"filename",destfname);
} else jaddstr(retjson,"error","couldnt encrypt json file");
free_json(argjson);
return(jprint(retjson,1));
}
TWO_STRINGS(InstantDEX,decryptjson,passphrase,permanentfile)
{
char pass[8192],fname2[1023]; cJSON *retjson,*obj; bits256 wallethash,wallet2priv;
safecopy(pass,passphrase,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2));
wallethash = wallet2priv = GENESIS_PRIVKEY;
if ( strlen(pass) == sizeof(wallethash)*2 && is_hexstr(pass,(int32_t)sizeof(bits256)*2) > 0 )
wallethash = bits256_conv(pass);
if ( strlen(fname2) == sizeof(wallet2priv)*2 && is_hexstr(fname2,(int32_t)sizeof(bits256)*2) > 0 )
wallet2priv = bits256_conv(fname2);
//printf("decrypt.(%s %s)\n",pass,fname2);
if ( (retjson= SuperNET_decryptedjson(pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 )
{
obj = jduplicate(jobj(retjson,"anything"));
jdelete(retjson,"anything");
jadd(retjson,"result",obj);
return(jprint(retjson,1));
}
else return(clonestr("{\"error\":\"couldnt decrypt json file\"}"));
}
#include "../includes/iguana_apiundefs.h"

31
iguana/exchanges/bitfinex.c

@ -13,7 +13,8 @@
* *
******************************************************************************/
#define EXCHANGE_NAME "bitfinex"
#define EXCHANGE_NAMESTR "bitfinex"
#define EXCHANGE_NAME #bitfinex
#define UPDATE bitfinex ## _price
#define SUPPORTS bitfinex ## _supports
#define SIGNPOST bitfinex ## _signpost
@ -26,6 +27,12 @@
#define PARSEBALANCE bitfinex ## _parsebalance
#define WITHDRAW bitfinex ## _withdraw
#define CHECKBALANCE bitfinex ## _checkbalance
#define ALLPAIRS bitfinex ## _allpairs
#define FUNCS bitfinex ## _funcs
#define BASERELS bitfinex ## _baserels
static char *BASERELS[][2] = { {"btc","usd"}, {"ltc","usd"}, {"ltc","btc"}, {"",""} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -34,12 +41,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,"price","amount",maxdepth,0));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","usd"}, {"ltc","usd"}, {"ltc","btc"} };
return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
}
char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson)
{
//[[{"type":"deposit","currency":"btc","amount":"0.0","available":"0.0"},{"type":"deposit","currency":"usd","amount":"0.0","available":"0.0"},{"type":"exchange","currency":"btc","amount":"0.01065851","available":"0.01065851"},{"type":"exchange","currency":"usd","amount":"23386.37278962","available":"0.00378962"},{"type":"trading","currency":"btc","amount":"0.0","available":"0.0"},{"type":"trading","currency":"usd","amount":"0.0","available":"0.0"}]]
@ -245,18 +246,6 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
return(retstr); // return standardized withdraw
}
struct exchange_funcs bitfinex_funcs = EXCHANGE_FUNCS(bitfinex,EXCHANGE_NAME);
struct exchange_funcs FUNCS = EXCHANGE_FUNCS(bitfinex,EXCHANGE_NAMESTR);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef CHECKBALANCE
#include "exchange_undefs.h"

27
iguana/exchanges/bitstamp.c

@ -27,6 +27,12 @@
#define WITHDRAW bitstamp ## _withdraw
#define EXCHANGE_AUTHURL "https://www.bitstamp.net/api"
#define CHECKBALANCE bitstamp ## _checkbalance
#define ALLPAIRS bitstamp ## _allpairs
#define FUNCS bitstamp ## _funcs
#define BASERELS bitstamp ## _baserels
static char *BASERELS[][2] = { {"btc","usd"} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -35,12 +41,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","usd"} };
return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *method,char *payload)
{
/*signature is a HMAC-SHA256 encoded message containing: nonce, customer ID (can be found here) and API key. The HMAC-SHA256 code must be generated using a secret key that was generated with your API key. This code must be converted to it's hexadecimal representation (64 uppercase characters).Example (Python):
@ -154,17 +154,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs bitstamp_funcs = EXCHANGE_FUNCS(bitstamp,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef EXCHANGE_AUTHURL
#undef CHECKBALANCE
#include "exchange_undefs.h"

69
iguana/exchanges/bittrex.c

@ -26,24 +26,40 @@
#define PARSEBALANCE bittrex ## _parsebalance
#define WITHDRAW bittrex ## _withdraw
#define CHECKBALANCE bittrex ## _checkbalance
#define ALLPAIRS bittrex ## _allpairs
#define FUNCS bittrex ## _funcs
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
static char *(*bittrex_baserels)[][2];
char *ALLPAIRS(struct exchange_info *exchange,cJSON *argjson)
{
cJSON *json,*obj; char *jsonstr,market[128],url[1024]; double hbla = 0.;
sprintf(market,"%s-%s",rel,base);
sprintf(url,"https://bittrex.com/api/v1.1/public/getorderbook?market=%s&type=both&depth=%d",market,maxdepth);
jsonstr = issue_curl(url);
if ( jsonstr != 0 )
static int32_t num;
char *jsonstr,*base,*rel; int32_t i; cJSON *json,*array,*item;
if ( num == 0 || (*bittrex_baserels) == 0 )
{
if ( (json = cJSON_Parse(jsonstr)) != 0 )
jsonstr = issue_curl("https://bittrex.com/api/v1.1/public/getmarkets");
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (obj= cJSON_GetObjectItem(json,"success")) != 0 && is_cJSON_True(obj) != 0 )
hbla = exchanges777_json_orderbook(exchange,commission,base,rel,quotes,maxdepth,json,"result","buy","sell","Rate","Quantity");
if ( (array= jarray(&num,json,"result")) != 0 )
{
bittrex_baserels = calloc(num,sizeof(char *) * 2);
for (i=0; i<num; i++)
{
item = jitem(array,i);
base = jstr(item,"MarketCurrency");
rel = jstr(item,"BaseCurrency");
if ( base != 0 && rel != 0 )
{
(*bittrex_baserels)[i][0] = clonestr(base);
(*bittrex_baserels)[i][1] = clonestr(rel);
}
}
}
free_json(json);
}
free(jsonstr);
}
return(hbla);
return(jprint(exchanges777_allpairs((*bittrex_baserels),num),1));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
@ -57,6 +73,25 @@ int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argj
else return(0);
}
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
cJSON *json,*obj; char *jsonstr,market[128],url[1024]; double hbla = 0.;
sprintf(market,"%s-%s",rel,base);
sprintf(url,"https://bittrex.com/api/v1.1/public/getorderbook?market=%s&type=both&depth=%d",market,maxdepth);
jsonstr = issue_curl(url);
if ( jsonstr != 0 )
{
if ( (json = cJSON_Parse(jsonstr)) != 0 )
{
if ( (obj= cJSON_GetObjectItem(json,"success")) != 0 && is_cJSON_True(obj) != 0 )
hbla = exchanges777_json_orderbook(exchange,commission,base,rel,quotes,maxdepth,json,"result","buy","sell","Rate","Quantity");
free_json(json);
}
free(jsonstr);
}
return(hbla);
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *url,char *payload)
{
char dest[(512>>3)*2+1],hdr1[512],hdr2[512],hdr3[512],hdr4[512],*data,*sig; cJSON *json;
@ -230,16 +265,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs bittrex_funcs = EXCHANGE_FUNCS(bittrex,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef CHECKBALANCE
#include "exchange_undefs.h"

77
iguana/exchanges/btc38.c

@ -27,22 +27,36 @@
#define WITHDRAW btc38 ## _withdraw
#define EXCHANGE_AUTHURL "http://www.btc38.com/trade/t_api"
#define CHECKBALANCE btc38 ## _checkbalance
#define ALLPAIRS btc38 ## _allpairs
#define FUNCS btc38 ## _funcs
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
char *btc38_cnypairs[] = { "BTC", "LTC", "DOGE", "XRP", "BTS", "XLM", "NXT", "BLK", "BC", "VPN", "BILS", "BOST", "PPC", "APC", "ZCC", "XPM", "DGC", "MEC", "WDC", "QRK", "BEC", "ANC", "UNC", "RIC", "SRC", "TAG" };
char *btc38_btcpairs[] = { "TMC", "LTC", "DOGE", "XRP", "BTS", "XEM", "XCN", "VOOT", "SYS", "NRS", "NAS", "SYNC", "MED", "EAC" };
char *ALLPAIRS(struct exchange_info *exchange,cJSON *argjson)
{
char url[1024],lrel[16],lbase[16];
strcpy(lrel,rel), strcpy(lbase,base);
tolowercase(lrel), tolowercase(lbase);
if ( strcmp(lbase,"cny") == 0 && strcmp(lrel,"btc") == 0 )
sprintf(url,"http://api.btc38.com/v1/depth.php?c=%s&mk_type=%s","btc","cny");
else sprintf(url,"http://api.btc38.com/v1/depth.php?c=%s&mk_type=%s",lbase,lrel);
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
int32_t i; char str[65]; cJSON *json,*item,*array = cJSON_CreateArray();
for (i=0; i<sizeof(btc38_btcpairs)/sizeof(*btc38_btcpairs); i++)
{
item = cJSON_CreateArray();
jaddistr(item,uppercase_str(str,btc38_btcpairs[i]));
jaddistr(item,"BTC");
jaddi(array,item);
}
for (i=0; i<sizeof(btc38_cnypairs)/sizeof(*btc38_cnypairs); i++)
{
item = cJSON_CreateArray();
jaddistr(item,uppercase_str(str,btc38_cnypairs[i]));
jaddistr(item,"CNY");
jaddi(array,item);
}
json = cJSON_CreateObject();
jadd(json,"result",array);
return(jprint(json,1));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *_base,char *_rel,cJSON *argjson)
{
char *cnypairs[] = { "BTC", "LTC", "DOGE", "XRP", "BTS", "STR", "NXT", "BLK", "BC", "VPN", "BILS", "BOST", "PPC", "APC", "ZCC", "XPM", "DGC", "MEC", "WDC", "QRK", "BEC", "ANC", "UNC", "RIC", "SRC", "TAG" };
char *btcpairs[] = { "TMC", "LTC", "DOGE", "XRP", "BTS", "XEM", "VPN", "XCN", "VOOT", "SYS", "NRS", "NAS", "SYNC", "MED", "EAC" };
int32_t i; char base[64],rel[64];
strcpy(base,_base), strcpy(rel,_rel);
touppercase(base), touppercase(rel);
@ -54,32 +68,43 @@ int32_t SUPPORTS(struct exchange_info *exchange,char *_base,char *_rel,cJSON *ar
return(-1);
else if ( strcmp(base,"BTC") == 0 )
{
for (i=0; i<sizeof(btcpairs)/sizeof(*btcpairs); i++)
if ( strcmp(btcpairs[i],rel) == 0 )
for (i=0; i<sizeof(btc38_btcpairs)/sizeof(*btc38_btcpairs); i++)
if ( strcmp(btc38_btcpairs[i],rel) == 0 )
return(-1);
}
else if ( strcmp(rel,"BTC") == 0 )
{
for (i=0; i<sizeof(btcpairs)/sizeof(*btcpairs); i++)
if ( strcmp(btcpairs[i],base) == 0 )
for (i=0; i<sizeof(btc38_btcpairs)/sizeof(*btc38_btcpairs); i++)
if ( strcmp(btc38_btcpairs[i],base) == 0 )
return(1);
}
else if ( strcmp(base,"CNY") == 0 )
{
for (i=0; i<sizeof(cnypairs)/sizeof(*cnypairs); i++)
if ( strcmp(cnypairs[i],rel) == 0 )
for (i=0; i<sizeof(btc38_cnypairs)/sizeof(*btc38_cnypairs); i++)
if ( strcmp(btc38_cnypairs[i],rel) == 0 )
return(-1);
}
else if ( strcmp(rel,"CNY") == 0 )
{
for (i=0; i<sizeof(cnypairs)/sizeof(*cnypairs); i++)
if ( strcmp(cnypairs[i],base) == 0 )
for (i=0; i<sizeof(btc38_cnypairs)/sizeof(*btc38_cnypairs); i++)
if ( strcmp(btc38_cnypairs[i],base) == 0 )
return(1);
}
printf("BTC38 doesnt support (%s/%s)\n",base,rel);
return(0);
}
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
char url[1024],lrel[16],lbase[16];
strcpy(lrel,rel), strcpy(lbase,base);
tolowercase(lrel), tolowercase(lbase);
if ( strcmp(lbase,"cny") == 0 && strcmp(lrel,"btc") == 0 )
sprintf(url,"http://api.btc38.com/v1/depth.php?c=%s&mk_type=%s","btc","cny");
else sprintf(url,"http://api.btc38.com/v1/depth.php?c=%s&mk_type=%s",lbase,lrel);
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path)
{
char cmdbuf[2048],url[1024],buf[1024],hdr1[512],hdr2[512],hdr3[512],hdr4[512],digest[33],*data;
@ -304,18 +329,4 @@ char *ORDERSTATUS(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson
struct exchange_funcs btc38_funcs = EXCHANGE_FUNCS(btc38,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef EXCHANGE_AUTHURL
#undef CHECKBALANCE
#include "exchange_undefs.h"

28
iguana/exchanges/btce.c

@ -27,6 +27,13 @@
#define WITHDRAW btce ## _withdraw
#define EXCHANGE_AUTHURL "https://btc-e.com/tapi"
#define CHECKBALANCE btce ## _checkbalance
#define ALLPAIRS btce ## _allpairs
#define FUNCS btce ## _funcs
#define BASERELS btce ## _baserels
static char *BASERELS[][2] = { {"btc","usd"}, {"btc","rur"}, {"btc","eur"}, {"ltc","btc"}, {"ltc","usd"}, {"ltc","rur"}, {"ltc","eur"}, {"nmc","btc"}, {"nmc","usd"}, {"nvc","btc"}, {"nvc","usd"}, {"eur","usd"}, {"eur","rur"}, {"ppc","btc"}, {"ppc","usd"} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -38,12 +45,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,field));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","usd"}, {"btc","rur"}, {"btc","eur"}, {"ltc","btc"}, {"ltc","usd"}, {"ltc","rur"}, {"ltc","eur"}, {"nmc","btc"}, {"nmc","usd"}, {"nvc","btc"}, {"nvc","usd"}, {"eur","usd"}, {"eur","rur"}, {"ppc","btc"}, {"ppc","usd"} };
return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *url,char *payload)
{
char dest[(512>>3)*2+1],hdr1[512],hdr2[512],hdr3[512],hdr4[512],*data,*sig; cJSON *json;
@ -200,17 +201,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs btce_funcs = EXCHANGE_FUNCS(btce,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef EXCHANGE_AUTHURL
#undef CHECKBALANCE
#include "exchange_undefs.h"

27
iguana/exchanges/coinbase.c

@ -27,6 +27,12 @@
#define WITHDRAW coinbase ## _withdraw
#define EXCHANGE_AUTHURL "https://api.exchange.coinbase.com"
#define CHECKBALANCE coinbase ## _checkbalance
#define ALLPAIRS coinbase ## _allpairs
#define FUNCS coinbase ## _funcs
#define BASERELS coinbase ## _baserels
static char *BASERELS[][2] = { {"btc","usd"} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -35,12 +41,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","usd"} };
return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,uint64_t nonce,char *path,char *method)
{
/*All REST requests must contain the following headers:
@ -213,17 +213,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs coinbase_funcs = EXCHANGE_FUNCS(coinbase,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef EXCHANGE_AUTHURL
#undef CHECKBALANCE
#include "exchange_undefs.h"

25
iguana/exchanges/exchange_supports.h

@ -0,0 +1,25 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
char *ALLPAIRS(struct exchange_info *exchange,cJSON *argjson)
{
return(jprint(exchanges777_allpairs(BASERELS,(int32_t)(sizeof(BASERELS)/sizeof(*BASERELS))),1));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
return(baserel_polarity(BASERELS,(int32_t)(sizeof(BASERELS)/sizeof(*BASERELS)),base,rel));
}

32
iguana/exchanges/exchange_undefs.h

@ -0,0 +1,32 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef CHECKBALANCE
#undef ALLPAIRS
#undef FUNCS
#undef BASERELS
#undef EXCHANGE_AUTHURL

27
iguana/exchanges/huobi.c

@ -26,6 +26,12 @@
#define PARSEBALANCE huobi ## _parsebalance
#define WITHDRAW huobi ## _withdraw
#define CHECKBALANCE huobi ## _checkbalance
#define ALLPAIRS huobi ## _allpairs
#define FUNCS huobi ## _funcs
#define BASERELS huobi ## _baserels
static char *BASERELS[][2] = { {"btc","cny"}, {"ltc","cny"} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -35,12 +41,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","cny"}, {"ltc","cny"} };
return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload)
{
char *data; cJSON *json;
@ -168,17 +168,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs huobi_funcs = EXCHANGE_FUNCS(huobi,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef CHECKBALANCE
#include "exchange_undefs.h"

30
iguana/exchanges/lakebtc.c

@ -26,6 +26,12 @@
#define PARSEBALANCE lakebtc ## _parsebalance
#define WITHDRAW lakebtc ## _withdraw
#define CHECKBALANCE lakebtc ## _checkbalance
#define ALLPAIRS lakebtc ## _allpairs
#define FUNCS lakebtc ## _funcs
#define BASERELS lakebtc ## _baserels
static char *BASERELS[][2] = { {"btc","usd"}, {"btc","cny"} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -38,15 +44,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","usd"}, {"btc","cny"} };
int32_t polarity;
polarity = baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel);
printf("lakebtc.(%s %s) polarity.%d\n",base,rel,polarity);
return(polarity);
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *hdr1,uint64_t tonce)
{
char hdr2[512],cmdbuf[1024],buf64[1024],hdr3[512],dest[1025],hdr4[512],*sig,*data = 0; cJSON *json;
@ -267,17 +264,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs lakebtc_funcs = EXCHANGE_FUNCS(lakebtc,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef CHECKBALANCE
#include "exchange_undefs.h"

28
iguana/exchanges/okcoin.c

@ -27,6 +27,12 @@
#define WITHDRAW okcoin ## _withdraw
#define EXCHANGE_AUTHURL "https://www.okcoin.com/api/v1"
#define CHECKBALANCE okcoin ## _checkbalance
#define ALLPAIRS okcoin ## _allpairs
#define FUNCS okcoin ## _funcs
#define BASERELS okcoin ## _baserels
static char *BASERELS[][2] = { {"btc","usd"}, {"ltc","usd"} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -44,12 +50,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","usd"}, {"ltc","usd"} };
return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *url,char *payload)
{
char hdr1[512],hdr2[512],hdr3[512],hdr4[512],*data; cJSON *json;
@ -226,18 +226,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs okcoin_funcs = EXCHANGE_FUNCS(okcoin,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef EXCHANGE_AUTHURL
#undef CHECKBALANCE
#include "exchange_undefs.h"

57
iguana/exchanges/poloniex.c

@ -27,13 +27,36 @@
#define WITHDRAW poloniex ## _withdraw
#define EXCHANGE_AUTHURL "https://poloniex.com/tradingApi"
#define CHECKBALANCE poloniex ## _checkbalance
#define ALLPAIRS poloniex ## _allpairs
#define FUNCS poloniex ## _funcs
static char *(*poloniex_baserels)[][2];
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
char *ALLPAIRS(struct exchange_info *exchange,cJSON *argjson)
{
char market[128],url[1024];
sprintf(market,"%s_%s",rel,base);
sprintf(url,"https://poloniex.com/public?command=returnOrderBook&currencyPair=%s&depth=%d",market,maxdepth);
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
static int32_t num;
char *jsonstr,*baserel; int32_t i; cJSON *json;
if ( num == 0 || (*poloniex_baserels) == 0 )
{
jsonstr = issue_curl("https://poloniex.com/public?command=returnTicker");
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (num= cJSON_GetArraySize(json)) != 0 )
{
poloniex_baserels = calloc(num,sizeof(char *) * 2);
for (i=0; i<num; i++)
{
if ( (baserel= get_cJSON_fieldname(jitem(json,i))) != 0 && strncmp(baserel,"BTC_",4) == 0 )
{
(*poloniex_baserels)[i][0] = clonestr(baserel+4);
(*poloniex_baserels)[i][1] = "BTC";
}
}
}
free_json(json);
}
free(jsonstr);
}
return(jprint(exchanges777_allpairs((*poloniex_baserels),num),1));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
@ -49,6 +72,14 @@ int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argj
else return(0);
}
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
char market[128],url[1024];
sprintf(market,"%s_%s",rel,base);
sprintf(url,"https://poloniex.com/public?command=returnOrderBook&currencyPair=%s&depth=%d",market,maxdepth);
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *url,char *payload)
{
char dest[(512>>3)*2+1],hdr1[512],hdr2[512],hdr3[512],hdr4[512],*data,*sig; cJSON *json;
@ -213,18 +244,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs poloniex_funcs = EXCHANGE_FUNCS(poloniex,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef EXCHANGE_AUTHURL
#undef CHECKBALANCE
#include "exchange_undefs.h"

27
iguana/exchanges/quadriga.c

@ -26,6 +26,12 @@
#define PARSEBALANCE quadriga ## _parsebalance
#define WITHDRAW quadriga ## _withdraw
#define CHECKBALANCE quadriga ## _checkbalance
#define ALLPAIRS quadriga ## _allpairs
#define FUNCS quadriga ## _funcs
#define BASERELS quadriga ## _baserels
static char *BASERELS[][2] = { {"btc","usd"}, {"btc","cad"} };
#include "exchange_supports.h"
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson)
{
@ -36,12 +42,6 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0));
}
int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson)
{
char *baserels[][2] = { {"btc","usd"}, {"btc","cad"} };
return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
}
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path)
{
char url[1024],req[1024],md5secret[128],tmp[1024],dest[1025],hdr1[512],hdr2[512],hdr3[512],hdr4[512],*sig,*data = 0;
@ -169,17 +169,4 @@ char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *des
struct exchange_funcs quadriga_funcs = EXCHANGE_FUNCS(quadriga,EXCHANGE_NAME);
#undef UPDATE
#undef SUPPORTS
#undef SIGNPOST
#undef TRADE
#undef ORDERSTATUS
#undef CANCELORDER
#undef OPENORDERS
#undef TRADEHISTORY
#undef BALANCES
#undef PARSEBALANCE
#undef WITHDRAW
#undef EXCHANGE_NAME
#undef CHECKBALANCE
#include "exchange_undefs.h"

3
iguana/exchanges777.h

@ -40,8 +40,9 @@ struct exchange_funcs
char *(*openorders)(struct exchange_info *exchange,cJSON *argjson);
char *(*tradehistory)(struct exchange_info *exchange,cJSON *argjson);
char *(*withdraw)(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson);
char *(*allpairs)(struct exchange_info *exchange,cJSON *argjson);
};
#define EXCHANGE_FUNCS(xchg,name) { name, xchg ## _price, xchg ## _supports, xchg ## _parsebalance, xchg ## _balances, xchg ## _trade, xchg ## _orderstatus, xchg ## _cancelorder, xchg ## _openorders, xchg ## _tradehistory, xchg ## _withdraw }
#define EXCHANGE_FUNCS(xchg,name) { name, xchg ## _price, xchg ## _supports, xchg ## _parsebalance, xchg ## _balances, xchg ## _trade, xchg ## _orderstatus, xchg ## _cancelorder, xchg ## _openorders, xchg ## _tradehistory, xchg ## _withdraw, xchg ## _allpairs }
struct exchange_info
{

33
iguana/iguana_exchanges.c

@ -38,6 +38,21 @@ void prices777_processprice(struct exchange_info *exchange,char *base,char *rel,
}
cJSON *exchanges777_allpairs(char *baserels[][2],int32_t num)
{
int32_t i; char str[32]; cJSON *json,*item,*array = cJSON_CreateArray();
for (i=0; i<num; i++)
{
item = cJSON_CreateArray();
jaddistr(item,uppercase_str(str,baserels[i][0]));
jaddistr(item,uppercase_str(str,baserels[i][1]));
jaddi(array,item);
}
json = cJSON_CreateObject();
jadd(json,"result",array);
return(json);
}
cJSON *exchanges777_quotejson(struct exchange_quote *quote,int32_t allflag,double pricesum,double totalvol)
{
cJSON *json; char str[65];
@ -841,4 +856,22 @@ STRING_AND_INT(InstantDEX,pollgap,exchange,pollgap)
return(clonestr("{\"result\":\"set pollgap\"}"));
} else return(clonestr("{\"error\":\"cant find or create exchange\"}"));
}
ZERO_ARGS(InstantDEX,allexchanges)
{
int32_t i; cJSON *retjson,*array;
retjson = cJSON_CreateObject(); array = cJSON_CreateArray();
for (i=0; i<sizeof(Exchange_names)/sizeof(*Exchange_names); i++)
jaddistr(array,Exchange_names[i]);
jadd(retjson,"result",array);
return(jprint(retjson,1));
}
STRING_ARG(InstantDEX,allpairs,exchange)
{
struct exchange_info *ptr;
if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 )
return((*ptr->issue.allpairs)(ptr,json));
else return(clonestr("{\"error\":\"cant find or create exchange\"}"));
}
#include "../includes/iguana_apiundefs.h"

26
iguana/iguana_instantdex.c

@ -85,13 +85,28 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,cJSON *argjson,char *cmdst
}
}
char *instantdex_reqprice(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen)
char *instantdex_request(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen)
{
char *base,*rel,*request; double volume; int32_t i; struct exchange_info *exchange;
if ( argjson != 0 )
{
return(clonestr("{\"result\":\"reqprice response not sent\"}"));
return(clonestr("{\"result\":\"reqprice response sent\"}"));
} else return(clonestr("{\"error\":\"reqprice needs argjson\"}"));
request = jstr(argjson,"request");
base = jstr(argjson,"base");
rel = jstr(argjson,"rel");
volume = jdouble(argjson,"volume");
if ( base != 0 && rel != 0 && volume > SMALLVAL )
{
for (i=0; i<myinfo->numexchanges; i++)
{
if ( (exchange= myinfo->tradingexchanges[i]) != 0 )
{
}
}
return(clonestr("{\"result\":\"reqprice response sent\"}"));
}
return(clonestr("{\"error\":\"request missing parameter\"}"));
} else return(clonestr("{\"error\":\"request needs argjson\"}"));
}
char *instantdex_proposal(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen)
@ -123,7 +138,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
{
static struct { char *cmdstr; char *(*func)(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen); uint64_t cmdbits; } cmds[] =
{
{ "reqprice", instantdex_reqprice }, { "proposal", instantdex_proposal },
{ "request", instantdex_request }, { "proposal", instantdex_proposal },
{ "accepted", instantdex_accepted }, { "confirmed", instantdex_confirmed },
};
char *retstr = 0; int32_t i; uint64_t cmdbits;
@ -266,6 +281,5 @@ TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(InstantDEX,confirm,reference,message,basetx
} else return(clonestr("{\"error\":\"InstantDEX API confirm only local usage!\"}"));
}
#include "../includes/iguana_apiundefs.h"

6
iguana/iguana_json.c

@ -220,7 +220,7 @@ int32_t agentform(FILE *fp,char *form,int32_t max,char *agent,cJSON *methoditem)
sprintf(&form[size],"<form action=\"http://127.0.0.1:7778/api/%s/%s\" oninput=\"%s\">%s<output for=\"%s\"></output><input type=\"submit\" value=\"%s\"></form>",agent,methodstr,outstr,fields,outstr2,methodstr);
if ( fp != 0 )
fprintf(fp,"%s\n",&form[size]);
printf("%s\n",&form[size]);
//printf("%s\n",&form[size]);
return((int32_t)strlen(form));
}
@ -342,7 +342,7 @@ int32_t pretty_forms(char *fname,char *agentstr)
{
len = pretty_form(fp,formheader,formfooter,field,str!=0?str:"agent",item);
size += len;
printf("%s.%s\n",str,jstr(item,"method"));
//printf("%s.%s\n",str,jstr(item,"method"));
} //else printf("agentstr.%p (%s) (%s) str.%p \n",agentstr,agentstr,str,str);
}
}
@ -367,7 +367,7 @@ char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr)
htmlstr[0] = 0;
if ( pretty_forms(fname,agentstr) != 0 )
{
printf("%s\n",htmlstr);
//printf("%s\n",htmlstr);
return(htmlstr);
}
sprintf(htmlstr,"<!DOCTYPE HTML><html> <head><title>SuperUGLY GUI></title></head> <body> ");

10
iguana/iguana_rpc.c

@ -787,7 +787,6 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
{
if ( (n= cJSON_GetArraySize(tokens)) > 0 )
{
jaddstr(argjson,"agent",jstri(tokens,0));
if ( n > 1 )
{
if ( jstri(tokens,1) != 0 )
@ -838,13 +837,20 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
key = &buf[i];
break;
}
else if ( buf[i] == '+' )
buf[i] = ' ';
}
}
}
}
if ( key != 0 && value != 0 )
jaddstr(argjson,key,value);
} else jaddstr(argjson,"method",buf);
}
else
{
//jdelete(argjson,"method");
//jaddstr(argjson,"method",buf);
}
}
for (i=2; i<n; i++)
{

238
iguana/main.c

@ -276,186 +276,33 @@ void sigchild_func() { printf("\nSIGCHLD\n"); signal(SIGCHLD,sigchild_func); }
void sigalarm_func() { printf("\nSIGALRM\n"); signal(SIGALRM,sigalarm_func); }
void sigcontinue_func() { printf("\nSIGCONT\n"); signal(SIGCONT,sigcontinue_func); }
void iguana_main(void *arg)
void mainloop(struct supernet_info *myinfo)
{
FILE *fp; cJSON *json; uint8_t *space,secretbuf[512]; uint32_t r; long allocsize; bits256 pangeahash;
char helperstr[64],fname[512],*wallet2,*wallet2str,*tmpstr,*confstr,*helperargs,*ipaddr,*coinargs=0,*secret,*jsonstr = arg;
struct supernet_info *myinfo;
int32_t i,len,flag,c; bits256 acct,seed,checkhash,wallethash,walletpub,wallet2shared,wallet2priv,wallet2pub;
myinfo = SuperNET_MYINFO(0);
//iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD
//iguana_chaingenesis(1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN
iguana_chaingenesis(1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC
mycalloc(0,0,0);
//exchanges777_init(0);
iguana_initQ(&helperQ,"helperQ");
OS_ensure_directory("confs");
OS_ensure_directory("DB");
OS_ensure_directory("tmp");
if ( (tmpstr= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"help\"}"),0)) != 0 )
{
if ( (API_json= cJSON_Parse(tmpstr)) != 0 && (API_json= jobj(API_json,"result")) != 0 )
API_json = jobj(API_json,"API");
free(tmpstr);
}
memset(wallet2shared.bytes,0,sizeof(wallet2shared));
wallethash = GENESIS_PRIVKEY;
wallet2pub = GENESIS_PUBKEY;
if ( jsonstr != 0 && (json= cJSON_Parse(jsonstr)) != 0 )
{
printf("ARGSTR.(%s)\n",jsonstr);
if ( jobj(json,"numhelpers") != 0 )
IGUANA_NUMHELPERS = juint(json,"numhelpers");
if ( (secret= jstr(json,"wallet")) != 0 )
{
len = (int32_t)strlen(secret);
if ( is_hexstr(secret,0) != 0 && len == 128 )
{
len >>= 1;
decode_hex(secretbuf,len,secret);
} else vcalc_sha256(0,secretbuf,(void *)secret,len), len = sizeof(bits256);
memcpy(wallethash.bytes,secretbuf,sizeof(wallethash));
char str[65]; printf("wallethash.(%s)\n",bits256_str(str,wallethash));
}
if ( (wallet2= jstr(json,"2fafile")) != 0 )
{
if ( (wallet2str= OS_filestr(&allocsize,wallet2)) != 0 )
{
r = calc_crc32(0,wallet2str,(int32_t)allocsize);
r %= 32;
for (i=0; i<allocsize; i++)
wallet2str[i] ^= wallethash.bytes[(i + r) % 32];
vcalc_sha256(0,wallet2priv.bytes,(void *)wallet2str,(int32_t)allocsize);
wallet2pub = curve25519(wallet2priv,curve25519_basepoint9());
seed = curve25519_shared(wallethash,wallet2pub);
vcalc_sha256(0,wallet2shared.bytes,seed.bytes,sizeof(bits256));
char str[65],str2[65]; printf("have 2fafile.(%s) -> pub.%s shared.%s\n",wallet2,bits256_str(str,wallet2pub),bits256_str(str2,wallet2shared));
free(wallet2str);
}
}
if ( jobj(json,"coins") != 0 )
coinargs = jsonstr;
}
walletpub = curve25519(wallethash,curve25519_basepoint9());
seed = curve25519_shared(wallethash,wallet2pub);
vcalc_sha256(0,wallet2shared.bytes,seed.bytes,sizeof(bits256));
OS_randombytes(myinfo->persistent_priv.bytes,sizeof(myinfo->privkey));
myinfo->myaddr.persistent = curve25519(myinfo->persistent_priv,curve25519_basepoint9());
vcalc_sha256(0,acct.bytes,(void *)myinfo->myaddr.persistent.bytes,sizeof(bits256));
myinfo->myaddr.nxt64bits = acct.txid;
RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits);
if ( bits256_nonz(wallet2shared) > 0 )
sprintf(fname,"confs/iguana.%llu",(long long)wallet2shared.txid);
else sprintf(fname,"confs/iguana.conf");
printf("check conf.(%s)\n",fname);
if ( (confstr= OS_filestr(&allocsize,fname)) != 0 )
{
if ( bits256_nonz(wallet2shared) > 0 )
{
space = malloc(IGUANA_MAXPACKETSIZE);
json = cJSON_Parse(confstr);
//json = SuperNET_bits2json(walletpub,wallet2shared,(uint8_t *)confstr,space,(int32_t)allocsize,1);
free(space);
printf("decoded.(%s)\n",jprint(json,0));
} else json = cJSON_Parse(confstr), printf("CONF.(%s)\n",confstr);
if ( json != 0 )
{
if ( (ipaddr= jstr(json,"ipaddr")) != 0 && is_ipaddr(ipaddr) != 0 )
strcpy(myinfo->ipaddr,ipaddr);
if ( (secret= jstr(json,"secret")) != 0 )
{
myinfo->myaddr.nxt64bits = conv_NXTpassword(myinfo->persistent_priv.bytes,myinfo->myaddr.persistent.bytes,(uint8_t *)secret,(int32_t)strlen(secret));
RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits);
}
else
{
myinfo->persistent_priv = jbits256(json,"persistent_priv");
if ( bits256_nonz(myinfo->persistent_priv) == 0 )
{
printf("null persistent_priv? generate new one\n");
OS_randombytes(myinfo->persistent_priv.bytes,sizeof(myinfo->privkey));
}
myinfo->myaddr.persistent = jbits256(json,"persistent_pub");
checkhash = curve25519(myinfo->persistent_priv,curve25519_basepoint9());
}
free_json(json);
if ( memcmp(checkhash.bytes,myinfo->myaddr.persistent.bytes,sizeof(checkhash)) != 0 )
{
printf("persistent pubkey mismatches one in iguana.conf\n");
myinfo->myaddr.persistent = checkhash;
confstr = 0;
}
} else printf("Cant parse.(%s)\n",confstr), confstr = 0;
if ( confstr != 0 )
free(confstr);
}
else if ( (ipaddr= OS_filestr(&allocsize,"ipaddr")) != 0 )
{
printf("got ipaddr.(%s)\n",ipaddr);
len = (int32_t)strlen(ipaddr) - 1;
while ( len > 8 && ((c= ipaddr[len]) == '\r' || c == '\n' || c == ' ' || c == '\t') )
ipaddr[len] = 0, len--;
printf("got ipaddr.(%s) %x\n",ipaddr,is_ipaddr(ipaddr));
if ( is_ipaddr(ipaddr) != 0 )
{
strcpy(myinfo->ipaddr,ipaddr);
myinfo->myaddr.selfipbits = (uint32_t)calc_ipbits(ipaddr);
}
free(ipaddr);
}
if ( myinfo->myaddr.selfipbits == 0 )
{
strcpy(myinfo->ipaddr,"127.0.0.1");
myinfo->myaddr.selfipbits = (uint32_t)calc_ipbits(myinfo->ipaddr);
}
vcalc_sha256(0,acct.bytes,(void *)myinfo->myaddr.persistent.bytes,sizeof(bits256));
myinfo->myaddr.nxt64bits = acct.txid;
RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits);
char str[65],str2[65]; printf("%s %llu %p PRIV.%s PUB.%s persistent.%llx %llx\n",myinfo->myaddr.NXTADDR,(long long)myinfo->myaddr.nxt64bits,&myinfo->privkey,bits256_str(str,myinfo->privkey),bits256_str(str2,myinfo->myaddr.pubkey),(long long)myinfo->persistent_priv.txid,(long long)myinfo->myaddr.persistent.txid);
if ( confstr == 0 )
struct iguana_helper *ptr; int32_t flag;
while ( 1 )
{
uint8_t *compressed,*serialized; int32_t r,complen,maxsize = IGUANA_MAXPACKETSIZE;
json = cJSON_CreateObject();
jaddstr(json,"agent","SuperNET");
jaddstr(json,"method","saveconf");
jaddstr(json,"myipaddr",myinfo->ipaddr);
jaddbits256(json,"persistent_priv",myinfo->persistent_priv);
jaddbits256(json,"persistent_pub",myinfo->myaddr.persistent);
compressed = calloc(1,maxsize);
serialized = calloc(1,maxsize);
OS_randombytes((void *)&r,sizeof(r));
jadd64bits(json,"rand",r);
char *str = jprint(json,0);
if ( strcmp("confs/iguana.conf",fname) != 0 )
{
//sprintf(fname,"confs/iguana.%llu",(long long)wallet2shared.txid);
//if ( SuperNET_json2bits(myinfo->ipaddr,wallethash,walletpub,wallet2shared,serialized,&complen,compressed,maxsize,myinfo->ipaddr,wallet2pub,json) > 0 )
{
complen = (int32_t)strlen(jprint(json,0));
printf("save (%s) <- %d\n",fname,complen);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(str,1,strlen(str),fp);
//fwrite(compressed,1,complen,fp);
fclose(fp);
}
}// else printf("error saving.(%s) json2bits.(%s)\n",fname,jprint(json,0));
}
else
flag = 0;
iguana_jsonQ();
if ( flag == 0 )
{
//sprintf(fname,"confs/iguana.conf");
printf("save (%s) <- (%s)\n",fname,str);
if ( (fp= fopen(fname,"wb")) != 0 )
if ( (ptr= queue_dequeue(&bundlesQ,0)) != 0 )
{
fwrite(str,1,strlen(str),fp);
fclose(fp);
if ( ptr->bp != 0 && ptr->coin != 0 )
flag += iguana_bundleiters(ptr->coin,ptr->bp,ptr->timelimit);
myfree(ptr,ptr->allocsize);
}
else pangea_queues(SuperNET_MYINFO(0));
}
free(str);
free(compressed), free(serialized);
free_json(json);
if ( flag == 0 )
sleep(1);
}
}
void iguana_main(void *arg)
{
struct supernet_info *myinfo; char *tmpstr,*helperargs,*coinargs,helperstr[512]; int32_t i;
mycalloc(0,0,0);
myinfo = SuperNET_MYINFO(0);
signal(SIGINT,sigint_func);
signal(SIGILL,sigillegal_func);
signal(SIGHUP,sighangup_func);
@ -465,13 +312,22 @@ void iguana_main(void *arg)
signal(SIGCHLD,sigchild_func);
signal(SIGALRM,sigalarm_func);
signal(SIGCONT,sigcontinue_func);
//iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD
//iguana_chaingenesis(1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN
iguana_chaingenesis(1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC
iguana_initQ(&helperQ,"helperQ");
OS_ensure_directory("confs");
OS_ensure_directory("DB");
OS_ensure_directory("tmp");
if ( (tmpstr= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"help\"}"),0)) != 0 )
{
if ( (API_json= cJSON_Parse(tmpstr)) != 0 && (API_json= jobj(API_json,"result")) != 0 )
API_json = jobj(API_json,"API");
free(tmpstr);
}
if ( IGUANA_NUMHELPERS == 0 )
IGUANA_NUMHELPERS = 1;
category_subscribe(&MYINFO,GENESIS_PUBKEY,GENESIS_PUBKEY);
pangeahash = calc_categoryhashes(0,"pangea",0);
category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY);
category_processfunc(pangeahash,pangea_hexmsg);
category_chain_functions(&MYINFO,pangeahash,GENESIS_PUBKEY,sizeof(bits256),sizeof(bits256),0,0,0,0);
for (i=0; i<IGUANA_NUMHELPERS; i++)
{
sprintf(helperstr,"{\"name\":\"helper.%d\"}",i);
@ -479,7 +335,8 @@ void iguana_main(void *arg)
iguana_launch(iguana_coinadd("BTCD"),"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD);
}
iguana_launch(iguana_coinadd("BTCD"),"rpcloop",iguana_rpcloop,SuperNET_MYINFO(0),IGUANA_PERMTHREAD);
if ( coinargs != 0 )
category_init(&MYINFO);
if ( (coinargs= SuperNET_keysinit(&MYINFO,arg)) != 0 )
iguana_launch(iguana_coinadd("BTCD"),"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
else if ( 0 )
{
@ -495,27 +352,6 @@ void iguana_main(void *arg)
}
if ( arg != 0 )
SuperNET_JSON(&MYINFO,cJSON_Parse(arg),0);
//#ifndef MINIGUANA
// iguana_launch(iguana_coinadd("BTCD"),"SuperNET_init",SuperNET_init,&MYINFO,IGUANA_PERMTHREAD);
//#endif
//init_InstantDEX();
while ( 1 )
{
flag = 0;
iguana_jsonQ();
if ( flag == 0 )
{
struct iguana_helper *ptr;
if ( (ptr= queue_dequeue(&bundlesQ,0)) != 0 )
{
if ( ptr->bp != 0 && ptr->coin != 0 )
flag += iguana_bundleiters(ptr->coin,ptr->bp,ptr->timelimit);
myfree(ptr,ptr->allocsize);
}
else pangea_queues(SuperNET_MYINFO(0));
}
if ( flag == 0 )
sleep(1);
}
mainloop(&MYINFO);
}

12
iguana/pnacl/Release/iguana.nmf

@ -1,12 +0,0 @@
{
"program": {
"portable": {
"pnacl-translate": {
"url": "iguana.pexe"
},
"pnacl-debug": {
"url": "iguana_unstripped.bc"
}
}
}
}

BIN
iguana/pnacl/Release/iguana.pexe

Binary file not shown.

5
includes/iguana_apideclares.h

@ -20,6 +20,9 @@ HASH_AND_INT(ramchain,getrawtransaction,txid,verbose);
HASH_ARG(ramchain,gettransaction,txid);
STRING_ARG(ramchain,decoderawtransaction,rawtx);
THREE_STRINGS(InstantDEX,encryptjson,passphrase,permanentfile,anything);
TWO_STRINGS(InstantDEX,decryptjson,passphrase,permanentfile);
THREE_STRINGS_AND_THREE_INTS(InstantDEX,orderbook,exchange,base,rel,depth,allfields,invert);
THREE_STRINGS_AND_THREE_DOUBLES(InstantDEX,buy,exchange,base,rel,price,volume,dotrade);
THREE_STRINGS_AND_THREE_DOUBLES(InstantDEX,sell,exchange,base,rel,price,volume,dotrade);
@ -33,6 +36,8 @@ TWO_STRINGS(InstantDEX,cancelorder,exchange,orderid);
STRING_ARG(InstantDEX,openorders,exchange);
STRING_ARG(InstantDEX,tradehistory,exchange);
STRING_AND_INT(InstantDEX,pollgap,exchange,pollgap);
ZERO_ARGS(InstantDEX,allexchanges);
STRING_ARG(InstantDEX,allpairs,exchange);
THREE_STRINGS_AND_DOUBLE(InstantDEX,request,reference,base,rel,volume);
TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(InstantDEX,proposal,reference,message,basetxid,reltxid,duration,flags);

Loading…
Cancel
Save