Browse Source

Merge pull request #138 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
3e2001730d
  1. 2
      .gitignore
  2. 36
      OSlibs/win/mingw.h
  3. BIN
      OSlibs/win/nanomsg.dll
  4. BIN
      OSlibs/win/nanomsg.lib
  5. BIN
      OSlibs/win/release/nanomsg.dll
  6. BIN
      OSlibs/win/release/nanomsg.lib
  7. BIN
      OSlibs/win/release/pthreadVC2.lib
  8. BIN
      OSlibs/win/release/pthreadvc2.dll
  9. BIN
      OSlibs/win/x64/nanomsg.dll
  10. BIN
      OSlibs/win/x64/nanomsg.lib
  11. BIN
      OSlibs/win/x64/release/nanomsg.dll
  12. BIN
      OSlibs/win/x64/release/nanomsg.lib
  13. 17
      crypto777/OS_nonportable.c
  14. 4
      crypto777/curve25519.c
  15. 17
      crypto777/iguana_OS.c
  16. 2
      crypto777/nanosrc/nn_config.h
  17. 304
      deprecated/STEEM.c
  18. 384
      deprecated/steemit_parser.c
  19. 28
      iguana.sln
  20. 18
      iguana.vcxproj
  21. 1
      iguana.vcxproj.filters
  22. 4
      iguana/dPoW.h
  23. 37
      iguana/dpow/dpow_network.c
  24. 4
      iguana/dpow/dpow_rpc.c
  25. 6
      iguana/dpow/dpow_tx.c
  26. 5
      iguana/iguana777.h
  27. 40
      iguana/iguana_accept.c
  28. 2
      iguana/iguana_bitmap.c
  29. 13
      iguana/iguana_blocks.c
  30. 4
      iguana/iguana_bundles.c
  31. 9
      iguana/iguana_init.c
  32. 4
      iguana/iguana_json.c
  33. 7
      iguana/iguana_mofn.c
  34. 64
      iguana/iguana_peers.c
  35. 29
      iguana/iguana_ramchain.c
  36. 38
      iguana/iguana_tx.c
  37. 10
      iguana/iguana_txidfind.c
  38. 4
      iguana/iguana_unspents.c
  39. 2
      iguana/tests/ratify
  40. 8
      includes/iguana_apideclares.h
  41. 1
      includes/iguana_defines.h
  42. 9
      includes/iguana_funcs.h
  43. 20
      includes/iguana_structs.h

2
.gitignore

@ -1,4 +1,4 @@
x64
*.o *.o
agents/iguana.exe agents/iguana.exe
Debug/* Debug/*

36
OSlibs/win/mingw.h

@ -28,18 +28,52 @@
* are copied from linux man pages. A poll() macro is defined to * are copied from linux man pages. A poll() macro is defined to
* call the version in mingw.c. * call the version in mingw.c.
*/ */
#define POLLIN 0x0001 /* There is data to read */
#define POLLPRI 0x0002 /* There is urgent data to read */ #define POLLPRI 0x0002 /* There is urgent data to read */
#if defined(_M_X64)
/*
* when we are using WSAPoll() with window's struct pollfd struct
* we need to update the value for POLLIN and POLLOUT according to window's
* WSAPoll() return values
* @author - fadedreamz@gmail.com
*/
//TODO: need to update other values to match with WSAPoll() function
#define POLLIN POLLRDNORM | POLLRDBAND /* There is data to read */
#define POLLOUT POLLWRNORM /* Writing now will not block */
#else
#define POLLIN 0x0001 /* There is data to read */
#define POLLOUT 0x0004 /* Writing now will not block */ #define POLLOUT 0x0004 /* Writing now will not block */
#endif
#define POLLERR 0x0008 /* Error condition */ #define POLLERR 0x0008 /* Error condition */
#define POLLHUP 0x0010 /* Hung up */ #define POLLHUP 0x0010 /* Hung up */
#define POLLNVAL 0x0020 /* Invalid request: fd not open */ #define POLLNVAL 0x0020 /* Invalid request: fd not open */
/**
* we want to use mingw provided pollfd if and only if we are compiling this
* in windows 32bit but exclude it when we are compiling it in win 64
*
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*/
#if !defined(_M_X64)
struct pollfd { struct pollfd {
SOCKET fd; /* file descriptor */ SOCKET fd; /* file descriptor */
short events; /* requested events */ short events; /* requested events */
short revents; /* returned events */ short revents; /* returned events */
}; };
#endif
#if defined(_M_X64)
/*
* we want to use the window's poll function if poll() is invoked in win64
* as we are using window's pollfd struct when we are using x64
* @author - fadedreamz@gmail.com
*/
#define poll(x, y, z) WSAPoll(x, y, z)
#else
#define poll(x, y, z) win32_poll(x, y, z) #define poll(x, y, z) win32_poll(x, y, z)
#endif
/* These wrappers do nothing special except set the global errno variable if /* These wrappers do nothing special except set the global errno variable if
* an error occurs (winsock doesn't do this by default). They set errno * an error occurs (winsock doesn't do this by default). They set errno

BIN
OSlibs/win/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/nanomsg.lib

Binary file not shown.

BIN
OSlibs/win/release/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/release/nanomsg.lib

Binary file not shown.

BIN
OSlibs/win/release/pthreadVC2.lib

Binary file not shown.

BIN
OSlibs/win/release/pthreadvc2.dll

Binary file not shown.

BIN
OSlibs/win/x64/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/x64/nanomsg.lib

Binary file not shown.

BIN
OSlibs/win/x64/release/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/x64/release/nanomsg.lib

Binary file not shown.

17
crypto777/OS_nonportable.c

@ -13,6 +13,23 @@
* * * *
******************************************************************************/ ******************************************************************************/
/**
* - we need to include WinSock2.h header to correctly use windows structure
* as the application is still using 32bit structure from mingw so, we need to
* add the include based on checking
*
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*
* @remarks - we need this because in win64 we are using windows provided pollfd structure
* not from the mingw header, so we need to include the windows header
* if we are compiling in windows 64bit
*/
#if defined(_M_X64)
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#endif
#include "OS_portable.h" #include "OS_portable.h"

4
crypto777/curve25519.c

@ -1839,7 +1839,11 @@ uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey
struct acct777_sig checksig; uint64_t signerbits; int32_t datalen; uint8_t *serialized; struct acct777_sig checksig; uint64_t signerbits; int32_t datalen; uint8_t *serialized;
datalen = (int32_t)(sig->allocsize - sizeof(*sig)); datalen = (int32_t)(sig->allocsize - sizeof(*sig));
checksig = *sig; checksig = *sig;
#if defined(_M_X64)
serialized = (uint8_t *)((unsigned char *)sig + sizeof(*sig));
#else
serialized = (uint8_t *)((long)sig + sizeof(*sig)); serialized = (uint8_t *)((long)sig + sizeof(*sig));
#endif
//{ int32_t i; for (i=0; i<datalen; i++) printf("%02x",serialized[i]); printf(" VALIDATE.%d?\n",datalen); } //{ int32_t i; for (i=0; i<datalen; i++) printf("%02x",serialized[i]); printf(" VALIDATE.%d?\n",datalen); }
acct777_sign(&checksig,privkey,pubkey,sig->timestamp,serialized,datalen); acct777_sign(&checksig,privkey,pubkey,sig->timestamp,serialized,datalen);
if ( memcmp(checksig.sigbits.bytes,sig->sigbits.bytes,sizeof(checksig.sigbits)) != 0 ) if ( memcmp(checksig.sigbits.bytes,sig->sigbits.bytes,sizeof(checksig.sigbits)) != 0 )

17
crypto777/iguana_OS.c

@ -217,10 +217,18 @@ static uint64_t _align16(uint64_t ptrval) { if ( (ptrval & 15) != 0 ) ptrval +=
void *myaligned_alloc(uint64_t allocsize) void *myaligned_alloc(uint64_t allocsize)
{ {
void *ptr,*realptr; uint64_t tmp; void *ptr,*realptr; uint64_t tmp;
#if defined(_M_X64)
realptr = mycalloc('A', 1, (uint64_t)(allocsize + 16 + sizeof(realptr)));
#else
realptr = mycalloc('A',1,(long)(allocsize + 16 + sizeof(realptr))); realptr = mycalloc('A',1,(long)(allocsize + 16 + sizeof(realptr)));
#endif
tmp = _align16((long)realptr + sizeof(ptr)); tmp = _align16((long)realptr + sizeof(ptr));
memcpy(&ptr,&tmp,sizeof(ptr)); memcpy(&ptr,&tmp,sizeof(ptr));
#if defined(_M_X64)
memcpy((void *)((unsigned char *)ptr - sizeof(realptr)), &realptr, sizeof(realptr));
#else
memcpy((void *)((long)ptr - sizeof(realptr)),&realptr,sizeof(realptr)); memcpy((void *)((long)ptr - sizeof(realptr)),&realptr,sizeof(realptr));
#endif
//printf("aligned_alloc(%llu) realptr.%p -> ptr.%p, diff.%ld\n",(long long)allocsize,realptr,ptr,((long)ptr - (long)realptr)); //printf("aligned_alloc(%llu) realptr.%p -> ptr.%p, diff.%ld\n",(long long)allocsize,realptr,ptr,((long)ptr - (long)realptr));
return(ptr); return(ptr);
} }
@ -446,7 +454,16 @@ void *iguana_memalloc(struct OS_memspace *mem,long size,int32_t clearflag)
#endif #endif
if ( (mem->used + size) <= mem->totalsize ) if ( (mem->used + size) <= mem->totalsize )
{ {
/*
* solution to calculate memory address in a portable way
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
ptr = (void *)((unsigned char *)mem->ptr + mem->used);
#else
ptr = (void *)(long)(((long)mem->ptr + mem->used)); ptr = (void *)(long)(((long)mem->ptr + mem->used));
#endif
mem->used += size; mem->used += size;
if ( size*clearflag != 0 ) if ( size*clearflag != 0 )
memset(ptr,0,size); memset(ptr,0,size);

2
crypto777/nanosrc/nn_config.h

@ -54,11 +54,13 @@ void PNACL_message(const char* format, ...);
#include <glibc-compat/sys/uio.h> #include <glibc-compat/sys/uio.h>
#include <glibc-compat/sys/un.h> #include <glibc-compat/sys/un.h>
#else #else
#if !defined(WIN32)
//#define NN_ENABLE_EXTRA 1 //#define NN_ENABLE_EXTRA 1
#define PNACL_message printf #define PNACL_message printf
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/un.h> #include <sys/un.h>
#endif #endif
#endif
/* Size of the buffer used for batch-reads of inbound data. To keep the /* Size of the buffer used for batch-reads of inbound data. To keep the
performance optimal make sure that this value is larger than network MTU. */ performance optimal make sure that this value is larger than network MTU. */

304
deprecated/STEEM.c

@ -0,0 +1,304 @@
/******************************************************************************
* Copyright © 2016 jl777 *
* ALL RIGHTS RESERVED *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#ifndef __APPLE__
#include "../iguana/iguana777.h"
#else
#include "iguana777.h"
#endif
#define STEEMIT_PLANKTON 0
#define STEEMIT_MINNOW_BALANCE 100
#define STEEMIT_MINNOW 1
#define STEEMIT_DOLPHIN_BALANCE 1000
#define STEEMIT_DOLPHIN 2
#define STEEMIT_WHALE_BALANCE 100000
#define STEEMIT_WHALE 3
#define STEEMIT_MEGAWHALE_BALANCE 1000000
#define STEEMIT_MEGAWHALE 4
#include "postingkeys.c"
#define rand_account() postingkeys[rand() % (sizeof(postingkeys)/sizeof(*postingkeys))][0]
struct vote_totals { char name[16]; uint32_t whale,nonwhale,whale_for_whale,whale_for_nonwhale,nonwhale_for_whale,nonwhale_for_nonwhale,whale_selfvote,nonwhale_selfvote; };
struct steemit_word { UT_hash_handle hh; int score,ind; char wordpair[]; };
struct steemit_vote { UT_hash_handle hh; double payout; char permlink[]; };
struct steemit_whale { UT_hash_handle hh; double stake; char whale[]; };
struct steemit_post { UT_hash_handle hh; double author_steempower,tallypower[STEEMIT_MEGAWHALE+1]; uint32_t height,author_type,tally[STEEMIT_MEGAWHALE+1]; char key[]; };
void steemit_vote(int32_t height,int32_t ind,int32_t j,cJSON *json);
void steemit_comment(int32_t height,int32_t ind,int32_t j,cJSON *json,int32_t activeflag);
struct upvote_info
{
char upvoter[64],*author,*permlink,*voters[1000];
int32_t numvoters,whaleids[1000]; double weights[1000]; uint32_t starttime;
};
#define issue_IGUANA(url) bitcoind_RPC(0,"curl",url,0,0,0)
void *curl_post(void **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3);
int32_t USE_JAY,Startheight;
char *STEEM_getstate(char *category)
{
static void *cHandle;
char params[1024],url[512],*retstr;
if ( category == 0 )
category = "";
sprintf(url,"http://127.0.0.1:8090");
sprintf(params,"{\"id\":%llu,\"method\":\"call\",\"params\":[\"database_api\", \"get_state\", [\"%s\"]]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),category);
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
return(retstr);
}
char *STEEM_getblock(int32_t height)
{
static void *cHandle;
char params[1024],url[512],*retstr;
sprintf(url,"http://127.0.0.1:8090");
sprintf(params,"{\"id\":%llu,\"method\":\"call\",\"params\":[\"database_api\", \"get_block\", [%d]]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),height);
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
return(retstr);
}
char *STEEM_vote(char *voter,char *author,char *permalink,int8_t wt,int32_t forceflag)
{
static void *cHandle; static portable_mutex_t mutex;
char params[1024],url[512],*retstr;
if ( cHandle == 0 )
portable_mutex_init(&mutex);
if ( strcmp(voter,"jl777") != 0 && strcmp(voter,"taker") != 0 && strcmp(voter,"karen13") != 0 && strcmp(voter,"proto") != 0 && strcmp(voter,"yefet") != 0 )
{
printf("OVERRIDE: only jl777 upvotes %s.(%s %s)\n",voter,author,permalink);
return(clonestr("{\"error\":\"override and dont vote\"}"));
}
if ( forceflag == 0 && strncmp(permalink,"re-",3) == 0 )//&& (strcmp(voter,"jl777") == 0 || strcmp(voter,"taker") == 0) )
{
printf("OVERRIDE: no upvoting on comments.(%s %s)\n",author,permalink);
return(clonestr("{\"error\":\"override and dont vote\"}"));
}
portable_mutex_lock(&mutex);
if ( wt > 100 )
wt = 100;
else if ( wt < -100 )
wt = -100;
sprintf(url,"http://127.0.0.1:8091");
sprintf(params,"{\"id\":%llu,\"method\":\"vote\",\"params\":[\"%s\", \"%s\", \"%s\", %d, true]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),voter,author,permalink,wt);
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
portable_mutex_unlock(&mutex);
return(retstr);
}
char *STEEM_getcontent(char *author,char *permalink)
{
static void *cHandle;
char params[1024],url[512],*retstr;
sprintf(url,"http://127.0.0.1:8090");
sprintf(params,"{\"id\":%llu,\"method\":\"get_content\",\"params\":[\"%s\", \"%s\"]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),author,permalink);
//printf("(%s %s) -> (%s)\n",author,permalink,params);
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
return(retstr);
}
char *STEEM_getcomments(char *author,char *permalink)
{
static void *cHandle;
char params[1024],url[512],*retstr;
sprintf(url,"http://127.0.0.1:8090");
sprintf(params,"{\"id\":%llu,\"method\":\"get_content_replies\",\"params\":[\"%s\", \"%s\"]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),author,permalink);
//printf("(%s %s) -> (%s)\n",author,permalink,params);
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
return(retstr);
}
char *STEEM_accountinfo(char *author)
{
static void *cHandle;
char params[1024],url[512],*retstr;
sprintf(url,"http://127.0.0.1:8091");
sprintf(params,"{\"id\":%llu,\"method\":\"get_account\",\"params\":[\"%s\"]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),author);
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
return(retstr);
}
int32_t permalink_str(char *permalink,int32_t size,char *str)
{
int32_t i,c;
for (i=0; str[i]!=0 && i<size-1; i++)
{
if ( (c= str[i]) == 0 )
break;
if ( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') )
{
} else c = '-';
permalink[i] = tolower(c);
}
permalink[i] = 0;
return(i);
}
char *STEEM_comment(char *author,char *usepermalink,char *parent,char *parentpermalink,char *title,char *body,char *tag)
{
/*post_comment(string author, string permlink, string parent_author, string parent_permlink, string title, string body, string json, bool broadcast)
"parent_author": "",
"parent_permlink": "introduceyourself",
"author": "jl777",
"permlink": "steemit-is-crypto-s-first-mass-market-solution",
"title": "steemit is crypto's first mass market solution!",
"body": "test post"
"json_metadata": "{\"tags\":[\"introduceyourself\",\"blockchain\",\"bitcoin\",\"networking\",\"iguana\",\"supernet\",\"bitcoindark\",\"\"],\"links\":[\"https://bitco.in/forum/forums/iguana.23/\"]}"
curl --url "http://127.0.0.1:8091" --data "{\"id\":444,\"method\":\"post_comment\",\"params\":[\"taker\", \"test-title\", \"\", \"introduceyourself\", \"test title\", \"test body\", \"{\\\"tags\\\":[\\\"introduceyourself\\\", \\\"test\\\", \\\"\\\"]}\", true]}"*/
static void *cHandle;
char *params,permalink[4096],url[512],*retstr;
params = malloc(1024*1024*10);
if ( parent != 0 && parent[0] != 0 && strlen(parentpermalink)+strlen(parent)+8 < sizeof(permalink) )
{
if ( usepermalink != 0 )
strcpy(permalink,usepermalink);
else sprintf(permalink,"re-%s-%s-r%d",parent,parentpermalink,rand() & 0x7fffffff);
}
else permalink_str(permalink,sizeof(permalink),title);
sprintf(url,"http://127.0.0.1:8091");
if ( tag != 0 )
sprintf(params,"{\"id\":%llu,\"method\":\"post_comment\",\"params\":[\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"{\\\"tags\\\":[\\\"%s\\\", \\\"steem\\\", \\\"steemit\\\", \\\"test\\\", \\\"\\\"]}\", true]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),author,permalink,parent,parentpermalink,title,body,tag); //\\\"introduceyourself\\\",
else sprintf(params,"{\"id\":%llu,\"method\":\"post_comment\",\"params\":[\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"{}\", true]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),author,permalink,parent,parentpermalink,title,body);
//printf("ABOUT TO POST.(%s)\n",params), getchar();
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
free(params);
//printf("got.(%s)\n",retstr);
return(retstr);
}
char *STEEM_post(char *author,char *title,char *body,char *tag)
{
return(STEEM_comment(author,0,"",tag!=0?tag:"steemit",title,body,tag));
}
char *STEEM_gethistory(char *account,int32_t firsti,int32_t num)
{
static void *cHandle;
char params[1024],url[512],*retstr;
sprintf(url,"http://127.0.0.1:8090");
sprintf(params,"{\"id\":%llu,\"method\":\"get_account_history\",\"params\":[\"%s\", %d, %d]}",(long long)(time(NULL)*1000 + ((int32_t)OS_milliseconds() % 1000)),account,firsti,num);
retstr = curl_post(&cHandle,url,"",params,0,0,0,0);
//printf("(%s) -> (%s)\n",params,retstr);
return(retstr);
}
char *IGUANA_request(char *agent,char *method,cJSON *argjson)
{
static void *cHandle;
char *argstr=0,*retstr,url[512];
if ( argjson != 0 )
argstr = jprint(argjson,0);
sprintf(url,"http://127.0.0.1:7778/api/%s/%s",agent,method);
retstr = curl_post(&cHandle,url,"",argstr,0,0,0,0);
if ( argstr != 0 )
free(argstr);
return(retstr);
}
int32_t special_account(char *account)
{
int32_t i;
if ( strcmp("jl777",account) == 0 || strcmp("upvotes",account) == 0 || strcmp("taker",account) == 0 )
return(1);
for (i=0; i<sizeof(postingkeys)/sizeof(*postingkeys); i++)
{
if ( strcmp(account,postingkeys[i][0]) == 0 )
return(1);
}
return(0);
}
int32_t steemit_dereference(char *_author,char *_permlink)
{
char *retstr,author[512],permlink[4096]; cJSON *retjson,*result; int32_t depth = 0;
safecopy(author,_author,sizeof(author));
safecopy(permlink,_permlink,sizeof(permlink));
while ( author[0] != 0 && depth++ < 5 )
{
if ( (retstr= STEEM_getcontent(author,permlink)) != 0 )
{
//printf("(%s %s) -> (%s)\n",author,permlink,retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (result= jobj(retjson,"result")) != 0 )
{
safecopy(author,jstr(result,"parent_author"),sizeof(author));
safecopy(permlink,jstr(result,"parent_permlink"),sizeof(permlink));
if ( author[0] != 0 )
{
strcpy(_author,author);
strcpy(_permlink,permlink);
}
} else author[0] = 0;
free_json(retjson);
}
free(retstr);
}
}
return(depth);
}
int32_t steemit_body(char *buf,int32_t size,char *author,char *permlink)
{
char *retstr,*body; cJSON *retjson,*result; int32_t len = 0;
if ( (retstr= STEEM_getcomments(author,permlink)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (result= jobj(retjson,"result")) != 0 )
{
if ( (body= jstr(result,"body")) != 0 )
{
if ( (len= (int32_t)strlen(body)) > size )
len = size;
strncpy(buf,body,len);
}
}
free_json(retjson);
}
free(retstr);
}
return(len);
}
int32_t steemit_power(double *powerp,char *author)
{
char *retstr; cJSON *retjson,*result; double steempower; int32_t retval = 0;
*powerp = 0.;
if ( (retstr= STEEM_accountinfo(author)) != 0 )
{
//printf("power.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (result= jobj(retjson,"result")) != 0 )
{
*powerp = steempower = jdouble(result,"vesting_shares") * .001;
if ( steempower >= STEEMIT_MINNOW_BALANCE )
{
if ( steempower >= STEEMIT_DOLPHIN_BALANCE )
{
if ( steempower >= STEEMIT_WHALE_BALANCE )
{
if ( steempower >= STEEMIT_MEGAWHALE_BALANCE )
retval = STEEMIT_MEGAWHALE;
else retval = STEEMIT_WHALE;
} else retval = STEEMIT_DOLPHIN;
} else retval = STEEMIT_MINNOW;
} else retval = STEEMIT_PLANKTON;
//printf("%s type.%d %.3f\n",author,retval,steempower);
} else printf("(%s) -> no result.(%s)\n",author,retstr);
free_json(retjson);
}
free(retstr);
}
return(retval);
}

384
deprecated/steemit_parser.c

@ -0,0 +1,384 @@
/******************************************************************************
* Copyright © 2016 jl777 *
* ALL RIGHTS RESERVED *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
int32_t init_startheight(int32_t startheight)
{
long filesize; int32_t height; char *heightstr;
if ( (heightstr= OS_filestr(&filesize,TRADEBOT_NAME)) != 0 )
{
height = atoi(heightstr);
free(heightstr);
if ( height > 0 && height < startheight )
startheight = height;
}
return(startheight);
}
void steemit_history_limitorder(int32_t ind,char *acount,cJSON *opitem)
{
// hwm.12081 flag.1 limit_order_create ({"owner":"taker","orderid":1469136578,"amount_to_sell":"24.346 SBD","min_to_receive":"7.770 STEEM","fill_or_kill":false,"expiration":"2016-07-24T23:21:24"})
}
void steemit_update_inventory(double *SBD,double *SBDVOL,double *STEEMVOL,double *STEEM,double myvol,char *mycoin,char *other,double othervol,char *othercoin)
{
if ( strcmp(mycoin,"SBD") == 0 && strcmp(othercoin,"STEEM") == 0 )
{
*SBD -= myvol;
*SBDVOL += myvol;
*STEEM += othervol;
*STEEMVOL += othervol;
}
else if ( strcmp(mycoin,"STEEM") == 0 && strcmp(othercoin,"SBD") == 0 )
{
*STEEM -= myvol;
*STEEMVOL += myvol;
*SBD += othervol;
*SBDVOL += othervol;
} else printf("steemit_update_inventory: unexpected pair (%s) (%s)\n",mycoin,othercoin);
}
void steemit_history_fillorder(int32_t ind,char *account,cJSON *opitem)
{
static double SBD,STEEM,SBDVOL,STEEMVOL;
char *taker,*maker,*takercoin,*makercoin; uint64_t openorderid,fillorderid; double takervol,makervol;
taker = jstr(opitem,"current_owner");
fillorderid = j64bits(opitem,"current_orderid");
takercoin = jstr(opitem,"current_pays");
maker = jstr(opitem,"open_owner");
openorderid = j64bits(opitem,"open_orderid");
makercoin = jstr(opitem,"open_pays");
if ( taker != 0 && maker != 0 && takercoin != 0 && makercoin != 0 && (strcmp(account,taker) == 0 || strcmp(maker,account) == 0) )
{
takervol = atof(takercoin);
while ( *takercoin != 0 && *takercoin != ' ' )
takercoin++;
makervol = atof(makercoin);
while ( *makercoin != 0 && *makercoin != ' ' )
makercoin++;
if ( strcmp(taker,account) == 0 )
{
steemit_update_inventory(&SBD,&SBDVOL,&STEEMVOL,&STEEM,takervol,takercoin+1,maker,makervol,makercoin+1);
printf("%6d %s.(%.6f%s) <-> %s.(%.6f%s) SBD %.6f STEEM %.6f | VOL SBD %.6f STEEM %.6f-> %.6f\n",ind,taker,takervol,takercoin,maker,makervol,makercoin,SBD,STEEM,SBDVOL,STEEMVOL,SBD/STEEM);
}
else
{
steemit_update_inventory(&SBD,&SBDVOL,&STEEMVOL,&STEEM,takervol,takercoin+1,maker,makervol,makercoin+1);
printf("%6d %s.(%.6f%s) <-> %s.(%.6f%s) SBD %.6f STEEM %.6f | VOL SBD %.6f STEEM %.6f-> %.6f\n",ind,maker,makervol,makercoin,taker,takervol,takercoin,SBD,STEEM,SBDVOL,STEEMVOL,SBD/STEEM);
}
}
//hwm.12077 flag.1 fill_order ({"current_owner":"enki","current_orderid":3402053187,"current_pays":"19.613 SBD","open_owner":"taker","open_orderid":1469136521,"open_pays":"5.792 STEEM"})
}
void steemit_tradehistory(char *account)
{
int32_t j,n,m,ind,flag = 1,hwm = 0; cJSON *retjson,*result,*item,*oparray,*opitem; char *opstr,*retstr;
while ( flag != 0 )
{
flag = 0;
if ( (retstr= STEEM_gethistory(account,hwm+1,1)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (result= jarray(&n,retjson,"result")) != 0 )
{
for (j=0; j<n; j++)
{
item = jitem(result,j);
if ( is_cJSON_Array(item) != 0 && cJSON_GetArraySize(item) == 2 )
{
ind = jdouble(jitem(item,0),0);
//printf("ind.%d from %s\n",ind,jprint(jitem(item,0),0));
if ( ind == hwm )
{
if ( (oparray= jarray(&m,jitem(item,1),"op")) != 0 && m == 2 )
{
opstr = jstr(jitem(oparray,0),0);
opitem = jitem(oparray,1);
if ( strcmp(opstr,"limit_order_create") == 0 )
steemit_history_limitorder(hwm,account,opitem);
else if ( strcmp(opstr,"fill_order") == 0 )
steemit_history_fillorder(hwm,account,opitem);
else printf("hwm.%d flag.%d %s (%s)\n",hwm,flag,opstr,jprint(opitem,0));
} else printf("unexpected oparray item.%d j.%d (%s)\n",hwm,j,jprint(jitem(item,1),0));
hwm++;
flag++;
} else printf("skip ind.%d when hwm.%d\n",ind,hwm);
} else printf("unexpected item.%d j.%d (%s)\n",hwm,j,jprint(item,0));
}
} else printf("no result in (%s)\n",retstr);
free(retjson);
} else printf("error.(%s)\n",retstr);
free(retstr);
} else printf("null return for hwm.%d\n",hwm);
}
}
void steemit_pow(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3417584.1: limit_order_create.({"owner":"taker","orderid":1469129923,"amount_to_sell":"7.770 STEEM","min_to_receive":"25.367 SBD","fill_or_kill":false,"expiration":"2016-07-23T14:20:23"})
}
void steemit_transfer(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3417584.0: transfer.({"from":"lukestokes","to":"benslayton","amount":"100.000 SBD","memo":"Dude, you're awesome. No need to give back as your rewards are all you. You worked hard on your post and it was perfectly timed. You deserve every bit of the reward you got! :)"})
}
void steemit_limitorder(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3417584.1: limit_order_create.({"owner":"taker","orderid":1469129923,"amount_to_sell":"7.770 STEEM","min_to_receive":"25.367 SBD","fill_or_kill":false,"expiration":"2016-07-23T14:20:23"})
}
void steemit_cancelorder(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3418230.1.0: limit_order_cancel.({"owner":"kujira","orderid":1469194992})
}
void steemit_accountupdate(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3417791.3: account_update.({"account":"hello","owner":{"weight_threshold":2,"account_auths":[["xeroc", 1]],"key_auths":[["STM8GkRiob5ErhxZgaVv7a3tCGUy14Kp2D3zL69LcpHpgnLxDoTTi", 1]]},"active":{"weight_threshold":1,"account_auths":[["xeroc", 1]],"key_auths":[["STM7WkgYMEfMrteCD1e5VyPGu6VbgYa95Q9xRjdQs8M8PgJ1QdQie", 1]]},"posting":{"weight_threshold":1,"account_auths":[["xeroc", 1]],"key_auths":[["STM6YMtZfg7AsiXdxHjZu7CpYBveLjSKQKgw9bcSUsePuWSMk1xTb", 1]]},"memo_key":"STM8MhWjF83aovRRyMVmFeSbiSXfWEyqMhxocvDoSri8MxAdTojWZ","json_metadata":""})
}
void steemit_convert(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3418042.8.0: convert.({"owner":"oliverb","requestid":1469194981,"amount":"1.090 SBD"})
}
void steemit_powerup(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3418105.2.0: transfer_to_vesting.({"from":"jed78","to":"jed78","amount":"2.600 STEEM"})
}
void steemit_deletecomment(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3417632.0: delete_comment.({"author":"cass","permlink":"re-isteemit-re-summon-re-isteemit-and-hours-later-the-steemit-theme-music-is-finally-here-20160722t132137767z"})
}
void steemit_customjson(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
// 3418087.5.0: custom_json.({"required_auths":[],"required_posting_auths":["sictransitgloria"],"id":"follow","json":"{\"follower\":\"sictransitgloria\",\"following\":\"johnsmith\",\"what\":[\"blog\"]}"})
}
void steemit_powerdown(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
}
void steemit_feedpublish(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
}
void steemit_accountwitness(int32_t height,int32_t ind,int32_t j,cJSON *json)
{
}
void iguana_accounts(char *keytype)
{
long filesize; cJSON *json,*array,*item,*posting,*auths,*json2; int32_t i,n,m; char *str,*str2,*postingkey,*name,*key,fname[128],cmd[512]; FILE *postingkeys;
if ( (str= OS_filestr(&filesize,"accounts.txt")) != 0 )
{
if ( (json= cJSON_Parse(str)) != 0 )
{
if ( (array= jarray(&n,json,"result")) != 0 && (postingkeys= fopen("keys.c","wb")) != 0 )
{
fprintf(postingkeys,"char *%skeys[][2] = {\n",keytype);
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (name= jstr(item,"name")) != 0 && (posting= jobj(item,keytype)) != 0 )
{
if ( (auths= jarray(&m,posting,"key_auths")) != 0 )
{
item = jitem(auths,0);
if ( is_cJSON_Array(item) != 0 && (key= jstri(item,0)) != 0 )
{
sprintf(fname,"/tmp/%s",name);
sprintf(cmd,"curl --url \"http://127.0.0.1:8091\" --data \"{\\\"id\\\":444,\\\"method\\\":\\\"get_private_key\\\",\\\"params\\\":[\\\"%s\\\"]}\" > %s",key,fname);
system(cmd);
if ( (str2= OS_filestr(&filesize,fname)) != 0 )
{
if ( (json2= cJSON_Parse(str2)) != 0 )
{
if ( (postingkey= jstr(json2,"result")) != 0 )
{
//miner = ["supernet", "5J4gTpk4CMBdPzgaRj7yNXDZTzBBQ41bNyJTqHbBi7Ku6v75bXa"]
//fprintf(postingkeys,"miner = [\"%s\", \"%s\"]\n",name,postingkey);
fprintf(postingkeys,"witness = \"%s\"\n",name);
//fprintf(postingkeys,"{ \"%s\", \"%s\" },",name,postingkey);
}
else printf("no result in (%s)\n",jprint(json2,0));
free_json(json2);
} else printf("couldnt parse (%s)\n",str2);
free(str2);
} else printf("couldnt load (%s)\n",fname);
}
}
}
}
fprintf(postingkeys,"\n};\n");
fclose(postingkeys);
}
free_json(json);
}
free(str);
}
}
void tradebots_LP(char *configjsonstr,char *arg)
{
char *retstr,*cmdstr; int32_t i,tallymode=0,repeat,lastheight=0,j,n,one,height = -1; cJSON *obj,*json,*operations,*item,*retjson,*result,*props,*transactions;
if ( configjsonstr != 0 && (json= cJSON_Parse(configjsonstr)) != 0 )
{
// process config
free_json(json);
}
strcpy(Articles.name,"Articles");
strcpy(Comments.name,"Comments");
strcpy(Votes.name,"Votes");
if ( (retstr= STEEM_getstate(0)) == 0 )
return;
for (i=0; i<sizeof(Whales)/sizeof(*Whales); i++)
whale_search(1,Whales[i]);
if ( arg != 0 )
{
if ( strcmp(arg,"taker") == 0 )
{
steemit_tradehistory("taker");
return;
}
else if ( strcmp(arg,"active") == 0 )
{
iguana_accounts("active");
return;
}
if ( strcmp(arg,"tally") == 0 )
tallymode = 1;
}
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (result= jobj(retjson,"result")) != 0 )
{
if ( (props= jobj(result,"props")) != 0 )
{
if ( jobj(props,"head_block_number") != 0 )
height = juint(props,"head_block_number");
}
}
free_json(retjson);
}
//printf("ht.%d retstr.(%s)\n",height,retstr);
free(retstr);
printf("Start %s from %d instead, tallymode.%d\n",TRADEBOT_NAME,height,tallymode);
Startheight = init_startheight(height);
if ( tallymode != 0 )
height = (Startheight - 24*30*3600/3);
while ( height >= 0 )
{
if ( tallymode != 0 && height == Startheight )
{
printf("reached Startheight.%d, getchar()\n",Startheight);
steemit_summary(Startheight);
getchar();
exit(0);
}
if ( (retstr= STEEM_getblock(height)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (result= jobj(retjson,"result")) != 0 )
{
if ( (transactions= jarray(&n,result,"transactions")) != 0 )
{
if ( tallymode == 0 )
printf("lag.%d ht.%d n.%d\n",height-Startheight,height,n);
for (i=0; i<n; i++)
{
item = jitem(transactions,i);
if ( (operations= jarray(&one,item,"operations")) != 0 )
{
if ( 0 && tallymode == 0 )
printf("one.%d: ",one);
for (j=0; j<one; j++)
{
item = jitem(operations,j);
if ( is_cJSON_Array(item) != 0 && cJSON_GetArraySize(item) == 2 )
{
cmdstr = jstr(jitem(item,0),0);
obj = jitem(item,1);
if ( cmdstr != 0 && obj != 0 )
{
//printf("%s ",jprint(item,0));
if ( 0 && tallymode == 0 )
printf("%d %s\n",j,cmdstr);
if ( strcmp("vote",cmdstr) == 0 )
steemit_vote(height,i,j,obj);
else if ( (tallymode != 0 || height >= Startheight) && strcmp("comment",cmdstr) == 0 )
steemit_comment(height,i,j,obj,height >= Startheight);
else if ( height >= Startheight )
{
if ( strcmp("limit_order_create",cmdstr) == 0 )
steemit_limitorder(height,i,j,obj);
else if ( strcmp("convert",cmdstr) == 0 )
steemit_convert(height,i,j,obj);
else if ( strcmp("custom_json",cmdstr) == 0 )
steemit_customjson(height,i,j,obj);
else if ( strcmp("transfer_to_vesting",cmdstr) == 0 )
steemit_powerup(height,i,j,obj);
else if ( strcmp("account_update",cmdstr) == 0 )
steemit_accountupdate(height,i,j,obj);
else if ( strcmp("transfer",cmdstr) == 0 )
steemit_transfer(height,i,j,obj);
else if ( strcmp("limit_order_cancel",cmdstr) == 0 )
steemit_cancelorder(height,i,j,obj);
else if ( strcmp("delete_comment",cmdstr) == 0 )
steemit_deletecomment(height,i,j,obj);
else if ( strcmp("pow",cmdstr) == 0 )
steemit_pow(height,i,j,obj);
else if ( strcmp("feed_publish",cmdstr) == 0 )
steemit_feedpublish(height,i,j,obj);
else if ( strcmp("withdraw_vesting",cmdstr) == 0 )
steemit_powerdown(height,i,j,obj);
else if ( strcmp("account_witness_vote",cmdstr) == 0 )
steemit_accountwitness(height,i,j,obj);
else printf("%d.%d.%d: %s.(%s)\n",height,i,j,cmdstr,jprint(obj,0));
}
} else printf("%d.%d: unexpected paired item.(%s)\n",height,i,jprint(item,0));
} else printf("%d.%d: unexpected unpaired item.(%s)\n",height,i,jprint(item,0));
}
}
}
} else if ( is_cJSON_Null(result) == 0 && jstr(result,"previous") == 0 )
printf("ht.%d no transactions in result.(%s)\n",height,jprint(result,0));
if ( is_cJSON_Null(result) == 0 )
{
FILE *fp;
if ( (fp= fopen(TRADEBOT_NAME,"wb")) != 0 )
{
// printf("startheight.%d for %s\n",height,TRADEBOT_NAME);
fprintf(fp,"%d\n",height);
fclose(fp);
} else printf("error saving startheight.%d for %s\n",height,TRADEBOT_NAME);
height++, repeat = 0;
if ( 0 && tallymode != 0 && (height % 1000) == 0 )
disp_vote_totals(height);
}
} else printf("ht.%d no result in (%s)\n",height,jprint(retjson,0));
//printf("ht.%d blockstr.(%s)\n",height,retstr);
free_json(retjson);
} else printf("ht.%d couldnt parse.(%s)\n",height,retstr);
free(retstr);
} else printf("error getting ht.%d\n",height);
if ( height >= Startheight )
sleep(1);
if ( height == lastheight && ++repeat > 3 )
height++, repeat = 0, lastheight = height;
#ifdef __APPLE__
continue;
#endif
}
printf("done whale watching, hope you enjoyed the show\n");
}

28
iguana.sln

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "iguana", "iguana.vcxproj", "{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x64.ActiveCfg = Debug|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x64.Build.0 = Debug|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x86.ActiveCfg = Debug|Win32
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Debug|x86.Build.0 = Debug|Win32
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x64.ActiveCfg = Release|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x64.Build.0 = Release|x64
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x86.ActiveCfg = Release|Win32
{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

18
iguana.vcxproj

@ -92,11 +92,13 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment> <StructMemberAlignment>1Byte</StructMemberAlignment>
<AdditionalIncludeDirectories>.\iguana;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\iguana;.\OSlibs\win;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -105,12 +107,14 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;NATIVE_WINDOWS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment> <StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>.\OSlibs\win\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>pthread_lib.lib;Ws2_32.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -122,13 +126,15 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\OSlibs\win\release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -140,7 +146,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN64;_WIN64;_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN64;_WIN64;_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>1Byte</StructMemberAlignment>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
@ -148,7 +154,8 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;Advapi32.lib;$(SolutionDir)OSlibs\win\x64\pthread_lib.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Ws2_32.lib;Advapi32.lib;$(SolutionDir)OSlibs\win\x64\pthread_lib.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\OSlibs\win\x64\release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
@ -260,6 +267,7 @@
<ClCompile Include="iguana\iguana_json.c" /> <ClCompile Include="iguana\iguana_json.c" />
<ClCompile Include="iguana\iguana_mofn.c" /> <ClCompile Include="iguana\iguana_mofn.c" />
<ClCompile Include="iguana\iguana_msg.c" /> <ClCompile Include="iguana\iguana_msg.c" />
<ClCompile Include="iguana\iguana_notary.c" />
<ClCompile Include="iguana\iguana_passport.c" /> <ClCompile Include="iguana\iguana_passport.c" />
<ClCompile Include="iguana\iguana_payments.c" /> <ClCompile Include="iguana\iguana_payments.c" />
<ClCompile Include="iguana\iguana_peers.c" /> <ClCompile Include="iguana\iguana_peers.c" />

1
iguana.vcxproj.filters

@ -102,6 +102,7 @@
<ClCompile Include="iguana\secp256k1\src\secp256k1.c" /> <ClCompile Include="iguana\secp256k1\src\secp256k1.c" />
<ClCompile Include="iguana\SuperNET_keys.c" /> <ClCompile Include="iguana\SuperNET_keys.c" />
<ClCompile Include="OSlibs\win\mingw.c" /> <ClCompile Include="OSlibs\win\mingw.c" />
<ClCompile Include="iguana\iguana_notary.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="basilisk\basilisk.h" /> <ClInclude Include="basilisk\basilisk.h" />

4
iguana/dPoW.h

@ -22,7 +22,7 @@
#define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 11) #define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 11)
//#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1) //#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
#define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries) #define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries)
#define DPOW_VERSION 0x0771 #define DPOW_VERSION 0x0772
#define DPOW_UTXOSIZE 10000 #define DPOW_UTXOSIZE 10000
#define DPOW_MINOUTPUT 6000 #define DPOW_MINOUTPUT 6000
#define DPOW_DURATION 300 #define DPOW_DURATION 300
@ -70,7 +70,7 @@ struct dpow_entry
{ {
bits256 commit,beacon,ratifysrcutxo,ratifydestutxo; bits256 commit,beacon,ratifysrcutxo,ratifydestutxo;
uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask,bestmask,ratifyrecvmask,ratifybestmask; uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask,bestmask,ratifyrecvmask,ratifybestmask;
int32_t height; uint32_t pendingcrcs[2]; int32_t height; uint32_t pendingcrcs[2],paxwdcrc;
uint16_t ratifysrcvout,ratifydestvout; uint16_t ratifysrcvout,ratifydestvout;
int8_t bestk,ratifybestk; int8_t bestk,ratifybestk;
uint8_t pubkey[33],ratifysigs[2][DPOW_MAXSIGLEN],ratifysiglens[2]; uint8_t pubkey[33],ratifysigs[2][DPOW_MAXSIGLEN],ratifysiglens[2];

37
iguana/dpow/dpow_network.c

@ -185,7 +185,7 @@ struct dpow_nanoutxo
{ {
bits256 srcutxo,destutxo; bits256 srcutxo,destutxo;
uint64_t bestmask,recvmask; uint64_t bestmask,recvmask;
uint32_t pendingcrcs[2]; uint32_t pendingcrcs[2],paxwdcrc;
uint16_t srcvout,destvout; uint16_t srcvout,destvout;
uint8_t sigs[2][DPOW_MAXSIGLEN],siglens[2],bestk,pad; uint8_t sigs[2][DPOW_MAXSIGLEN],siglens[2],bestk,pad;
} PACKED; } PACKED;
@ -319,6 +319,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
nn_setsockopt(myinfo->dexsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(myinfo->dexsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(myinfo->repsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(myinfo->repsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
printf("DEXINIT dex.%d rep.%d\n",myinfo->dexsock,myinfo->repsock); printf("DEXINIT dex.%d rep.%d\n",myinfo->dexsock,myinfo->repsock);
myinfo->nanoinit = (uint32_t)time(NULL);
} }
} }
} }
@ -333,6 +334,8 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isratify) void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isratify)
{ {
int32_t i; int32_t i;
if ( bp->myind < 0 )
return;
if ( isratify != 0 ) if ( isratify != 0 )
{ {
np->srcutxo = bp->notaries[bp->myind].ratifysrcutxo; np->srcutxo = bp->notaries[bp->myind].ratifysrcutxo;
@ -374,6 +377,8 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct
int8_t bestks[64]; int32_t counts[64],i,j,numcrcs=0,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask; uint32_t crcval=0; char srcaddr[64],destaddr[64]; int8_t bestks[64]; int32_t counts[64],i,j,numcrcs=0,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask; uint32_t crcval=0; char srcaddr[64],destaddr[64];
//char str[65],str2[65]; //char str[65],str2[65];
//printf("senderind.%d num.%d %s %s\n",senderind,bp->numnotaries,bits256_str(str,srcutxo),bits256_str(str2,destutxo)); //printf("senderind.%d num.%d %s %s\n",senderind,bp->numnotaries,bits256_str(str,srcutxo),bits256_str(str2,destutxo));
if ( bp->myind < 0 )
return;
if ( bp->isratify != 0 && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 ) if ( bp->isratify != 0 && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
{ {
memset(masks,0,sizeof(masks)); memset(masks,0,sizeof(masks));
@ -545,9 +550,11 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct
} }
} }
void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][DPOW_MAXSIGLEN]) void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][DPOW_MAXSIGLEN],uint32_t paxwdcrc)
{ {
int32_t i,bestmatches = 0,matches = 0; int32_t i,bestmatches = 0,matches = 0;
if ( bp->myind < 0 )
return;
if ( bp->isratify == 0 && bp->state != 0xffffffff && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 ) if ( bp->isratify == 0 && bp->state != 0xffffffff && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
{ {
bp->notaries[senderind].src.prev_hash = srcutxo; bp->notaries[senderind].src.prev_hash = srcutxo;
@ -556,6 +563,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
bp->notaries[senderind].dest.prev_vout = destvout; bp->notaries[senderind].dest.prev_vout = destvout;
bp->notaries[senderind].bestmask = bestmask; bp->notaries[senderind].bestmask = bestmask;
bp->notaries[senderind].recvmask = recvmask; bp->notaries[senderind].recvmask = recvmask;
bp->notaries[senderind].paxwdcrc = paxwdcrc;
if ( (bp->notaries[senderind].bestk= bestk) >= 0 ) if ( (bp->notaries[senderind].bestk= bestk) >= 0 )
{ {
if ( (bp->notaries[senderind].src.siglens[bestk]= siglens[0]) != 0 ) if ( (bp->notaries[senderind].src.siglens[bestk]= siglens[0]) != 0 )
@ -585,7 +593,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
if ( bp->bestk >= 0 && bp->notaries[i].bestk == bp->bestk && bp->notaries[i].bestmask == bp->bestmask ) if ( bp->bestk >= 0 && bp->notaries[i].bestk == bp->bestk && bp->notaries[i].bestmask == bp->bestmask )
{ {
matches++; matches++;
if ( ((1LL << i) & bp->bestmask) != 0 ) if ( ((1LL << i) & bp->bestmask) != 0 && bp->notaries[i].paxwdcrc == bp->notaries[i].paxwdcrc )
bestmatches++; bestmatches++;
} // else printf("mismatch.%d (%d %llx) ",i,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask); } // else printf("mismatch.%d (%d %llx) ",i,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask);
} }
@ -623,14 +631,18 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d
} }
else else
{ {
dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs); dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc);
} }
//dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask);
} }
void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen) void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen)
{ {
struct dpow_nanomsghdr *np; int32_t i,size,sentbytes = 0; uint32_t crc32; struct dpow_nanomsghdr *np; int32_t i,size,extralen=0,sentbytes = 0; uint32_t crc32; uint8_t extras[10000];
if ( bp->myind < 0 )
return;
if ( time(NULL) < myinfo->nanoinit+5 )
return;
crc32 = calc_crc32(0,data,datalen); crc32 = calc_crc32(0,data,datalen);
//dp->crcs[firstz] = crc32; //dp->crcs[firstz] = crc32;
size = (int32_t)(sizeof(*np) + datalen); size = (int32_t)(sizeof(*np) + datalen);
@ -646,8 +658,11 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
// printf("%08x ",np->ipbits[i]); // printf("%08x ",np->ipbits[i]);
//printf(" dpow_send.(%d) size.%d numipbits.%d myind.%d\n",datalen,size,np->numipbits,bp->myind); //printf(" dpow_send.(%d) size.%d numipbits.%d myind.%d\n",datalen,size,np->numipbits,bp->myind);
if ( bp->isratify == 0 ) if ( bp->isratify == 0 )
{
extralen = dpow_paxpending(extras);
bp->notaries[bp->myind].paxwdcrc = calc_crc32(0,extras,extralen);
dpow_nanoutxoset(&np->notarize,bp,0); dpow_nanoutxoset(&np->notarize,bp,0);
else dpow_nanoutxoset(&np->ratify,bp,1); } else dpow_nanoutxoset(&np->ratify,bp,1);
np->size = size; np->size = size;
np->datalen = datalen; np->datalen = datalen;
np->crc32 = crc32; np->crc32 = crc32;
@ -663,6 +678,9 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
strcpy(np->symbol,dp->symbol); strcpy(np->symbol,dp->symbol);
np->version0 = DPOW_VERSION & 0xff; np->version0 = DPOW_VERSION & 0xff;
np->version1 = (DPOW_VERSION >> 8) & 0xff; np->version1 = (DPOW_VERSION >> 8) & 0xff;
if ( extralen > 0 )
np->notarize.paxwdcrc = calc_crc32(0,extras,extralen);
else np->notarize.paxwdcrc = 0;
memcpy(np->packet,data,datalen); memcpy(np->packet,data,datalen);
sentbytes = nn_send(myinfo->dpowsock,np,size,0); sentbytes = nn_send(myinfo->dpowsock,np,size,0);
free(np); free(np);
@ -714,6 +732,8 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *
void dpow_nanomsg_update(struct supernet_info *myinfo) void dpow_nanomsg_update(struct supernet_info *myinfo)
{ {
int32_t i,n=0,num=0,size,firstz = -1; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; int32_t i,n=0,num=0,size,firstz = -1; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0;
if ( time(NULL) < myinfo->nanoinit+5 )
return;
while ( (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 ) while ( (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 )
{ {
num++; num++;
@ -742,7 +762,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo)
else else
{ {
dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits); dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits);
if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff ) if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff && bp->myind >= 0 )
{ {
if ( np->senderind >= 0 && np->senderind < bp->numnotaries && memcmp(bp-> notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 ) if ( np->senderind >= 0 && np->senderind < bp->numnotaries && memcmp(bp-> notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 )
{ {
@ -878,6 +898,7 @@ int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *hei
{ {
memcpy(&opret[opretlen],extras,extralen); memcpy(&opret[opretlen],extras,extralen);
opretlen += extralen; opretlen += extralen;
printf("added extra.%d opreturn for withdraws paxwdcrc.%08x\n",extralen,calc_crc32(0,extras,extralen));
} }
} }
else else
@ -929,6 +950,8 @@ int32_t dpow_rwsigentry(int32_t rwflag,uint8_t *data,struct dpow_sigentry *dsig)
void dpow_sigsend(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,int32_t myind,int8_t bestk,uint64_t bestmask,bits256 srchash,uint32_t sigchannel) void dpow_sigsend(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,int32_t myind,int8_t bestk,uint64_t bestmask,bits256 srchash,uint32_t sigchannel)
{ {
struct dpow_sigentry dsig; int32_t i,len; uint8_t data[4096]; struct dpow_entry *ep; struct dpow_sigentry dsig; int32_t i,len; uint8_t data[4096]; struct dpow_entry *ep;
if ( bp->myind < 0 )
return;
if ( ((1LL << myind) & bestmask) == 0 ) if ( ((1LL << myind) & bestmask) == 0 )
return; return;
ep = &bp->notaries[myind]; ep = &bp->notaries[myind];

4
iguana/dpow/dpow_rpc.c

@ -100,11 +100,11 @@ int32_t dpow_paxpending(uint8_t *hex)
if ( (hexstr= jstr(retjson,"withdraws")) != 0 && (n= is_hexstr(hexstr,0)) > 1 ) if ( (hexstr= jstr(retjson,"withdraws")) != 0 && (n= is_hexstr(hexstr,0)) > 1 )
{ {
n >>= 1; n >>= 1;
printf("PAXPENDING.(%s)\n",retstr); //printf("PAXPENDING.(%s)\n",hexstr);
decode_hex(hex,n,hexstr); decode_hex(hex,n,hexstr);
} }
free_json(retjson); free_json(retjson);
} } else printf("dpow_paxpending: parse error.(%s)\n",retstr);
free(retstr); free(retstr);
} else printf("dpow_paxpending: paxwithdraw null return\n"); } else printf("dpow_paxpending: paxwithdraw null return\n");
} else printf("dpow_paxpending: KMD FULLNODE.%d\n",coin->FULLNODE); } else printf("dpow_paxpending: KMD FULLNODE.%d\n",coin->FULLNODE);

6
iguana/dpow/dpow_tx.c

@ -201,12 +201,12 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in
{ {
for (i=0; i<n; i++) for (i=0; i<n; i++)
printf("%02x",extras[i]); printf("%02x",extras[i]);
printf(" <- withdraw.%d\n",n); printf(" <- withdraw.%d %08x\n",n,calc_crc32(0,extras,n));
} }
satoshis = 0; satoshis = 0;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis); len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
if ( src_or_dest != 0 ) if ( bp->isratify != 0 )
opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,bp->srccoin->symbol,extras,n,bp,src_or_dest); opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,bp->srccoin->symbol,0,0,bp,src_or_dest);
else opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,bp->srccoin->symbol,extras,n,bp,src_or_dest); else opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,bp->srccoin->symbol,extras,n,bp,src_or_dest);
if ( opretlen < 0 ) if ( opretlen < 0 )
{ {

5
iguana/iguana777.h

@ -89,7 +89,7 @@ struct supernet_info
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024]; char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024];
char *decryptstr; char *decryptstr;
int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults,remoteorigin; int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults,remoteorigin;
uint32_t expiration,dirty,DEXactive,DEXpoll,totalcoins,dexcrcs[1024]; uint32_t expiration,dirty,DEXactive,DEXpoll,totalcoins,nanoinit,dexcrcs[1024];
uint16_t argport,rpcport; uint16_t argport,rpcport;
struct basilisk_info basilisks; struct basilisk_info basilisks;
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges; struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges;
@ -105,7 +105,8 @@ struct supernet_info
struct dpow_info DPOWS[64]; int32_t numdpows,dpowsock,dexsock,pubsock,repsock,subsock,reqsock; struct dpow_info DPOWS[64]; int32_t numdpows,dpowsock,dexsock,pubsock,repsock,subsock,reqsock;
struct delayedPoW_info dPoW; struct delayedPoW_info dPoW;
struct basilisk_spend *spends; int32_t numspends; struct basilisk_spend *spends; int32_t numspends;
//struct peggy_info *PEGS; // fadedreamz
struct peggy_info *PEGS;
void *PAXDATA; void *PAXDATA;
struct liquidity_info linfos[64]; struct liquidity_info linfos[64];
struct komodo_notaries NOTARY; struct komodo_notaries NOTARY;

40
iguana/iguana_accept.c

@ -13,6 +13,19 @@
* * * *
******************************************************************************/ ******************************************************************************/
/**
* - we need to include WinSock2.h header to correctly use windows structure
* as the application is still using 32bit structure from mingw so, we need to
* add the include based on checking
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*/
#if defined(_M_X64)
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#endif
#include "iguana777.h" #include "iguana777.h"
#include "exchanges777.h" #include "exchanges777.h"
@ -20,10 +33,28 @@ struct iguana_accept { struct queueitem DL; char ipaddr[64]; uint32_t ipbits; in
int32_t iguana_acceptspoll(uint8_t *buf,int32_t bufsize,struct iguana_accept *accepts,int32_t num,int32_t timeout) int32_t iguana_acceptspoll(uint8_t *buf,int32_t bufsize,struct iguana_accept *accepts,int32_t num,int32_t timeout)
{ {
/**
* This solution is for win64
* 2^11*sizeof(struct fd) for win64 bit gives a very big number
* for that reason it cannot allocate memory from stack
* so the solution is to allocate memory from heap, instead of stack
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
struct pollfd * fds;
int32_t i, j, n, r, nonz, flag; struct iguana_accept *ptr;
if (num == 0)
return(0);;
fds = (struct pollfd *) malloc(sizeof(struct pollfd) * IGUANA_MAXPEERS);
if (NULL == fds)
return -1;
memset(fds, 0, sizeof(struct pollfd) * IGUANA_MAXPEERS);
#else
struct pollfd fds[IGUANA_MAXPEERS]; int32_t i,j,n,r,nonz,flag; struct iguana_accept *ptr; struct pollfd fds[IGUANA_MAXPEERS]; int32_t i,j,n,r,nonz,flag; struct iguana_accept *ptr;
if ( num == 0 ) if ( num == 0 )
return(0);; return(0);;
memset(fds,0,sizeof(fds)); memset(fds,0,sizeof(fds));
#endif
flag = 0; flag = 0;
r = (rand() % num); r = (rand() % num);
for (j=n=nonz=0; j<num&&j<sizeof(fds)/sizeof(*fds)-1; j++) for (j=n=nonz=0; j<num&&j<sizeof(fds)/sizeof(*fds)-1; j++)
@ -58,6 +89,15 @@ int32_t iguana_acceptspoll(uint8_t *buf,int32_t bufsize,struct iguana_accept *ac
} }
} }
} }
/**
* graceful memory release, because we allocated memory on heap,
* so we are releasing it here
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
free(fds);
#endif
return(0); return(0);
} }

2
iguana/iguana_bitmap.c

@ -116,6 +116,7 @@ void gen_ppmfile(char *fname,int32_t binaryflag,uint8_t *bitmap,int32_t width,in
void gen_jpegfile(char *fname,int32_t quality,uint8_t *bitmap,int32_t width,int32_t height) void gen_jpegfile(char *fname,int32_t quality,uint8_t *bitmap,int32_t width,int32_t height)
{ {
#ifdef later
struct jpeg_compress_struct cinfo; struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr; struct jpeg_error_mgr jerr;
FILE * outfile; /* target file */ FILE * outfile; /* target file */
@ -145,6 +146,7 @@ void gen_jpegfile(char *fname,int32_t quality,uint8_t *bitmap,int32_t width,int3
jpeg_finish_compress(&cinfo); jpeg_finish_compress(&cinfo);
fclose(outfile); fclose(outfile);
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
#endif
} }
/* /*

13
iguana/iguana_blocks.c

@ -313,8 +313,21 @@ int32_t iguana_blockROsize(uint8_t zcash)
void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci) void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci)
{ {
int32_t bROsize = iguana_blockROsize(zcash); int32_t bROsize = iguana_blockROsize(zcash);
/**
* The memory address calculation was done in a non-portable way using
* long value which has 4 bytes in 64bit windows (causing invalide memory address)
* due to data truncation,
* the solution is to use portable way to calculate the address
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
dest = (void *)((unsigned char *)dest + desti*bROsize);
src = (void *)((unsigned char *)src + srci*bROsize);
#else
dest = (void *)((long)dest + desti*bROsize); dest = (void *)((long)dest + desti*bROsize);
src = (void *)((long)src + srci*bROsize); src = (void *)((long)src + srci*bROsize);
#endif
memcpy(dest,src,bROsize); memcpy(dest,src,bROsize);
return(src); return(src);
} }

4
iguana/iguana_bundles.c

@ -435,7 +435,11 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl
iguana_peerfname(coin,&hdrsi,iter==0?"DB/ro":"DB",fname,0,bp->hashes[0],zero,bp->n,1); iguana_peerfname(coin,&hdrsi,iter==0?"DB/ro":"DB",fname,0,bp->hashes[0],zero,bp->n,1);
if ( (fp= fopen(fname,"rb")) != 0 ) if ( (fp= fopen(fname,"rb")) != 0 )
{ {
#if defined(_M_X64)
fseek(fp, (uint64_t)&rdata.Toffset - (uint64_t)&rdata, SEEK_SET);
#else
fseek(fp,(long)&rdata.Toffset - (long)&rdata,SEEK_SET); fseek(fp,(long)&rdata.Toffset - (long)&rdata,SEEK_SET);
#endif
if ( fread(&Toffset,1,sizeof(Toffset),fp) == sizeof(Toffset) ) if ( fread(&Toffset,1,sizeof(Toffset),fp) == sizeof(Toffset) )
{ {
fseek(fp,Toffset + sizeof(struct iguana_txid) * txidind,SEEK_SET); fseek(fp,Toffset + sizeof(struct iguana_txid) * txidind,SEEK_SET);

9
iguana/iguana_init.c

@ -612,7 +612,16 @@ struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,struct iguana_
fpos = -1; fpos = -1;
for (j=0; j<2; j++) for (j=0; j<2; j++)
{ {
/**
* macro switch for easy debug from Visual Studio IDE
* @author-fadedreamz@gmail.com
*/
#if defined(WIN32) && defined(_DEBUG)
sprintf(fname, "%s/%s/%s_%s%s.txt", "iguana", GLOBAL_CONFSDIR, coin->symbol, j == 0 ? "" : "old", (iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname);
#else
sprintf(fname,"%s/%s_%s%s.txt",GLOBAL_CONFSDIR,coin->symbol,j==0?"":"old",(iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname); sprintf(fname,"%s/%s_%s%s.txt",GLOBAL_CONFSDIR,coin->symbol,j==0?"":"old",(iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname);
#endif
//sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs"); //sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
//sprintf(fname,"tmp/%s/%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs"); //sprintf(fname,"tmp/%s/%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
OS_compatible_path(fname); OS_compatible_path(fname);

4
iguana/iguana_json.c

@ -263,7 +263,11 @@ int32_t template_emit(char *retbuf,int32_t maxsize,char *template,char *varname,
varnamelen = (int32_t)strlen(varname); varnamelen = (int32_t)strlen(varname);
while ( (match= strstr(varname,&template[offset])) != 0 ) while ( (match= strstr(varname,&template[offset])) != 0 )
{ {
#if defined(_M_X64)
position = (int32_t)((uint64_t)match - (uint64_t)&template[offset]);
#else
position = (int32_t)((long)match - (long)&template[offset]); position = (int32_t)((long)match - (long)&template[offset]);
#endif
printf("found match.(%s) at %d offset.%d\n",varname,position,offset); printf("found match.(%s) at %d offset.%d\n",varname,position,offset);
if ( size + (valuelen + position) > maxsize ) if ( size + (valuelen + position) > maxsize )
return(-1); return(-1);

7
iguana/iguana_mofn.c

@ -563,10 +563,17 @@ int32_t test_mofn256(struct supernet_info *myinfo,int32_t M,int32_t N)
if ( m >= M ) if ( m >= M )
printf("%s %s error m.%d vs M.%d N.%d\n",bits256_str(str,secret),bits256_str(str2,recover),m,mofn->M,mofn->N); printf("%s %s error m.%d vs M.%d N.%d\n",bits256_str(str,secret),bits256_str(str2,recover),m,mofn->M,mofn->N);
} }
#if defined(_M_X64)
if (((uint64_t)mofn - (uint64_t)space) >= sizeof(space) || ((uint64_t)mofn - (uint64_t)space) < 0)
free(mofn);
if (((uint64_t)cmp - (uint64_t)space) >= sizeof(space) || ((uint64_t)cmp - (uint64_t)space) < 0)
free(cmp);
#else
if ( ((long)mofn - (long)space) >= sizeof(space) || ((long)mofn - (long)space) < 0 ) if ( ((long)mofn - (long)space) >= sizeof(space) || ((long)mofn - (long)space) < 0 )
free(mofn); free(mofn);
if ( ((long)cmp - (long)space) >= sizeof(space) || ((long)cmp - (long)space) < 0 ) if ( ((long)cmp - (long)space) >= sizeof(space) || ((long)cmp - (long)space) < 0 )
free(cmp); free(cmp);
#endif
return(retval); return(retval);
} }

64
iguana/iguana_peers.c

@ -13,6 +13,19 @@
* * * *
******************************************************************************/ ******************************************************************************/
/**
* - we need to include WinSock2.h header to correctly use windows structure
* as the application is still using 32bit structure from mingw so, we need to
* add the include based on checking
* @author - fadedreamz@gmail.com
* @remarks - #if (defined(_M_X64) || defined(__amd64__)) && defined(WIN32)
* is equivalent to #if defined(_M_X64) as _M_X64 is defined for MSVC only
*/
#if defined(_M_X64)
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#endif
#include "iguana777.h" #include "iguana777.h"
#define _iguana_hashfind(coin,ipbits) _iguana_hashset(coin,ipbits,-1) #define _iguana_hashfind(coin,ipbits) _iguana_hashset(coin,ipbits,-1)
@ -357,20 +370,70 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
struct sockaddr_in saddr; socklen_t addrlen,slen; struct sockaddr_in saddr; socklen_t addrlen,slen;
addrlen = sizeof(saddr); addrlen = sizeof(saddr);
struct hostent *hostent; struct hostent *hostent;
/**
* gethostbyname() is deprecated and cause crash on x64 windows
* the solution is to implement similar functionality by using getaddrinfo()
* it is standard posix function and is correctly supported in win32/win64/linux
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
struct addrinfo *addrresult = NULL;
struct addrinfo *returnptr = NULL;
struct addrinfo hints;
struct sockaddr_in * sockaddr_ipv4;
int retVal;
int found = 0;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
#endif
if ( parse_ipaddr(ipaddr,hostname) != 0 ) if ( parse_ipaddr(ipaddr,hostname) != 0 )
port = parse_ipaddr(ipaddr,hostname); port = parse_ipaddr(ipaddr,hostname);
#if defined(_M_X64)
retVal = getaddrinfo(ipaddr, NULL, &hints, &addrresult);
for (returnptr = addrresult; returnptr != NULL && found == 0; returnptr = returnptr->ai_next) {
switch (returnptr->ai_family) {
case AF_INET:
sockaddr_ipv4 = (struct sockaddr_in *) returnptr->ai_addr;
// we want to break from the loop after founding the first ipv4 address
found = 1;
break;
}
}
// if we iterate through the loop and didn't find anything,
// that means we failed in the dns lookup
if (found == 0) {
printf("getaddrinfo(%s) returned error\n", hostname);
freeaddrinfo(addrresult);
return(-1);
}
#else
hostent = gethostbyname(ipaddr); hostent = gethostbyname(ipaddr);
if ( hostent == NULL ) if ( hostent == NULL )
{ {
printf("gethostbyname(%s) returned error: %d port.%d ipaddr.(%s)\n",hostname,errno,port,ipaddr); printf("gethostbyname(%s) returned error: %d port.%d ipaddr.(%s)\n",hostname,errno,port,ipaddr);
return(-1); return(-1);
} }
#endif
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_port = htons(port); saddr.sin_port = htons(port);
//#ifdef WIN32 //#ifdef WIN32
// saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1"); // saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1");
//#else //#else
#if defined(_M_X64)
saddr.sin_addr.s_addr = sockaddr_ipv4->sin_addr.s_addr;
// graceful cleanup
sockaddr_ipv4 = NULL;
freeaddrinfo(addrresult);
#else
memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length); memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length);
#endif
expand_ipbits(checkipaddr,saddr.sin_addr.s_addr); expand_ipbits(checkipaddr,saddr.sin_addr.s_addr);
if ( strcmp(ipaddr,checkipaddr) != 0 ) if ( strcmp(ipaddr,checkipaddr) != 0 )
printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr); printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr);
@ -1242,6 +1305,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
memset(&fds,0,sizeof(fds)); memset(&fds,0,sizeof(fds));
fds.fd = addr->usock; fds.fd = addr->usock;
fds.events |= (POLLOUT | POLLIN); fds.events |= (POLLOUT | POLLIN);
if ( poll(&fds,1,timeout) > 0 && (fds.revents & POLLOUT) != 0 ) if ( poll(&fds,1,timeout) > 0 && (fds.revents & POLLOUT) != 0 )
{ {
flag += iguana_pollsendQ(coin,addr); flag += iguana_pollsendQ(coin,addr);

29
iguana/iguana_ramchain.c

@ -1326,7 +1326,16 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
sprintf(fname,"%s/%s%s/spends/%s.%d",GLOBAL_DBDIR,iter==0?"ro/":"",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight); sprintf(fname,"%s/%s%s/spends/%s.%d",GLOBAL_DBDIR,iter==0?"ro/":"",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight);
if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 ) if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 )
{ {
#if defined(_M_X64)
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
ramchain->Xspendinds = (void *)((unsigned char *)ptr + sizeof(sha256));
#else
ramchain->Xspendinds = (void *)((long)ptr + sizeof(sha256)); ramchain->Xspendinds = (void *)((long)ptr + sizeof(sha256));
#endif
if ( bp->Xvalid == 0 ) if ( bp->Xvalid == 0 )
vcalc_sha256(0,sha256.bytes,(void *)ramchain->Xspendinds,(int32_t)(filesize - sizeof(sha256))); vcalc_sha256(0,sha256.bytes,(void *)ramchain->Xspendinds,(int32_t)(filesize - sizeof(sha256)));
ramchain->from_roX = (iter == 0); ramchain->from_roX = (iter == 0);
@ -1399,7 +1408,17 @@ struct iguana_ramchain *_iguana_ramchain_map(struct supernet_info *myinfo,struct
if ( ramchain->fileptr != 0 && ramchain->filesize > 0 ) if ( ramchain->fileptr != 0 && ramchain->filesize > 0 )
{ {
// verify hashes // verify hashes
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
ramchain->H.data = rdata = (void *)((unsigned char *)ramchain->fileptr + fpos);
#else
ramchain->H.data = rdata = (void *)(long)((long)ramchain->fileptr + fpos); ramchain->H.data = rdata = (void *)(long)((long)ramchain->fileptr + fpos);
#endif
ramchain->H.ROflag = 1; ramchain->H.ROflag = 1;
ramchain->expanded = expanded; ramchain->expanded = expanded;
ramchain->numblocks = (bp == 0) ? 1 : bp->n; ramchain->numblocks = (bp == 0) ? 1 : bp->n;
@ -2421,7 +2440,17 @@ int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_r
memset(mapchain,0,sizeof(*mapchain)); memset(mapchain,0,sizeof(*mapchain));
mapchain->fileptr = ptr; mapchain->fileptr = ptr;
mapchain->filesize = filesize; mapchain->filesize = filesize;
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
mapchain->H.data = (void *)((unsigned char *)ptr + block->fpos);
#else
mapchain->H.data = (void *)(long)((long)ptr + block->fpos); mapchain->H.data = (void *)(long)((long)ptr + block->fpos);
#endif
mapchain->H.ROflag = 1; mapchain->H.ROflag = 1;
if ( ptr == 0 || block->fpos > filesize ) if ( ptr == 0 || block->fpos > filesize )
{ {

38
iguana/iguana_tx.c

@ -15,14 +15,28 @@
#include "iguana777.h" #include "iguana777.h"
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen) #if defined(_M_X64)
/*
* because we have no choice but to pass the value as parameters
* we need 64bit to hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,uint64_t fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen)
#else
int32_t iguana_scriptdata(struct iguana_info *coin, uint8_t *scriptspace, long fileptr[2], char *fname, uint64_t scriptpos, int32_t scriptlen)
#endif
{ {
FILE *fp; long err; int32_t retval = scriptlen; FILE *fp; long err; int32_t retval = scriptlen;
#ifndef __PNACL__ #ifndef __PNACL__
if ( scriptpos < 0xffffffff ) if ( scriptpos < 0xffffffff )
{ {
if ( fileptr[0] == 0 ) if ( fileptr[0] == 0 )
fileptr[0] = (long)OS_mapfile(fname,&fileptr[1],0); #if defined(_M_X64)
fileptr[0] = (uint64_t)OS_mapfile(fname,&fileptr[1],0);
#else
fileptr[0] = (long)OS_mapfile(fname, &fileptr[1], 0);
#endif
if ( fileptr[0] != 0 ) if ( fileptr[0] != 0 )
{ {
if ( (scriptpos + scriptlen) <= fileptr[1] ) if ( (scriptpos + scriptlen) <= fileptr[1] )
@ -249,7 +263,17 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs) int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs)
{ {
#if defined(_M_X64)
/*
* because we have no choice but to access the memory address
* we need 64bit to correctly hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
struct iguana_txid *tx, T; bits256 checktxid; int32_t i, len, total, bundlei = -2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree, checkhash2, merkle_root; struct iguana_bundle *bp = 0; uint64_t tmp; char str[65]; struct iguana_ramchaindata *rdata;
#else
struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata; struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata;
#endif
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n ) if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n )
{ {
if ( (rdata= bp->ramchain.H.data) == 0 )//&& bp == coin->current ) if ( (rdata= bp->ramchain.H.data) == 0 )//&& bp == coin->current )
@ -298,7 +322,17 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
} }
if ( i == block->RO.txn_count ) if ( i == block->RO.txn_count )
{ {
#if defined(_M_X64)
/*
* because we have no choice but to access the memory address
* we need 64bit to correctly hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
tmp = (uint64_t)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)];
#else
tmp = (long)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)]; tmp = (long)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)];
#endif
tmp &= ~(sizeof(bits256) - 1); tmp &= ~(sizeof(bits256) - 1);
tree = (void *)tmp; tree = (void *)tmp;
for (i=0; i<block->RO.txn_count; i++) for (i=0; i<block->RO.txn_count; i++)

10
iguana/iguana_txidfind.c

@ -193,7 +193,17 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
// ramchain->sparsemax = i; // ramchain->sparsemax = i;
return(setind); return(setind);
} }
// fadedreamz@gmail.com
#if defined(_M_X64)
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
else if (x < maxitems && memcmp((void *)((unsigned char *)refdata + x*refsize), key, keylen) == 0)
#else
else if ( x < maxitems && memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 ) else if ( x < maxitems && memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 )
#endif
{ {
if ( setind == 0 ) if ( setind == 0 )
ramchain->sparsehits++; ramchain->sparsehits++;

4
iguana/iguana_unspents.c

@ -1416,7 +1416,11 @@ int32_t iguana_utxoaddr_map(struct iguana_info *coin,char *fname)
memcpy(&last,(void *)((long)coin->utxoaddrfileptr+sizeof(uint64_t)),sizeof(last)); memcpy(&last,(void *)((long)coin->utxoaddrfileptr+sizeof(uint64_t)),sizeof(last));
memcpy(&coin->utxoaddrind,(void *)((long)coin->utxoaddrfileptr+sizeof(uint64_t)+sizeof(uint32_t)),sizeof(coin->utxoaddrind)); memcpy(&coin->utxoaddrind,(void *)((long)coin->utxoaddrfileptr+sizeof(uint64_t)+sizeof(uint32_t)),sizeof(coin->utxoaddrind));
memcpy(&coin->utxoaddrhash.bytes,(void *)((long)coin->utxoaddrfileptr+sizeof(uint64_t)+2*sizeof(uint32_t)),sizeof(coin->utxoaddrhash)); memcpy(&coin->utxoaddrhash.bytes,(void *)((long)coin->utxoaddrfileptr+sizeof(uint64_t)+2*sizeof(uint32_t)),sizeof(coin->utxoaddrhash));
#if defined(_M_X64)
coin->utxoaddroffsets = (void *)((unsigned char *)coin->utxoaddrfileptr + sizeof(uint64_t) + 2 * sizeof(uint32_t) + sizeof(bits256));
#else
coin->utxoaddroffsets = (void *)((long)coin->utxoaddrfileptr + sizeof(uint64_t) + 2*sizeof(uint32_t) + sizeof(bits256)); coin->utxoaddroffsets = (void *)((long)coin->utxoaddrfileptr + sizeof(uint64_t) + 2*sizeof(uint32_t) + sizeof(bits256));
#endif
for (ind=total=count=0; ind<0x10000; ind++) for (ind=total=count=0; ind<0x10000; ind++)
{ {
if ( (offset= coin->utxoaddroffsets[ind]) != 0 ) if ( (offset= coin->utxoaddroffsets[ind]) != 0 )

2
iguana/tests/ratify

@ -1,2 +1,2 @@
#!/bin/bash #!/bin/bash
curl -s "http://komodonotary.com/notary.json" | curl "http://127.0.0.1:7776" -d @- curl -s "https://komodonotary.com/notary.json" | curl "http://127.0.0.1:7776" -d @-

8
includes/iguana_apideclares.h

@ -64,14 +64,14 @@ HASH_ARRAY_STRING(basilisk,subscribe,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,forward,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,forward,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,mailbox,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,mailbox,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNcreate,hash,vals,hexstr); /*HASH_ARRAY_STRING(basilisk,VPNcreate,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNjoin,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,VPNjoin,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNmessage,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,VPNmessage,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNbroadcast,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,VPNbroadcast,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNreceive,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,VPNreceive,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNlogout,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,VPNlogout,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,vote,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,vote,hash,vals,hexstr);*/
ZERO_ARGS(bitcoinrpc,getinfo); ZERO_ARGS(bitcoinrpc,getinfo);
ZERO_ARGS(bitcoinrpc,getblockcount); ZERO_ARGS(bitcoinrpc,getblockcount);
@ -208,7 +208,7 @@ TWO_STRINGS(tradebot,stop,exchange,botid);
TWO_STRINGS(tradebot,resume,exchange,botid); TWO_STRINGS(tradebot,resume,exchange,botid);
#ifndef WIN32 #ifndef WIN32
HASH_ARG(pangea,call,tablehash); /*HASH_ARG(pangea,call,tablehash);
HASH_AND_INT(pangea,raise,tablehash,numchips); HASH_AND_INT(pangea,raise,tablehash,numchips);
HASH_AND_INT(pangea,bet,tablehash,numchips); HASH_AND_INT(pangea,bet,tablehash,numchips);
HASH_ARG(pangea,check,tablehash); HASH_ARG(pangea,check,tablehash);
@ -222,7 +222,7 @@ INT_AND_ARRAY(pangea,host,minplayers,params);
ZERO_ARGS(pangea,lobby); ZERO_ARGS(pangea,lobby);
HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_STRING(pangea,join,tablehash,handle);
HASH_AND_INT(pangea,buyin,tablehash,numchips); HASH_AND_INT(pangea,buyin,tablehash,numchips);
HASH_ARG(pangea,start,tablehash); HASH_ARG(pangea,start,tablehash);*/
#endif #endif
ZERO_ARGS(SuperNET,help); ZERO_ARGS(SuperNET,help);

1
includes/iguana_defines.h

@ -58,6 +58,7 @@
#define IGUANA_MAXBUNDLES (50000000 / 500) #define IGUANA_MAXBUNDLES (50000000 / 500)
#define IGUANA_MINPEERS 64 #define IGUANA_MINPEERS 64
#define IGUANA_LOG2MAXPEERS 11 // cant exceed 13 bits as ramchain unspents has bitfield #define IGUANA_LOG2MAXPEERS 11 // cant exceed 13 bits as ramchain unspents has bitfield
#define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS) #define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS)

9
includes/iguana_funcs.h

@ -580,7 +580,16 @@ struct iguana_peer *iguana_peerfindipbits(struct iguana_info *coin,uint32_t ipbi
//int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *addr); //int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *addr);
int32_t basilisk_hashes_send(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_peer *addr,char *CMD,bits256 *txids,int32_t num); int32_t basilisk_hashes_send(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_peer *addr,char *CMD,bits256 *txids,int32_t num);
int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen); int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen);
/*
* because the address passed in a non-portable way we defined uint64_t as parameter to
* allow the pass of 64bit memory address in windows 64
* @author - fadedreamz@gmail.com
*/
#if defined(_M_X64)
int32_t iguana_scriptdata(struct iguana_info *coin, uint8_t *scriptspace, uint64_t fileptr[2], char *fname, uint64_t scriptpos, int32_t scriptlen);
#else
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen); int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen);
#endif
void basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits); void basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits);
void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr); void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr);
int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]); int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]);

20
includes/iguana_structs.h

@ -301,7 +301,17 @@ struct iguana_txblock
struct iguana_zblock zblock; struct iguana_zblock zblock;
}; };
#if defined(_M_X64)
/*
* calculate the address in a portable manner
* in all platform sizeof(char) / sizeof(uchar) == 1
* @author - fadedreamz@gmail.com
*/
#define RAMCHAIN_PTR(rdata,offset) ((void *)((unsigned char *)rdata + rdata->offset))
#else
#define RAMCHAIN_PTR(rdata,offset) ((void *)(long)((long)(rdata) + (long)(rdata)->offset)) #define RAMCHAIN_PTR(rdata,offset) ((void *)(long)((long)(rdata) + (long)(rdata)->offset))
#endif
struct iguana_ramchaindata struct iguana_ramchaindata
{ {
bits256 sha256; bits256 sha256;
@ -461,7 +471,17 @@ struct iguana_info
struct iguana_peers *peers; struct iguana_peer internaladdr; struct iguana_peers *peers; struct iguana_peer internaladdr;
//basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value; //basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value;
//basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric; //basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric;
#if defined(_M_X64)
/*
* because we have no choice but to pass the value as parameters
* we need 64bit to hold 64bit memory address, thus changing
* to uint64_t instead of long in win x64
* @author - fadedreamz@gmail.com
*/
uint64_t vinptrs[IGUANA_MAXPEERS + 1][2], voutptrs[IGUANA_MAXPEERS + 1][2];
#else
long vinptrs[IGUANA_MAXPEERS+1][2],voutptrs[IGUANA_MAXPEERS+1][2]; long vinptrs[IGUANA_MAXPEERS+1][2],voutptrs[IGUANA_MAXPEERS+1][2];
#endif
uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100]; uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100];
uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime; uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime;
int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles; int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles;

Loading…
Cancel
Save