Browse Source

Merge branch 'release/v0.1'

dPoW2
jl777 8 years ago
parent
commit
2d4020b3ae
  1. 6
      .gitignore
  2. 22
      MyTemplate.vstemplate
  3. 4
      OSlibs/win/mingw.h
  4. 40
      ReadMe.txt
  5. BIN
      __TemplateIcon.ico
  6. 221
      basilisk/basilisk.c
  7. 2
      basilisk/basilisk.h
  8. 15
      basilisk/basilisk_CMD.c
  9. 8
      basilisk/basilisk_MSG.c
  10. 419
      basilisk/basilisk_bitcoin.c
  11. 1
      basilisk/basilisk_ping.c
  12. 4
      basilisk/basilisk_swap.c
  13. 7
      basilisk/basilisk_tradebot.c
  14. 107
      crypto777/OS_nonportable.c
  15. 24
      crypto777/OS_portable.c
  16. 65
      crypto777/OS_portable.h
  17. 8
      crypto777/OS_time.c
  18. 2
      crypto777/SaM.c
  19. 30
      crypto777/curve25519.c
  20. 129
      crypto777/iguana_OS.c
  21. 6
      crypto777/iguana_utils.c
  22. 2
      crypto777/inet.c
  23. 5
      crypto777/jpeg/jconfig.h
  24. 1
      crypto777/jpeg/jmemsys.h
  25. 2
      crypto777/jpeg/unix/jmemname.c
  26. 7
      crypto777/scrypt.c
  27. 24
      datachain/datachain_KOMODO.c
  28. 2
      deprecated/iguana_instantdex.c
  29. 498
      deprecated/obsolete.h
  30. 6
      gecko/gecko.c
  31. 16
      gecko/gecko_blocks.c
  32. 12
      gecko/gecko_headers.c
  33. 9
      gecko/gecko_mempool.c
  34. 20
      gecko/gecko_miner.c
  35. 297
      iguana.vcxproj
  36. 146
      iguana.vcxproj.filters
  37. 2
      iguana/SuperNET_keys.c
  38. 8
      iguana/coins/allofus
  39. 6
      iguana/coins/basilisk
  40. 0
      iguana/coins/genanc
  41. 0
      iguana/coins/genanc.json
  42. 1
      iguana/coins/genblk
  43. 2
      iguana/coins/genbtc
  44. 2
      iguana/coins/genbtc.json
  45. 1
      iguana/coins/genbtc8.json
  46. 2
      iguana/coins/genbtcd
  47. 1
      iguana/coins/genbtcdsigs
  48. 0
      iguana/coins/genbtm
  49. 0
      iguana/coins/genbtm.json
  50. 0
      iguana/coins/gencarb
  51. 0
      iguana/coins/gencarb.json
  52. 0
      iguana/coins/genfrk
  53. 0
      iguana/coins/genfrk.json
  54. 2
      iguana/coins/gengmc
  55. 2
      iguana/coins/genkmd
  56. 1
      iguana/coins/gensxc
  57. 2
      iguana/coins/gensys
  58. 2
      iguana/coins/gentaz
  59. 0
      iguana/coins/genvia
  60. 111
      iguana/confs/BTCD_hdrs.txt
  61. 1
      iguana/confs/BTCD_peers.txt
  62. 4293
      iguana/confs/BTC_hdrs.txt
  63. 17301
      iguana/confs/DGB_peers.txt
  64. 28
      iguana/confs/GMC_peers.txt
  65. 3
      iguana/confs/KMD_peers.txt
  66. 11
      iguana/confs/SXC_peers.txt
  67. 3
      iguana/confs/TAZ_peers.txt
  68. 14
      iguana/confs/UNO_peers.txt
  69. 8
      iguana/exchanges/bitcoin.c
  70. 4
      iguana/exchanges777.h
  71. 6
      iguana/genbtcloop8
  72. 235
      iguana/iguana777.c
  73. 27
      iguana/iguana777.h
  74. 43
      iguana/iguana_accept.c
  75. 2
      iguana/iguana_bitmap.c
  76. 156
      iguana/iguana_blocks.c
  77. 145
      iguana/iguana_bundles.c
  78. 52
      iguana/iguana_chains.c
  79. 31
      iguana/iguana_exchanges.c
  80. 56
      iguana/iguana_init.c
  81. 52
      iguana/iguana_interpreter.c
  82. 2
      iguana/iguana_json.c
  83. 2
      iguana/iguana_mofn.c
  84. 339
      iguana/iguana_msg.c
  85. 170
      iguana/iguana_payments.c
  86. 113
      iguana/iguana_peers.c
  87. 337
      iguana/iguana_ramchain.c
  88. 757
      iguana/iguana_realtime.c
  89. 576
      iguana/iguana_recv.c
  90. 4
      iguana/iguana_rpc.c
  91. 24
      iguana/iguana_scripts.c
  92. 4
      iguana/iguana_secp.c
  93. 120
      iguana/iguana_sign.c
  94. 123
      iguana/iguana_spendvectors.c
  95. 2
      iguana/iguana_tradebots.c
  96. 133
      iguana/iguana_tx.c
  97. 15
      iguana/iguana_txidfind.c
  98. 347
      iguana/iguana_unspents.c
  99. 52
      iguana/iguana_volatiles.c
  100. 257
      iguana/iguana_wallet.c

6
.gitignore

@ -1,11 +1,7 @@
*.o
agents/iguana.exe
Debug/*
iguana/pnacl/Release/iguana_unstripped.pexe

22
MyTemplate.vstemplate

@ -0,0 +1,22 @@
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>iguana_template</Name>
<Description>&lt;No description available&gt;</Description>
<ProjectType>VC</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>iguana_template</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="ConsoleApplication3.vcxproj" File="ConsoleApplication3.vcxproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.vcxproj.filters">ConsoleApplication3.vcxproj.filters</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="ReadMe.txt">ReadMe.txt</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate>

4
OSlibs/win/mingw.h

@ -1,12 +1,14 @@
#ifndef MINGW_H
#define MINGW_H
#define ssize_t __int32
#include <io.h>
#define _USE_W32_SOCKETS 1
#include <windows.h>
#include "pthread.h"
#ifndef NATIVE_WINDOWS
#define ENOTCONN WSAENOTCONN
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOBUFS WSAENOBUFS
@ -18,7 +20,7 @@
#define EISCONN WSAEISCONN
#define ECONNREFUSED WSAECONNREFUSED
#define EHOSTUNREACH WSAEHOSTUNREACH
#endif
/* winsock doesn't feature poll(), so there is a version implemented
* in terms of select() in mingw.c. The following definitions

40
ReadMe.txt

@ -0,0 +1,40 @@
========================================================================
CONSOLE APPLICATION : ConsoleApplication3 Project Overview
========================================================================
AppWizard has created this ConsoleApplication3 application for you.
This file contains a summary of what you will find in each of the files that
make up your ConsoleApplication3 application.
ConsoleApplication3.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
ConsoleApplication3.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
ConsoleApplication3.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named ConsoleApplication3.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////

BIN
__TemplateIcon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

221
basilisk/basilisk.c

@ -48,8 +48,8 @@ uint32_t basilisk_calcnonce(struct supernet_info *myinfo,uint8_t *data,int32_t d
break;
}
iguana_rwnum(0,(void *)hash.uints,sizeof(basilisktag),&basilisktag);
iguana_rwnum(1,&data[-sizeof(basilisktag)],sizeof(basilisktag),&basilisktag);
char str[65],str2[65]; printf("found hash after numiters.%d %s vs %s basilisktag.%u\n",numiters,bits256_str(str,threshold),bits256_str(str2,hash2),basilisktag);
iguana_rwnum(1,&data[-(int32_t)sizeof(basilisktag)],sizeof(basilisktag),&basilisktag);
//char str[65],str2[65]; printf("found hash after numiters.%d %s vs %s basilisktag.%u\n",numiters,bits256_str(str,threshold),bits256_str(str2,hash2),basilisktag);
return(basilisktag);
}
@ -95,7 +95,7 @@ uint8_t *get_dataptr(int32_t hdroffset,uint8_t **ptrp,int32_t *datalenp,uint8_t
uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag)
{
char *sendstr,*hexstr=0; uint8_t *data,hexspace[4096],*allocptr=0,*hexdata; int32_t datalen,hexlen=0;
char *sendstr,*hexstr=0; uint8_t *data,hexspace[4096],*allocptr=0,*hexdata=0; int32_t datalen,hexlen=0;
if ( jobj(sendjson,"symbol") == 0 )
jaddstr(sendjson,"symbol",symbol);
if ( (hexstr= jstr(sendjson,"data")) != 0 )
@ -118,7 +118,7 @@ uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int
memcpy(data,sendstr,datalen);
//printf("jsondata.(%s) + hexlen.%d\n",sendstr,hexlen);
free(sendstr);
if ( hexlen > 0 )
if ( hexlen > 0 && hexdata != 0 )
{
//int32_t i; for (i=0; i<hexlen; i++)
// printf("%02x",hexdata[i]);
@ -132,12 +132,12 @@ uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int
return(data);
}
struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD,char *symbol,uint32_t basilisktag,int32_t minresults,cJSON *vals,int32_t timeoutmillis,void *metricfunc)
struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD,char *symbol,uint32_t basilisktag,int32_t numrequired,cJSON *vals,int32_t timeoutmillis,void *metricfunc)
{
struct basilisk_item *ptr;
ptr = calloc(1,sizeof(*ptr));
ptr->basilisktag = basilisktag;
if ( (ptr->numrequired= minresults) == 0 )
if ( (ptr->numrequired= numrequired) == 0 )
ptr->numrequired = 1;
strcpy(ptr->CMD,CMD);
safecopy(ptr->symbol,symbol,sizeof(ptr->symbol));
@ -162,7 +162,9 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
if ( destipaddr != 0 )
{
if ( destipaddr[0] == 0 )
{
destipaddr = 0; // broadcast
}
else if ( strcmp(destipaddr,"127.0.0.1") == 0 || strcmp(destipaddr,myinfo->ipaddr) == 0 )
{
printf("return after locally basilisk_msgprocess\n");
@ -171,19 +173,42 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
return(0);
}
}
alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent));
iguana_rwnum(1,&data[-sizeof(*basilisktagp)],sizeof(*basilisktagp),basilisktagp);
iguana_rwnum(1,&data[-(int32_t)sizeof(*basilisktagp)],sizeof(*basilisktagp),basilisktagp);
if ( *basilisktagp == 0 )
{
if ( nBits != 0 )
*basilisktagp = basilisk_calcnonce(myinfo,data,datalen,nBits);
else *basilisktagp = rand();
iguana_rwnum(1,&data[-sizeof(*basilisktagp)],sizeof(*basilisktagp),basilisktagp);
iguana_rwnum(1,&data[-(int32_t)sizeof(*basilisktagp)],sizeof(*basilisktagp),basilisktagp);
}
data -= sizeof(*basilisktagp), datalen += sizeof(*basilisktagp);
memset(cmd,0,sizeof(cmd));
sprintf(cmd,"SuperNET%s",type);
if ( destipaddr != 0 )
{
cmd[6] = 'E', cmd[7] = 'T';
HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{
if ( coin->peers == 0 )
continue;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 )
cmd[0] = 's';
else cmd[0] = 'S';
for (i=0; i<IGUANA_MAXPEERS; i++)
{
addr = &coin->peers->active[i];
if ( addr->usock >= 0 && strcmp(addr->ipaddr,destipaddr) == 0 )
{
return(iguana_queue_send(addr,delaymillis,&data[-(int32_t)sizeof(struct iguana_msghdr)],cmd,datalen));
}
}
}
return(-1);
}
if ( basilisk_specialcmd(type) != 0 && NUMRELAYS == 0 )
return(-1);
//portable_mutex_lock(&myinfo->allcoins_mutex);
alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent));
HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{
if ( coin->peers == 0 )
@ -202,8 +227,10 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
if ( addr->usock >= 0 )
{
s = 0;
if ( NUMRELAYS > 0 && basilisk_specialcmd(type) != 0 )
valid = (addr->supernet != 0);
if ( basilisk_specialcmd(type) != 0 )
{
valid = 0;
OS_randombytes((void *)&r2,sizeof(r2));
if ( (r2 % NUMRELAYS) >= sqrt(NUMRELAYS) )
{
@ -218,8 +245,8 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
//printf("skip non-relay.(%s)\n",addr->ipaddr);
continue;
}
//printf("send to other relay.(%s)\n",addr->ipaddr);
valid = 1;
//printf("send to other relay.(%s)\n",addr->ipaddr);
}
for (s=0; s<n; s++)
if ( alreadysent[s] == addr->ipbits )
@ -229,7 +256,8 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
}
if ( s == n && valid == 1 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) )
{
//printf("n.%d/fanout.%d i.%d l.%d [%s].tag%d send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
//fprintf(stderr,"(%s) ",addr->ipaddr);
//printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 )
{
void *ptr; uint8_t *cipher,space[8192]; int32_t cipherlen; bits256 privkey;
@ -237,7 +265,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
memset(privkey.bytes,0,sizeof(privkey));
if ( (cipher= SuperNET_ciphercalc(&ptr,&cipherlen,&privkey,&addr->pubkey,data,datalen,space,sizeof(space))) != 0 )
{
if ( (val= iguana_queue_send(addr,delaymillis,&cipher[-sizeof(struct iguana_msghdr)],cmd,cipherlen)) >= cipherlen )
if ( (val= iguana_queue_send(addr,delaymillis,&cipher[-(int32_t)sizeof(struct iguana_msghdr)],cmd,cipherlen)) >= cipherlen )
alreadysent[n++] = (uint32_t)addr->ipbits;
if ( ptr != 0 )
free(ptr);
@ -246,7 +274,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
else
{
cmd[6] = 'E', cmd[7] = 'T';
if ( (val= iguana_queue_send(addr,delaymillis,&data[-sizeof(struct iguana_msghdr)],cmd,datalen)) >= datalen )
if ( (val= iguana_queue_send(addr,delaymillis,&data[-(int32_t)sizeof(struct iguana_msghdr)],cmd,datalen)) >= datalen )
{
alreadysent[n++] = (uint32_t)addr->ipbits;
if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS )
@ -299,10 +327,10 @@ void basilisk_sendback(struct supernet_info *myinfo,char *origCMD,char *symbol,c
}
}
struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,struct iguana_peer *addr,int32_t *numsentp,char *CMD,char *symbol,int32_t blockflag,cJSON *valsobj,int32_t fanout,int32_t minresults,uint32_t basilisktag,int32_t timeoutmillis,void *deprecated_dontuse,char *retstr,int32_t encryptflag,int32_t delaymillis,uint32_t nBits)
struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,struct iguana_peer *addr,int32_t *numsentp,char *CMD,char *symbol,int32_t blockflag,cJSON *valsobj,int32_t fanout,int32_t numrequired,uint32_t basilisktag,int32_t timeoutmillis,void *deprecated_dontuse,char *retstr,int32_t encryptflag,int32_t delaymillis,uint32_t nBits)
{
struct basilisk_item *pending; uint8_t *allocptr,*data,space[4096]; int32_t datalen; cJSON *retarray;
pending = basilisk_itemcreate(myinfo,CMD,symbol,basilisktag,minresults,valsobj,timeoutmillis,0);
pending = basilisk_itemcreate(myinfo,CMD,symbol,basilisktag,numrequired,valsobj,timeoutmillis,0);
pending->nBits = nBits;
*numsentp = 0;
if ( retstr != 0 )
@ -319,31 +347,33 @@ struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,struct i
if ( blockflag != 0 )
{
portable_mutex_lock(&myinfo->basilisk_mutex);
//printf("HASH_ADD.%p\n",pending);
HASH_ADD(hh,myinfo->basilisks.issued,basilisktag,sizeof(basilisktag),pending);
portable_mutex_unlock(&myinfo->basilisk_mutex);
//queue_enqueue("issuedQ",&myinfo->basilisks.issued,&pending->DL,0);
if ( pending->expiration <= OS_milliseconds() )
pending->expiration = OS_milliseconds() + BASILISK_TIMEOUT;
//ptr->vals = jduplicate(valsobj);
strcpy(pending->symbol,"BTCD");
strcpy(pending->CMD,CMD);
while ( OS_milliseconds() < pending->expiration )
{
portable_mutex_lock(&myinfo->basilisk_mutex);
if ( pending->numresults >= pending->numrequired )//|| (retstr= pending->retstr) != 0 )
{
//printf("numresults.%d vs numrequired.%d\n",pending->numresults,pending->numrequired);
portable_mutex_unlock(&myinfo->basilisk_mutex);
//printf("<<<<<<<<<<<<< numresults.%d vs numrequired.%d\n",pending->numresults,pending->numrequired);
break;
}
portable_mutex_unlock(&myinfo->basilisk_mutex);
usleep(10000);
}
portable_mutex_lock(&myinfo->basilisk_mutex);
if ( (retarray= pending->retarray) != 0 )
{
pending->retstr = jprint(retarray,0);
//printf("num.%d:%d required.%d RETSTR.(%s)\n",pending->numresults,cJSON_GetArraySize(pending->retarray),pending->numrequired,pending->retstr);
pending->retarray = 0;
free_json(retarray);
}
//return(basilisk_waitresponse(myinfo,CMD,"BTCD",0,&Lptr,valsobj,ptr));
portable_mutex_unlock(&myinfo->basilisk_mutex);
} else free(pending), pending = 0; //ptr->finished = (uint32_t)time(NULL);
if ( allocptr != 0 )
free(allocptr);
@ -356,22 +386,24 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc
int32_t minfanout,numrequired,timeoutmillis,numsent,delaymillis,encryptflag,fanout; struct basilisk_item *ptr; char buf[4096],*symbol,*str = 0; struct iguana_info *virt;
//printf("request.(%s)\n",jprint(valsobj,0));
basilisk_addhexstr(&str,valsobj,buf,sizeof(buf),data,datalen);
if ( bits256_cmp(hash,GENESIS_PUBKEY) != 0 && bits256_nonz(hash) != 0 )
if ( bits256_nonz(hash) == 0 || (bits256_cmp(hash,GENESIS_PUBKEY) != 0 && bits256_nonz(hash) != 0) )
{
if ( jobj(valsobj,"hash") != 0 )
jdelete(valsobj,"hash");
jaddbits256(valsobj,"hash",hash);
}
if ( (numrequired= jint(valsobj,"numrequired")) <= 0 )
numrequired = sqrt(NUMRELAYS);
if ( (timeoutmillis= jint(valsobj,"timeout")) == 0 )
timeoutmillis = BASILISK_TIMEOUT;
minfanout = sqrt(NUMRELAYS)+1;
if ( minfanout < 5 )
minfanout = 5;
if ( jobj(valsobj,"fanout") == 0 )
fanout = minfanout;
else fanout = jint(valsobj,"fanout");
if ( fanout < minfanout )
fanout = minfanout;
if ( (numrequired= jint(valsobj,"numrequired")) <= 0 )
numrequired = MAX(fanout,sqrt(NUMRELAYS)+1);
if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 )
{
if ( (virt= iguana_coinfind(symbol)) != 0 )
@ -395,6 +427,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add
if ( RELAYID >= 0 && basilisk_specialcmd(CMD) == 0 )
return(clonestr("{\"error\":\"unsupported special relay command\"}"));
data = get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr);
//printf("request.(%s)\n",jprint(valsobj,0));
ptr = basilisk_requestservice(myinfo,_addr,CMD,blockflag,valsobj,hash,data,datalen,nBits);
if ( allocptr != 0 )
free(allocptr);
@ -415,7 +448,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add
}
ptr->finished = (uint32_t)time(NULL);
}
if ( 1 && strcmp("RID",CMD) != 0 && strcmp("BAL",CMD) != 0 && strcmp("MSG",CMD) != 0 )
if ( 0 && strcmp("RID",CMD) != 0 && strcmp("BAL",CMD) != 0 && strcmp("MSG",CMD) != 0 )
printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:"");
return(retstr);
}
@ -540,8 +573,8 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
{
retstr = jprint(vals,0);
safecopy(CMD,jstr(vals,"origcmd"),sizeof(CMD));
if ( 0 && strcmp("RID",CMD) != 0 )
printf("(%s) -> Q.%u results vals.(%s)\n",CMD,basilisktag,retstr);
//if ( 0 && strcmp("RID",CMD) != 0 )
//printf("(%s) -> Q.%u results vals.(%s)\n",CMD,basilisktag,retstr);//(int32_t)strlen(retstr));
if ( strcmp(CMD,"GET") == 0 )
basilisk_geckoresult(myinfo,remoteaddr,retstr,data,datalen);
else
@ -549,7 +582,6 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
portable_mutex_lock(&myinfo->basilisk_mutex);
HASH_FIND(hh,myinfo->basilisks.issued,&basilisktag,sizeof(basilisktag),pending);
//printf("HASH_FIND.%p\n",pending);
portable_mutex_unlock(&myinfo->basilisk_mutex);
if ( pending != 0 && retstr != 0 )
{
if ( (item= cJSON_Parse(retstr)) != 0 )
@ -557,15 +589,16 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
if ( pending->retarray == 0 )
pending->retarray = cJSON_CreateArray();
if ( jobj(item,"myip") == 0 )
jaddstr(item,"myip",myinfo->ipaddr);
jaddstr(item,"myip",remoteaddr);
jaddi(pending->retarray,item);
if ( jobj(item,"error") == 0 )
{
//printf("numresults.%d (%s)\n",pending->numresults,jprint(item,0));
//printf("numresults.%d:%d\n",pending->numresults,cJSON_GetArraySize(pending->retarray));
pending->numresults++;
}
} else printf("couldnt parse.(%s)\n",retstr);
} //else printf("couldnt find issued.%u\n",basilisktag);
portable_mutex_unlock(&myinfo->basilisk_mutex);
}
}
}
@ -620,6 +653,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
// coin services
{ (void *)"VAL", &basilisk_respond_value },
{ (void *)"BAL", &basilisk_respond_balances },
{ (void *)"INF", &basilisk_respond_getinfo },
};
strncpy(CMD,type,3), CMD[3] = cmd[3] = 0;
if ( isupper((int32_t)CMD[0]) != 0 && isupper((int32_t)CMD[1]) != 0 && isupper((int32_t)CMD[2]) != 0 )
@ -637,6 +671,8 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
if ( basilisk_specialcmd(CMD) == 0 )
return;
}
else if ( basilisk_specialcmd(CMD) != 0 )
return;
symbol = "BTCD";
if ( senderipbits == 0 )
expand_ipbits(remoteaddr,myinfo->myaddr.myipbits);
@ -693,7 +729,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
hash = jbits256(valsobj,"hash");
timeoutmillis = jint(valsobj,"timeout");
if ( (numrequired= jint(valsobj,"numrequired")) == 0 )
numrequired = sqrt(NUMRELAYS);
numrequired = sqrt(NUMRELAYS)+1;
if ( senderipbits != 0 )
expand_ipbits(remoteaddr,senderipbits);
else remoteaddr[0] = 0;
@ -703,7 +739,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
{
if ( coin->FULLNODE != 0 || RELAYID >= 0 ) // iguana node
{
//printf("services %s\n",type);
//printf("FULL.%d RELAYID.%d NUMRELAYS.%d services %s\n",coin->FULLNODE,RELAYID,NUMRELAYS,type);
if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk)) != 0 )
{
//printf("from_basilisk.%d ret.(%s)\n",from_basilisk,retstr);
@ -751,8 +787,8 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag);
//int32_t i; for (i=0; i<datalen-len; i++)
// printf("%02x",data[len+i]);
if ( 0 && RELAYID >= 0 )
printf(" ->received.%d basilisk_p2p.(%s) from %s tag.%d\n",datalen,type,senderip!=0?senderip:"?",basilisktag);
if ( RELAYID >= 0 )
printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag);
basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len);
}
if ( ptr != 0 )
@ -834,14 +870,17 @@ void basilisks_loop(void *arg)
basilisk_ping_send(myinfo,btcd);
}
}
HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin)
if ( myinfo->expiration != 0 )
{
if ( time(NULL) > coin->lastunspentsupdate+10 )
HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin)
{
//printf(">>>>>>>>>>>>> update\n");
basilisk_unspents_update(myinfo,coin);
coin->lastunspentsupdate = (uint32_t)time(NULL);
//printf(">>>>>>>>>>>>> update finished\n");
if ( myinfo->Cunspents == 0 || time(NULL) > coin->lastunspentsupdate+60 )
{
//printf(">>>>>>>>>>>>> update %s\n",coin->symbol);
basilisk_unspents_update(myinfo,coin);
coin->lastunspentsupdate = (uint32_t)time(NULL);
//printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol);
}
}
}
if ( RELAYID < 0 && myinfo->expiration != 0 )
@ -860,8 +899,8 @@ void basilisks_loop(void *arg)
}
portable_mutex_unlock(&myinfo->messagemutex);
if ( RELAYID >= 0 )
usleep(30000);
else usleep(100000);
usleep(100000);
else usleep(3000000);
}
}
@ -882,6 +921,7 @@ void basilisks_init(struct supernet_info *myinfo)
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis;
@ -889,40 +929,46 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
if ( vals == 0 )
return(clonestr("{\"error\":\"need vals object\"}"));
//if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
coin = iguana_coinfind(symbol);
}
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
coin = iguana_coinfind(symbol);
if ( jobj(vals,"history") == 0 )
jaddnum(vals,"history",3);
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+1);
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",sqrt(NUMRELAYS));
jaddnum(vals,"numrequired",juint(vals,"fanout"));
if ( jobj(vals,"addresses") == 0 )
{
jadd(vals,"addresses",iguana_getaddressesbyaccount(myinfo,coin,"*"));
//printf("added all %s addresses: %s\n",coin->symbol,jprint(vals,0));
} //else printf("have addresses.(%s)\n",jprint(jobj(vals,"addresses"),0));
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = 3000;
if ( coin != 0 )
{
if ( jobj(vals,"addresses") == 0 )
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
jadd(vals,"addresses",iguana_getaddressesbyaccount(myinfo,coin,"*"));
//printf("added all addresses: %s\n",jprint(vals,0));
} //else printf("have addresses.(%s)\n",jprint(jobj(vals,"addresses"),0));
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( (coin->FULLNODE != 0 || coin->VALIDATENODE != 0) && (ptr= basilisk_bitcoinbalances(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
{
retstr = ptr->retstr, ptr->retstr = 0;
ptr->finished = (uint32_t)time(NULL);
return(retstr);
if ( (ptr= basilisk_bitcoinbalances(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
{
retstr = ptr->retstr, ptr->retstr = 0;
ptr->finished = (uint32_t)time(NULL);
return(retstr);
}
return(clonestr("{\"error\":\"no result\"}"));
}
return(clonestr("{\"error\":\"no result\"}"));
} else printf("no coin\n");
return(basilisk_standardservice("BAL",myinfo,0,hash,vals,hexstr,1));
if ( (retstr= basilisk_standardservice("BAL",myinfo,0,hash,vals,hexstr,1)) != 0 )
{
basilisk_unspents_process(myinfo,coin,retstr);
}
return(retstr);
}
HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)
{
struct basilisk_unspent *bu; int32_t i; int64_t totalspent=0,total = 0; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2; char *symbol; cJSON *retjson,*array; struct basilisk_spend *s;
int64_t total = 0; int32_t i,n; char *symbol; cJSON *retjson,*unspents,*spends,*array; //struct basilisk_spend *s; struct basilisk_unspent *bu; int32_t i; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2;
if ( vals == 0 )
return(clonestr("{\"error\":\"need vals object\"}"));
//if ( coin == 0 )
@ -932,43 +978,42 @@ HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)
}
if ( coin == 0 )
return(clonestr("{\"error\":\"couldnt find coin\"}"));
//printf("history for (%s)\n",coin->symbol);
basilisk_unspents_update(myinfo,coin);
array = cJSON_CreateArray();
unspents = cJSON_CreateArray();
spends = cJSON_CreateArray();
portable_mutex_lock(&myinfo->bu_mutex);
HASH_ITER(hh,myinfo->wallet,wacct,tmp)
//HASH_ITER(hh,myinfo->wallet,wacct,tmp)
{
HASH_ITER(hh,wacct->waddr,waddr,tmp2)
//HASH_ITER(hh,wacct->waddr,waddr,tmp2)
{
for (i=0; i<waddr->numunspents; i++)
if ( myinfo->Cunspents != 0 )
{
bu = &waddr->unspents[i];
if ( strcmp(bu->symbol,coin->symbol) == 0 )
//printf("Cunspents.(%s)\n",jprint(waddr->Cunspents,0));
if ( (array= jobj(myinfo->Cunspents,coin->symbol)) != 0 )
{
bitcoin_address(waddr->coinaddr,coin->chain->pubtype,waddr->rmd160,sizeof(waddr->rmd160));
jaddi(array,basilisk_history_item(coin,&total,waddr->coinaddr,bu->value,bu->timestamp,bu->txid,"vout",bu->vout,bu->height,"spentheight",bu->spentheight,bu->relaymask,-1));
//printf("%s %s i.%d numunspents.%d\n",coin->symbol,waddr->coinaddr,i,waddr->numunspents);
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
total += jdouble(jitem(array,i),"amount") * SATOSHIDEN;
}
jaddi(unspents,jduplicate(array));
}
}
}
}
if ( myinfo->numspends > 0 )
{
//spends = cJSON_CreateArray();
for (i=0; i<myinfo->numspends; i++)
{
s = &myinfo->spends[i];
//struct basilisk_spend { bits256 txid; uint64_t relaymask,value; uint32_t timestamp; int32_t vini,height,unspentheight,ismine; char destaddr[64]; };
if ( strcmp(s->symbol,coin->symbol) == 0 )
jaddi(array,basilisk_history_item(coin,&totalspent,s->destaddr,s->value,s->timestamp,s->txid,"vin",s->vini,s->height,"unspentheight",s->unspentheight,s->relaymask,s->ismine));
if ( myinfo->Cspends != 0 )
{
//printf("Cspends.(%s)\n",jprint(waddr->Cspends,0));
if ( (array= jobj(myinfo->Cspends,coin->symbol)) != 0 )
jaddi(spends,jduplicate(array));
}
}
}
portable_mutex_unlock(&myinfo->bu_mutex);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jadd(retjson,"history",array);
jadd(retjson,"unspents",unspents);
jadd(retjson,"spends",spends);
jaddstr(retjson,"coin",coin->symbol);
jaddnum(retjson,"balance",dstr(total));
//printf("return history balance %s %.8f\n",coin->symbol,dstr(total));
return(jprint(retjson,1));
}

2
basilisk/basilisk.h

@ -20,7 +20,7 @@
#include "../iguana/iguana777.h"
#define BASILISK_TIMEOUT 30000
#define BASILISK_TIMEOUT 5000
#define BASILISK_MINFANOUT 8
#define BASILISK_MAXFANOUT 64
#define BASILISK_DEFAULTDIFF 0x1effffff

15
basilisk/basilisk_CMD.c

@ -236,6 +236,21 @@ char *basilisk_respond_balances(struct supernet_info *myinfo,char *CMD,void *add
return(retstr);
}
char *basilisk_respond_getinfo(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk)
{
char *symbol,*retstr=0; struct basilisk_item Lptr,*ptr; int32_t timeoutmillis; struct iguana_info *coin = 0;
if ( (timeoutmillis= jint(valsobj,"timeout")) <= 0 )
timeoutmillis = 1000;
if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 )
coin = iguana_coinfind(symbol);
if ( coin != 0 && (ptr= basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,valsobj)) != 0 )
{
retstr = ptr->retstr;
ptr->finished = (uint32_t)time(NULL);
} else retstr = clonestr("{\"error\":\"no coin specified or error bitcoinrawtx\"}");
return(retstr);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"

8
basilisk/basilisk_MSG.c

@ -189,7 +189,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
free(retstr);
}
if ( vals != 0 && juint(vals,"fanout") == 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+2);
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+2));
return(basilisk_standardservice("OUT",myinfo,0,hash,vals,hexstr,0));
}
#include "../includes/iguana_apiundefs.h"
@ -203,7 +203,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
jaddnum(valsobj,"channel",channel);
if ( msgid == 0 )
msgid = (uint32_t)time(NULL);
jaddnum(valsobj,"fanout",(int32_t)sqrt(NUMRELAYS)+2);
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+2));
jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"duration",duration);
jaddbits256(valsobj,"sender",myinfo->myaddr.persistent);
@ -252,8 +252,8 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch
jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"width",width);
jaddnum(valsobj,"timeout",2500);
jaddnum(valsobj,"fanout",(int32_t)sqrt(NUMRELAYS)+1);
jaddnum(valsobj,"minresults",1);
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
jaddnum(valsobj,"numrequired",1);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 )
{
//printf("channel.%u msgid.%u gotmessage.(%s)\n",channel,msgid,retstr);

419
basilisk/basilisk_bitcoin.c

@ -299,7 +299,7 @@ int32_t basilisk_bitcoinavail(struct iguana_info *coin)
void *basilisk_bitcoinbalances(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals)
{
int64_t balance,total = 0; int32_t i,n,hist; cJSON *spends,*unspents,*retjson,*item,*addresses,*array = cJSON_CreateArray();
int64_t balance,total = 0; int32_t i,j,n,hist; char *str; cJSON *spends,*unspents,*retjson,*item,*addresses,*array = cJSON_CreateArray();
spends = unspents = 0;
if ( (hist= juint(vals,"history")) != 0 )
{
@ -313,13 +313,20 @@ void *basilisk_bitcoinbalances(struct basilisk_item *Lptr,struct supernet_info *
{
for (i=0; i<n; i++)
{
//if ( coin->RTheight > 0 )
balance = iguana_addressreceived(myinfo,coin,vals,remoteaddr,0,0,unspents,spends,jstri(addresses,i),juint(vals,"minconf"),juint(vals,"firstheight"));
//else balance = 0;
item = cJSON_CreateObject();
jaddnum(item,jstri(addresses,i),dstr(balance));
jaddi(array,item);
total += balance;
if ( (str= jstri(addresses,i)) != 0 )
{
for (j=0; j<n; j++)
if ( jstri(addresses,j) != 0 && strcmp(jstri(addresses,j),str) == 0 )
break;
if ( j == n )
continue;
balance = iguana_addressreceived(myinfo,coin,vals,remoteaddr,0,0,unspents,spends,str,juint(vals,"minconf"),0);//juint(vals,"firstheight"));
item = cJSON_CreateObject();
jaddnum(item,str,dstr(balance));
jaddstr(item,"address",str);
jaddi(array,item);
total += balance;
}
//printf("%.8f ",dstr(balance));
}
}
@ -335,6 +342,7 @@ void *basilisk_bitcoinbalances(struct basilisk_item *Lptr,struct supernet_info *
jaddnum(retjson,"RTheight",coin->RTheight);
jaddnum(retjson,"longest",coin->longestchain);
jaddnum(retjson,"lag",coin->longestchain- coin->RTheight);
//printf("BAL.(%s)\n",jprint(retjson,0));
Lptr->retstr = jprint(retjson,1);
return(Lptr);
}
@ -374,7 +382,7 @@ double basilisk_bitcoin_valuemetric(struct supernet_info *myinfo,struct basilisk
void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
int32_t i,height,vout,numsent; struct basilisk_item *ptr; char coinaddr[64],str[64]; struct basilisk_value *v; uint64_t value = 0; bits256 txid;
int32_t i,height,vout,numsent; struct basilisk_item *ptr; char coinaddr[64],str[65]; struct basilisk_value *v; uint64_t value = 0; bits256 txid; struct iguana_outpoint outpt;
if ( RELAYID >= 0 )
return(0);
txid = jbits256(valsobj,"txid");
@ -383,7 +391,7 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi
{
if ( (coin->VALIDATENODE != 0 || coin->FULLNODE != 0) )//&& coinaddr != 0 && coinaddr[0] != 0 )
{
if ( iguana_RTunspentindfind(myinfo,coin,coinaddr,0,0,&value,&height,txid,vout,coin->bundlescount,0) > 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,coinaddr,0,0,&value,&height,txid,vout,coin->bundlescount,0) == 0 )
{
//printf("bitcoinvalue found iguana\n");
Lptr->retstr = basilisk_valuestr(coin,coinaddr,value,height,txid,vout);
@ -401,18 +409,40 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi
if ( v->vout == vout && bits256_cmp(txid,v->txid) == 0 && strcmp(v->coinaddr,coinaddr) == 0 )
{
printf("bitcoinvalue local ht.%d %s %.8f\n",v->height,v->coinaddr,dstr(v->value));
ptr = basilisk_issueremote(myinfo,0,&numsent,"VAL",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,0,basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout),0,0,BASILISK_DEFAULTDIFF); // this completes immediate
ptr = basilisk_issueremote(myinfo,0,&numsent,"VAL",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"numrequired"),basilisktag,timeoutmillis,0,basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout),0,0,BASILISK_DEFAULTDIFF); // this completes immediate
//queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
return(ptr);
}
}
}
printf("bitcoinvalue issue remote tag.%u\n",basilisktag);
ptr = basilisk_issueremote(myinfo,0,&numsent,"VAL",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF);
ptr = basilisk_issueremote(myinfo,0,&numsent,"VAL",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"numrequired"),basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF);
//queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
return(ptr);
}
void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
struct basilisk_item *ptr; cJSON *infojson; int32_t numsent,fanout,numrequired;
if ( RELAYID >= 0 )
return(0);
if ( coin->VALIDATENODE != 0 || coin->FULLNODE != 0 )
{
infojson = iguana_getinfo(myinfo,coin);
Lptr->retstr = jprint(infojson,1);
return(Lptr);
}
if ( (fanout= juint(valsobj,"fanout")) < 5 )
fanout = 5;
if ( (numrequired= juint(valsobj,"numrequired")) < fanout )
{
jaddnum(valsobj,"numrequired",fanout);
numrequired = fanout;
}
ptr = basilisk_issueremote(myinfo,0,&numsent,"INF",coin->symbol,1,valsobj,fanout,numrequired,basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF);
return(ptr);
}
int32_t basilisk_voutvin_validate(struct iguana_info *coin,char *rawtx,uint64_t inputsum,uint64_t amount,uint64_t txfee)
{
//static int counter;
@ -505,10 +535,10 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
jadd(valsobj,"addresses",addresses);
}
//printf("use addresses.(%s)\n",jprint(addresses,0));
//printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr);
printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr);
if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 )
return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}"));
if ( coin != 0 )//&& basilisk_bitcoinavail(coin) != 0 )
if ( coin != 0 )
{
if ( (txobj= bitcoin_txcreate(coin->chain->isPoS,locktime,locktime==0?coin->chain->normal_txversion:coin->chain->locktime_txversion)) != 0 )
{
@ -524,7 +554,10 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
decode_hex(&buf[sizeof(buf) - oplen],oplen,opreturn);
spendlen = datachain_datascript(coin,buf,&buf[sizeof(buf) - oplen],oplen);
if ( (burnamount= SATOSHIDEN * jdouble(valsobj,"burn")) < 10000 )
burnamount = 10000;
{
//burnamount = 10000;
printf("low burnamount %.8f\n",dstr(burnamount));
}
bitcoin_txoutput(txobj,buf,spendlen,burnamount);
oplen = 0;
} else oplen = datachain_opreturnscript(coin,buf,opreturn,oplen);
@ -552,7 +585,6 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
return(clonestr("{\"error\":\"couldnt create rawtx\"}"));
}
return(clonestr("{\"error\":\"dont have coin to create rawtx\"}"));
//return(basilisk_issueremote(myinfo,0,&numsent,"RAW",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF));
}
/*
@ -791,7 +823,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+1);
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
if ( coin != 0 )
{
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
@ -808,99 +840,66 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
return(basilisk_standardservice("VAL",myinfo,0,hash,vals,hexstr,1));
}
/*HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray;
char *retstr=0,*symbol; uint32_t basilisktag; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray;
//if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",myinfo->numrelays);
jaddnum(vals,"numrequired",NUMRELAYS);
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(myinfo->numrelays));
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
if ( coin != 0 )
{
if ( juint(vals,"burn") == 0 )
jaddnum(vals,"burn",0.0001);
//if ( juint(vals,"burn") == 0 )
// jaddnum(vals,"burn",0.0001);
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( (ptr= basilisk_bitcoinrawtx(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
if ( (retstr= basilisk_bitcoinrawtx(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
{
if ( (retstr= ptr->retstr) != 0 )
printf("rawtx.(%s)\n",retstr);
if ( (amount= j64bits(vals,"satoshis")) == 0 )
amount = jdouble(vals,"value") * SATOSHIDEN;
if ( (txfee= j64bits(vals,"txfee")) == 0 )
txfee = coin->chain->txfee;
if ( txfee == 0 )
txfee = 10000;
retval = -1;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
if ( (amount= j64bits(vals,"satoshis")) == 0 )
amount = jdouble(vals,"value") * SATOSHIDEN;
if ( (txfee= j64bits(vals,"txfee")) == 0 )
txfee = coin->chain->txfee;
if ( txfee == 0 )
txfee = 10000;
retval = -1;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
if ( is_cJSON_Array(retarray) != 0 )
{
if ( is_cJSON_Array(retarray) != 0 )
for (i=0; i<cJSON_GetArraySize(retarray); i++)
{
for (i=0; i<cJSON_GetArraySize(retarray); i++)
if ( basilisk_vins_validate(myinfo,coin,jitem(retarray,i),amount,txfee) == 0 )
{
if ( basilisk_vins_validate(myinfo,coin,jitem(retarray,i),amount,txfee) == 0 )
{
retval = 0;
break;
}
retval = 0;
break;
}
} else retval = basilisk_vins_validate(myinfo,coin,retarray,amount,txfee);
if ( retval < 0 )
{
printf("ERROR.(%s)\n",retstr);
free(retstr);
retstr = clonestr("{\"error\":\"invalid vin in rawtx\"}");
}
} else retval = basilisk_vins_validate(myinfo,coin,retarray,amount,txfee);
if ( retval < 0 )
{
printf("ERROR.(%s)\n",retstr);
free(retstr);
retstr = clonestr("{\"error\":\"invalid vin in rawtx\"}");
}
ptr->retstr = 0;
ptr->finished = (uint32_t)time(NULL);
}
}
}
} else retstr = clonestr("{\"error\":\"no coin specified or found\"}");
return(retstr);
}*/
cJSON *basilisk_history_item(struct iguana_info *coin,int64_t *totalp,char *coinaddr,int64_t value,uint32_t timestamp,bits256 txid,char *vinvoutstr,int32_t vinvout,int32_t height,char *otherheightstr,int32_t otherheight,uint64_t relaymask,int32_t ismine)
{
cJSON *item,*details;
item = cJSON_CreateObject();
jaddstr(item,"address",coinaddr);
jaddnum(item,"amount",dstr(value));
jaddnum(item,"numseconds",time(NULL) - timestamp);
details = cJSON_CreateObject();
if ( ismine > 0 )
{
jaddnum(details,"ismine",ismine);
if ( strcmp(vinvoutstr,"spentheight") == 0 )
jaddstr(details,"category","sent");
else jaddstr(details,"category","received");
}
jaddbits256(details,"txid",txid);
jaddnum(details,vinvoutstr,vinvout);
jaddnum(details,"height",height);
if ( coin->blocks.hwmchain.height > 0 )
jaddnum(details,"confirms",coin->blocks.hwmchain.height - height);
jaddnum(details,"height",height);
if ( otherheight != 0 )
jaddnum(details,otherheightstr,otherheight);
else *totalp += value;
jaddnum(details,"relays",bitweight(relaymask));
jadd(item,"details",details);
return(item);
}
#include "../includes/iguana_apiundefs.h"
int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,uint8_t *spendscript,struct iguana_outpoint outpt,int64_t value)
{
struct basilisk_unspent *bu; int32_t i,spendlen; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2; char str[65];
struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2;
memset(txidp,0,sizeof(*txidp));
*voutp = -1;
portable_mutex_lock(&myinfo->bu_mutex);
@ -908,221 +907,109 @@ int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *co
{
HASH_ITER(hh,wacct->waddr,waddr,tmp2)
{
for (i=0; i<waddr->numunspents; i++)
{
bu = &waddr->unspents[i];
if ( bu->hdrsi == outpt.hdrsi && bu->unspentind == outpt.unspentind && bu->value == value )
{
if ( bu->status == 0 )
{
*txidp = bu->txid;
*voutp = bu->vout;
memcpy(spendscript,bu->script,bu->spendlen);
spendlen = bu->spendlen;
portable_mutex_unlock(&myinfo->bu_mutex);
return(spendlen);
} else printf("unspentfind skip %s/v%d\n",bits256_str(str,bu->txid),bu->vout);
}
}
printf("need to port basilisk_unspentfind\n");
}
}
portable_mutex_unlock(&myinfo->bu_mutex);
return(-1);
}
struct basilisk_spend *basilisk_addspend(struct supernet_info *myinfo,char *symbol,bits256 txid,uint16_t vout,int32_t addflag)
cJSON *basilisk_jsonmerge(char *symbol,cJSON *array)
{
int32_t i=0; struct basilisk_spend *s;
// mutex
if ( myinfo->numspends > 0 )
int32_t i,j,n,m; cJSON *jobj,*iobj,*dest = cJSON_CreateArray();
if ( dest != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<myinfo->numspends; i++)
for (i=0; i<n; i++)
{
if ( myinfo->spends[i].vout == vout && bits256_cmp(txid,myinfo->spends[i].txid) == 0 )
m = cJSON_GetArraySize(dest);
iobj = jitem(array,i);
for (j=0; j<m; j++)
{
char str[65]; printf("found spend.%s v%d skip it\n",bits256_str(str,txid),vout);
return(&myinfo->spends[i]);
jobj = jitem(dest,j);
if ( bits256_cmp(jbits256(jobj,"txid"),jbits256(iobj,"txid")) == 0 && jint(jobj,"vout") == jint(iobj,"vout") )
{
//printf("(%s) == (%s)\n",jprint(iobj,0),jprint(jobj,0));
break;
}
}
if ( j == m )
{
jaddi(dest,jduplicate(iobj));
//printf("add.(%s) ",jprint(iobj,0));
} //else printf("j.%d != m.%d\n",j,m);
}
}
if ( addflag != 0 && i == myinfo->numspends )
{
//printf("realloc spends.[%d] %p\n",myinfo->numspends,myinfo->spends);
myinfo->spends = realloc(myinfo->spends,sizeof(*myinfo->spends) * (myinfo->numspends+1));
//printf("allocated spends.[%d] %p\n",myinfo->numspends+1,myinfo->spends);
s = &myinfo->spends[myinfo->numspends++];
memset(s,0,sizeof(*s));
s->txid = txid;
s->vout = vout;
strcpy(s->symbol,symbol);
//char str[65]; printf("ADDSPEND.%s %s/v%d\n",symbol,bits256_str(str,txid),vout);
// mutex
return(s);
}
// mutex
return(0);
return(dest);
}
void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *item,int32_t spentheight,int32_t relayid,int32_t RTheight)
void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json)
{
//{"txid":"4814dc8a357f93f16271eb43806a69416ec41ab1956b128d170402b0a1b37c7f","vout":2,"address":"RSyKVKNxrSDc1Vwvh4guYb9ZDEpvMFz2rm","scriptPubKey":"76a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac","amount":9.99920000,"timestamp":1466684518,"height":1160306,"confirmations":22528,"checkind":1157,"spent":{"hdrsi":2320,"pkind":168,"unspentind":1157,"prevunspentind":0,"satoshis":"999920000","txidind":619,"vout":2,"type":2,"fileid":0,"scriptpos":0,"scriptlen":25},"spentheight":1161800,"dest":{"error":"couldnt find spent info"}}
int32_t i,n,j,m,already_spent=0; struct basilisk_unspent bu,bu2; char *address,*script=0,*destaddr; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0; cJSON *dest,*vouts,*vitem; double ratio;
if ( (address= jstr(item,"address")) != 0 && (script= jstr(item,"scriptPubKey")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
cJSON *unspents,*spends,*item; int32_t n; char *address; //struct iguana_waccount *wacct; struct iguana_waddress *waddr=0;
if ( (spends= jarray(&n,json,"spends")) != 0 && n > 0 )
{
if ( relayid >= 64 )
relayid = 0;
memset(&bu,0,sizeof(bu));
bu.spendlen = (int32_t)strlen(script) >> 1;
if ( bu.spendlen > sizeof(bu.script) )
item = jitem(spends,0);
if ( (address= jstr(item,"address")) != 0 )//&& (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
{
printf("spendscript too big.%d\n",bu.spendlen);
return;
if ( myinfo->Cspends == 0 )
myinfo->Cspends = cJSON_CreateObject();
if ( jobj(myinfo->Cspends,coin->symbol) != 0 )
jdelete(myinfo->Cspends,coin->symbol);
jadd(myinfo->Cspends,coin->symbol,basilisk_jsonmerge(coin->symbol,spends));
//printf("S.(%s)\n",jprint(waddr->Cspends,0));
}
strcpy(bu.symbol,coin->symbol);
bu.txid = jbits256(item,"txid");
bu.vout = jint(item,"vout");
bu.value = jdouble(item,"amount") * SATOSHIDEN;
bu.height = jint(item,"height");
bu.hdrsi = (bu.height / coin->chain->bundlesize);
bu.unspentind = juint(item,"checkind");
bu.timestamp = juint(item,"timestamp");
decode_hex(bu.script,bu.spendlen,script);
//printf("unspentupdate.(%s)\n",jprint(item,0));
n = waddr->numunspents;
for (i=0; i<n; i++)
{
bu2 = waddr->unspents[i];
bu2.status = 0;
bu2.RTheight = bu2.spentheight = 0;
bu2.relaymask = 0;
if ( memcmp(&bu,&bu2,sizeof(bu)) == 0 )
{
if ( waddr->unspents[i].RTheight > RTheight )
RTheight = waddr->unspents[i].RTheight;
already_spent = waddr->unspents[i].spentheight;
bu.relaymask = waddr->unspents[i].relaymask;
if ( (bu.status= waddr->unspents[i].status) != 0 )
{
//printf("mempool spend for %s/%d\n",bits256_str(str,bu.txid),bu.vout);
}
break;
}
}
bu.RTheight = RTheight;
bu.relaymask |= ((uint64_t)1 << relayid);
//printf("relayid.%d -> %llx wt.%d\n",relayid,(long long)bu.relaymask,bitweight(bu.relaymask));
if ( spentheight != 0 )
already_spent = spentheight;
if ( (bu.spentheight= already_spent) != 0 )
bu.status = 1;
if ( i == n )
//printf("merge spends.(%s)\n",jprint(spends,0));
}
if ( (unspents= jarray(&n,json,"unspents")) != 0 && n > 0 )
{
item = jitem(unspents,0);
if ( (address= jstr(item,"address")) != 0 )//&& (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
{
if ( i >= waddr->maxunspents )
{
waddr->maxunspents += 16;
waddr->unspents = realloc(waddr->unspents,sizeof(*waddr->unspents) * waddr->maxunspents);
//printf("allocate max.%d for %s\n",waddr->maxunspents,waddr->coinaddr);
}
waddr->numunspents++;
//printf("new unspent.%s %d script.%p [%d] (%s)\n",waddr->coinaddr,waddr->numunspents,bu.script,bu.spendlen,jprint(item,0));
if ( bu.spentheight != 0 && (dest= jobj(item,"dest")) != 0 )
{
struct basilisk_spend *s;
//{"txid":"cd4fb72f871d481c534f15d7f639883958936d49e965f58276f0925798e762df","vin":1,"height":<spentheight>,"unspentheight":<bu.height>,"relays":2}},
if ( (s= basilisk_addspend(myinfo,coin->symbol,bu.txid,bu.vout,1)) != 0 )
{
s->spentfrom = jbits256(dest,"spentfrom");
s->vini = jint(dest,"vin");
s->height = bu.spentheight;
s->timestamp = juint(dest,"timestamp");
s->unspentheight = bu.height;
s->relaymask = bu.relaymask;
ratio = jdouble(dest,"ratio");
if ( (vouts= jobj(dest,"vouts")) != 0 && (m= cJSON_GetArraySize(vouts)) > 0 )
{
for (j=0; j<m; j++)
{
vitem = jitem(vouts,j);
if ( (destaddr= jfieldname(vitem)) != 0 )
{
safecopy(s->destaddr,destaddr,sizeof(s->destaddr));
s->ismine = (iguana_waddresssearch(myinfo,&wacct,destaddr) != 0);
s->value = jdouble(vitem,jfieldname(vitem)) * SATOSHIDEN;
//printf("(%s %.8f) ",s->destaddr,dstr(s->value));
}
}
//char str[65]; printf("SPEND dest.(%s) ratio %.8f (%s/v%d)\n",jprint(dest,0),ratio,bits256_str(str,s->txid),s->vini);
}
}
}
waddr->unspents[i] = bu;
if ( myinfo->Cunspents == 0 )
myinfo->Cunspents = cJSON_CreateObject();
if ( jobj(myinfo->Cunspents,coin->symbol) != 0 )
jdelete(myinfo->Cunspents,coin->symbol);
jadd(myinfo->Cunspents,coin->symbol,basilisk_jsonmerge(coin->symbol,unspents));
//printf("U.(%s)\n",jprint(myinfo->Cunspents,0));
}
} else printf("waddr.%p script.%p address.%p %s\n",waddr,script,address,address!=0?address:"");
//printf("merge unspents.(%s)\n",jprint(unspents,0));
}
}
void basilisk_relay_unspentsprocess(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *relayjson)
void basilisk_unspents_process(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr)
{
int32_t RTheight,relayid,num,j; cJSON *unspents,*spends;
RTheight = jint(relayjson,"RTheight");
if ( (relayid= basilisk_relayid(myinfo,(uint32_t)calc_ipbits(jstr(relayjson,"relay")))) < BASILISK_MAXRELAYS )
{
coin->relay_RTheights[relayid] = RTheight;
}
//printf("basilisk_relay_unspentsprocess relayid.%d RT.%d (%s)\n",relayid,RTheight,jprint(relayjson,0));
if ( (unspents= jarray(&num,relayjson,"unspents")) != 0 )
{
for (j=0; j<num; j++)
basilisk_unspent_update(myinfo,coin,jitem(unspents,j),0,relayid,RTheight);
}
if ( (spends= jarray(&num,relayjson,"spends")) != 0 )
cJSON *retarray; int32_t i,n;
portable_mutex_lock(&myinfo->bu_mutex);
if ( myinfo->Cspends != 0 )
free_json(myinfo->Cspends), myinfo->Cspends = 0;
if ( myinfo->Cunspents != 0 )
free_json(myinfo->Cunspents), myinfo->Cunspents = 0;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
for (j=0; j<num; j++)
basilisk_unspent_update(myinfo,coin,jitem(spends,j),jint(jitem(spends,j),"spentheight"),relayid,RTheight);
if ( is_cJSON_Array(retarray) != 0 )
{
n = cJSON_GetArraySize(retarray);
for (i=0; i<n; i++)
basilisk_unspent_update(myinfo,coin,jitem(retarray,i));
} else basilisk_unspent_update(myinfo,coin,retarray);
free_json(retarray);
}
portable_mutex_unlock(&myinfo->bu_mutex);
}
void basilisk_unspents_update(struct supernet_info *myinfo,struct iguana_info *coin)
{
char *retstr; cJSON *retarray,*vals; int32_t oldest,i,n,RTheight;
//if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 )
{
vals = cJSON_CreateObject();
for (i=oldest=0; i<BASILISK_MAXRELAYS; i++)
if ( (RTheight= coin->relay_RTheights[i]) != 0 && (oldest == 0 || RTheight < oldest) )
oldest = RTheight;
jaddnum(vals,"firstheight",oldest);
jaddnum(vals,"history",3);
jaddstr(vals,"coin",coin->symbol);
if ( (retstr= basilisk_balances(myinfo,coin,0,0,GENESIS_PUBKEY,vals,"")) != 0 )
{
portable_mutex_lock(&myinfo->bu_mutex);
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
//printf("%s UNSPENTS_UPDATE.(%s)\n",coin->symbol,retstr);
if ( jobj(retarray,"error") == 0 )
{
if ( (jstr(retarray,"ipaddr") == 0 || strcmp(jstr(retarray,"ipaddr"),myinfo->ipaddr) != 0) && (n= cJSON_GetArraySize(retarray)) > 0 )
{
for (i=0; i<n; i++)
basilisk_relay_unspentsprocess(myinfo,coin,jitem(retarray,i));
} else basilisk_relay_unspentsprocess(myinfo,coin,retarray);
if ( 0 )
{
bits256 pubAm,pubBn; struct basilisk_rawtx test; struct basilisk_swap swap;
memset(&swap,0,sizeof(swap));
printf("create alicepayment\n");
swap.alicecoin = iguana_coinfind("BTCD");
swap.alicesatoshis = 100000;
basilisk_rawtx_setparms("alicepayment",myinfo,&swap,&test,swap.alicecoin,swap.aliceconfirms,0,swap.alicesatoshis,2,0);
basilisk_alicepayment(myinfo,swap.alicecoin,&test,pubAm,pubBn);
}
}
} else printf("couldnt parse.(%s)\n",retstr);
if ( retarray != 0 )
free_json(retarray);
free(retstr);
portable_mutex_unlock(&myinfo->bu_mutex);
}
free_json(vals);
}
char *retstr; cJSON *vals; int32_t oldest,i,RTheight;
vals = cJSON_CreateObject();
for (i=oldest=0; i<BASILISK_MAXRELAYS; i++)
if ( (RTheight= coin->relay_RTheights[i]) != 0 && (oldest == 0 || RTheight < oldest) )
oldest = RTheight;
jaddnum(vals,"firstheight",oldest);
jaddnum(vals,"history",3);
jaddstr(vals,"coin",coin->symbol);
if ( (retstr= basilisk_balances(myinfo,coin,0,0,GENESIS_PUBKEY,vals,"")) != 0 )
{
basilisk_unspents_process(myinfo,coin,retstr);
free(retstr);
}
free_json(vals);
}

1
basilisk/basilisk_ping.c

@ -231,6 +231,7 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
//len += basilisk_ping_processvirts(myinfo,btcd,addr,&data[len],datalen - len);
for (i=0; i<numrelays; i++)
{
rp = &RELAYS[i];
if ( len > datalen )
break;
if ( (n= basilisk_ping_processrelay(myinfo,&data[len],datalen-len,rp,i)) < 0 )

4
basilisk/basilisk_swap.c

@ -576,11 +576,11 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct
item = jitem(vins,i);
txid = jbits256(item,"txid");
vout = jint(item,"vout");
if ( bits256_nonz(txid) != 0 )
/*if ( bits256_nonz(txid) != 0 )
{
char str[65]; printf("call addspend.(%s) v.%d\n",bits256_str(str,txid),vout);
basilisk_addspend(myinfo,rawtx->coin->symbol,txid,vout,1);
}
}*/
}
}
}

7
basilisk/basilisk_tradebot.c

@ -229,6 +229,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_request *issueR,cJSON *retjson,double hwm)
{
cJSON *array,*item; int32_t i,n,m,nonz; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.;
memset(&refR,0,sizeof(refR));
if ( (array= jarray(&n,retjson,"result")) != 0 )
{
for (i=nonz=m=0; i<n; i++)
@ -244,7 +245,11 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
else
{
if ( (metric= basilisk_request_listprocess(myinfo,&tmpR,list,m)) > hwm )
*issueR = tmpR, hwm = metric;
{
*issueR = tmpR;
hwm = metric;
refR = tmpR;
}
m = 0;
}
}

107
crypto777/OS_nonportable.c

@ -47,6 +47,85 @@ void *OS_nonportable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,l
#include <tlhelp32.h>
#include <time.h>
#include <intrin.h>
static uint32_t __inline __builtin_clzll(uint64_t x) {
unsigned long r = 0;
_BitScanReverse64(&r, x);
return (63-r);
}
void usleep(int32_t micros)
{
if ( micros < 1000 )
Sleep(1);
else Sleep(micros / 1000);
}
int
mkstemp (template)
char *template;
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static uint64_t value;
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
#endif
char *XXXXXX;
size_t len;
int count;
len = strlen (template);
if ((int) len < 6
|| strncmp (&template[len - 6], "XXXXXX", 6))
{
return -1;
}
XXXXXX = &template[len - 6];
#ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */
gettimeofday (&tv, NULL);
value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
#else
value += getpid ();
#endif
for (count = 0; count < TMP_MAX; ++count)
{
uint64_t v = value;
int fd;
/* Fill in the random bits. */
XXXXXX[0] = letters[v % 62];
v /= 62;
XXXXXX[1] = letters[v % 62];
v /= 62;
XXXXXX[2] = letters[v % 62];
v /= 62;
XXXXXX[3] = letters[v % 62];
v /= 62;
XXXXXX[4] = letters[v % 62];
v /= 62;
XXXXXX[5] = letters[v % 62];
fd = open (template, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600);
if (fd >= 0)
/* The file does not exist. */
return fd;
/* This is a random value. It is only necessary that the next
TMP_MAX values generated by adding 7777 to VALUE are different
with (module 2^32). */
value += 7777;
}
/* We return the null string if we can't find a unique file name. */
template[0] = '\0';
return -1;
}
#include "../OSlibs/win/mman.h"
@ -496,10 +575,10 @@ char *OS_nonportable_path(char *str)
return(str);
}
void *OS_nonportable_mapfile(char *fname,uint64_t *filesizep,int32_t enablewrite)
void *OS_nonportable_mapfile(char *fname,long *filesizep,int32_t enablewrite)
{
int32_t fd,rwflags,flags = MAP_FILE|MAP_SHARED;
uint64_t filesize;
long filesize;
void *ptr = 0;
*filesizep = 0;
if ( enablewrite != 0 )
@ -511,7 +590,7 @@ void *OS_nonportable_mapfile(char *fname,uint64_t *filesizep,int32_t enablewrite
return(0);
}
if ( *filesizep == 0 )
filesize = (uint64_t)lseek(fd,0,SEEK_END);
filesize = (long)lseek(fd,0,SEEK_END);
else filesize = *filesizep;
rwflags = PROT_READ;
if ( enablewrite != 0 )
@ -528,15 +607,23 @@ void *OS_nonportable_mapfile(char *fname,uint64_t *filesizep,int32_t enablewrite
return(ptr);
}
int32_t OS_nonportable_renamefile(char *fname,char *newfname)
int32_t OS_nonportable_removefile(char *fname)
{
char cmdstr[1024],tmp[512];
char tmp[512];
strcpy(tmp,fname);
OS_nonportable_path(tmp);
sprintf(cmdstr,"del %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting file.(%s)\n",cmdstr);
else return(1);
OS_portable_path(tmp);
return((DeleteFileA(tmp) == 0) ? -1 : 0);
}
int32_t OS_nonportable_renamefile(char *fname,char *newfname)
{
char tmp[1024],tmp2[1024]; int32_t retval,retvaldel;
strcpy(tmp,fname), strcpy(tmp2,newfname);
OS_nonportable_path(tmp), OS_nonportable_path(tmp2);
retvaldel = OS_nonportable_removefile(tmp2);
retval = MoveFileA(tmp,tmp2);
//printf("call Movefile(%s -> %s) retval.%d retvaldel.%d %d\n",tmp,tmp2,retval,retvaldel,GetLastError());
return((retval == 0) ? -1 : 0);
}
int32_t OS_nonportable_launch(char *args[])

24
crypto777/OS_portable.c

@ -30,7 +30,7 @@ void OS_portable_init()
void OS_portable_randombytes(unsigned char *x,long xlen)
{
#ifdef _WIN32
return(OS_nonportable_randombytes(x,xlen));
OS_nonportable_randombytes(x,xlen);
#else
static int fd = -1;
int32_t i;
@ -97,13 +97,7 @@ char *OS_portable_path(char *str)
int32_t OS_portable_renamefile(char *fname,char *newfname)
{
#ifdef _WIN32
char cmdstr[1024],tmp[512];
strcpy(tmp,fname);
OS_portable_path(tmp);
sprintf(cmdstr,"del %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting file.(%s)\n",cmdstr);
else return(1);
return(OS_nonportable_renamefile(fname,newfname));
#else
return(rename(fname,newfname));
#endif
@ -112,13 +106,7 @@ int32_t OS_portable_renamefile(char *fname,char *newfname)
int32_t OS_portable_removefile(char *fname)
{
#ifdef _WIN32
char cmdstr[1024],tmp[512];
strcpy(tmp,fname);
OS_portable_path(tmp);
sprintf(cmdstr,"del %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting file.(%s)\n",cmdstr);
else return(1);
return(OS_nonportable_removefile(fname));
#else
return(remove(fname));
#endif
@ -131,7 +119,7 @@ int32_t OS_portable_rmdir(char *dirname,int32_t diralso)
strcpy(tmp,dirname);
OS_portable_path(tmp);
#ifdef _WIN32
sprintf(cmdstr,"del %s\*.*",tmp);
sprintf(cmdstr,"rmdir %s",tmp);
if ( system(cmdstr) != 0 )
printf("error deleting dir.(%s)\n",cmdstr);
else return(1);
@ -169,7 +157,7 @@ void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite)
return(OS_nonportable_mapfile(fname,filesizep,enablewrite));
#else
int32_t fd,rwflags,flags = MAP_FILE|MAP_SHARED;
uint64_t filesize;
long filesize;
void *ptr = 0;
*filesizep = 0;
if ( enablewrite != 0 )
@ -181,7 +169,7 @@ void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite)
return(0);
}
if ( *filesizep == 0 )
filesize = (uint64_t)lseek(fd,0,SEEK_END);
filesize = (long)lseek(fd,0,SEEK_END);
else filesize = *filesizep;
rwflags = PROT_READ;
if ( enablewrite != 0 )

65
crypto777/OS_portable.h

@ -17,11 +17,18 @@
// iguana_OS has functions that invoke system calls. Whenever possible stdio and similar functions are use and most functions are fully portable and in this file. For things that require OS specific, the call is routed to iguana_OS_portable_* Usually, all but one OS can be handled with the same code, so iguana_OS_portable.c has most of this shared logic and an #ifdef iguana_OS_nonportable.c
#ifdef NATIVE_WINDOWS
//#define uint64_t unsigned __int64
#define PACKED
#else
#define PACKED __attribute__((packed))
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define HAVE_STRUCT_TIMESPEC
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#include <math.h>
@ -30,28 +37,29 @@
#include <sys/types.h>
#include <time.h>
#ifdef __MINGW
#ifdef WIN32
#define sleep(x) Sleep(1000*(x))
#include "../OSlibs/win/mingw.h"
#include "../OSlibs/win/mman.h"
#include "../OSlibs/win/pthread.h"
#ifndef NATIVE_WINDOWS
#define EADDRINUSE WSAEADDRINUSE
#endif
#else
//#include <sys/poll.h>
#include <sys/time.h>
#include <time.h>
#include <poll.h>
#include <netdb.h>
#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
//#include <netinet/in.h>
//#include "in.h"
#include <sys/mman.h>
#include <sys/socket.h>
//#include <winsock2.h>
#include <unistd.h>
#define closesocket close
#endif
#ifndef MIN
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
#endif
@ -119,8 +127,8 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode);
#define issue_curl(cmdstr) bitcoind_RPC(0,"curl",cmdstr,0,0,0)
struct allocitem { uint32_t allocsize,type; } __attribute__((packed));
struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; } __attribute__((packed));
struct allocitem { uint32_t allocsize,type; } PACKED;
struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; } PACKED;
typedef struct queue
{
struct queueitem *list;
@ -192,8 +200,8 @@ void OS_remove_directory(char *dirname);
int32_t OS_portable_renamefile(char *fname,char *newfname);
int32_t OS_portable_removefile(char *fname);
void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len);
void *OS_portable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
//int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len);
//void *OS_portable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
int32_t is_DST(int32_t datenum);
int32_t extract_datenum(int32_t *yearp,int32_t *monthp,int32_t *dayp,int32_t datenum);
@ -203,31 +211,36 @@ int32_t ecb_decrdate(int32_t *yearp,int32_t *monthp,int32_t *dayp,char *date,int
int32_t conv_date(int32_t *secondsp,char *buf);
uint32_t OS_conv_datenum(int32_t datenum,int32_t hour,int32_t minute,int32_t second);
int32_t OS_conv_unixtime(struct tai *t,int32_t *secondsp,time_t timestamp);
double OS_milliseconds();
void OS_randombytes(uint8_t *x,long xlen);
int32_t OS_truncate(char *fname,long filesize);
char *OS_compatible_path(char *str);
int32_t OS_renamefile(char *fname,char *newfname);
int32_t OS_removefile(char *fname,int32_t scrubflag);
void OS_ensure_directory(char *dirname);
int64_t OS_filesize(char *fname);
int32_t OS_compare_files(char *fname,char *fname2);
int64_t OS_copyfile(char *src,char *dest,int32_t cmpflag);
int32_t OS_releasemap(void *ptr,uint64_t filesize);
void _OS_closemap(struct OS_mappedptr *mp);
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep);
void *OS_filestr(long *allocsizep,char *fname);
void OS_closemap(struct OS_mappedptr *mp);
long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag);
int32_t OS_openmap(struct OS_mappedptr *mp);
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,uint64_t allocsize,int32_t rwflag,char *fname);
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,unsigned long allocsize,int32_t rwflag,char *fname);
void *OS_filealloc(struct OS_mappedptr *M,char *fname,struct OS_memspace *mem,long size);
void *OS_nonportable_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_nonportable_removefile(char *fname);
unsigned long OS_filesize(char *fname);
void OS_ensure_directory(char *dirname);
long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag);
int32_t OS_truncate(char *fname,long filesize);
int32_t OS_renamefile(char *fname,char *newfname);
int32_t OS_removefile(char *fname,int32_t scrubflag);
void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite);
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep);
void *OS_filestr(long *allocsizep,char *fname);
int32_t OS_releasemap(void *ptr,unsigned long filesize);
double OS_milliseconds();
void OS_randombytes(uint8_t *x,long xlen);
int32_t OS_syncmap(struct OS_mappedptr *mp,long len);
void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
//int32_t OS_syncmap(struct OS_mappedptr *mp,long len);
//void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
long myallocated(uint8_t type,long change);
void *mycalloc(uint8_t type,int32_t n,long itemsize);
@ -347,7 +360,7 @@ void SaM_PrepareIndices();
// iguana_serdes.c
#define IGUANA_LOG2PACKETSIZE 21
#define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE)
struct iguana_msghdr { uint8_t netmagic[4]; char command[12]; uint8_t serdatalen[4],hash[4]; } __attribute__((packed));
struct iguana_msghdr { uint8_t netmagic[4]; char command[12]; uint8_t serdatalen[4],hash[4]; } PACKED;
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t iguana_validatehdr(char *symbol,struct iguana_msghdr *H);

8
crypto777/OS_time.c

@ -56,7 +56,7 @@ struct tm *gmtime_r(const time_t *timep,struct tm *result)
/*typedef struct timeval {
long tv_sec;
long tv_usec;
} timeval;
} timeval;*/
int gettimeofday(struct timeval * tp, struct timezone * tzp)
{
@ -75,7 +75,7 @@ int gettimeofday(struct timeval * tp, struct timezone * tzp)
tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
return 0;
}*/
}
#endif
double OS_portable_milliseconds()
@ -536,7 +536,7 @@ uint32_t OS_conv_datenum(int32_t datenum,int32_t hour,int32_t minute,int32_t sec
}
return(0);
}
else
/*else
{
#ifdef __PNACL
return(0);
@ -547,7 +547,7 @@ uint32_t OS_conv_datenum(int32_t datenum,int32_t hour,int32_t minute,int32_t sec
t.tm_hour = hour, t.tm_min = minute, t.tm_sec = second;
return((uint32_t)timegm(&t));
#endif
}
}*/
}
int32_t OS_conv_unixtime(struct tai *tp,int32_t *secondsp,time_t timestamp) // gmtime -> datenum + number of seconds

2
crypto777/SaM.c

@ -46,7 +46,7 @@ struct SaM_info { bits384 bits; TRIT trits[SAM_STATE_SIZE],hash[SAM_HASH_SIZE];
struct SaMhdr { bits384 sig; uint32_t timestamp,nonce; uint8_t numrounds,leverage; };
void SaM_Initialize(struct SaM_info *state);
int32_t SaM_Absorb(struct SaM_info *state,const uint8_t *input,const uint32_t inputSize,const uint8_t *input2,const uint32_t inputSize2);
int32_t SaM_Absorb(struct SaM_info *state,const uint8_t *input,uint32_t inputSize,const uint8_t *input2,uint32_t inputSize2);
bits384 SaM_emit(struct SaM_info *state);
bits384 SaM_encrypt(uint8_t *dest,uint8_t *src,int32_t len,bits384 password,uint32_t timestamp);
uint64_t SaM_threshold(int32_t leverage);

30
crypto777/curve25519.c

@ -16,11 +16,11 @@
#include "../includes/curve25519.h"
#undef force_inline
#define force_inline __attribute__((always_inline))
//#undef force_inline
//#define force_inline __attribute__((always_inline))
// Sum two numbers: output += in
static inline bits320 force_inline fsum(bits320 output,bits320 in)
static inline bits320 fsum(bits320 output,bits320 in)
{
int32_t i;
for (i=0; i<5; i++)
@ -28,7 +28,7 @@ static inline bits320 force_inline fsum(bits320 output,bits320 in)
return(output);
}
static inline void force_inline fdifference_backwards(uint64_t *out,const uint64_t *in)
static inline void fdifference_backwards(uint64_t *out,const uint64_t *in)
{
static const uint64_t two54m152 = (((uint64_t)1) << 54) - 152; // 152 is 19 << 3
static const uint64_t two54m8 = (((uint64_t)1) << 54) - 8;
@ -38,14 +38,14 @@ static inline void force_inline fdifference_backwards(uint64_t *out,const uint64
out[i] = in[i] + two54m8 - out[i];
}
inline void force_inline store_limb(uint8_t *out,uint64_t in)
void store_limb(uint8_t *out,uint64_t in)
{
int32_t i;
for (i=0; i<8; i++,in>>=8)
out[i] = (in & 0xff);
}
static inline uint64_t force_inline load_limb(uint8_t *in)
static inline uint64_t load_limb(uint8_t *in)
{
return
((uint64_t)in[0]) |
@ -75,7 +75,7 @@ bits320 fexpand(bits256 basepoint)
typedef unsigned uint128_t __attribute__((mode(TI)));
// Multiply a number by a scalar: output = in * scalar
static inline bits320 force_inline fscalar_product(const bits320 in,const uint64_t scalar)
static inline bits320 fscalar_product(const bits320 in,const uint64_t scalar)
{
int32_t i; uint128_t a = 0; bits320 output;
a = ((uint128_t)in.ulongs[0]) * scalar;
@ -119,7 +119,7 @@ bits320 fmul(const bits320 in2,const bits320 in)
return(out);
}
inline bits320 force_inline fsquare_times(const bits320 in,uint64_t count)
bits320 fsquare_times(const bits320 in,uint64_t count)
{
uint128_t t[5]; uint64_t r0,r1,r2,r3,r4,c,d0,d1,d2,d4,d419; bits320 out;
r0 = in.ulongs[0], r1 = in.ulongs[1], r2 = in.ulongs[2], r3 = in.ulongs[3], r4 = in.ulongs[4];
@ -149,7 +149,7 @@ inline bits320 force_inline fsquare_times(const bits320 in,uint64_t count)
return(out);
}
static inline void force_inline fcontract_iter(uint128_t t[5],int32_t flag)
static inline void fcontract_iter(uint128_t t[5],int32_t flag)
{
int32_t i; uint64_t mask = 0x7ffffffffffffLL;
for (i=0; i<4; i++)
@ -711,7 +711,7 @@ bits320 bits320_limbs(limb limbs[10])
return(output);
}
static inline bits320 force_inline fscalar_product(const bits320 in,const uint64_t scalar)
static inline bits320 fscalar_product(const bits320 in,const uint64_t scalar)
{
limb output[10],input[10]; int32_t i;
for (i=0; i<10; i++)
@ -720,7 +720,7 @@ static inline bits320 force_inline fscalar_product(const bits320 in,const uint64
return(bits320_limbs(output));
}
static inline bits320 force_inline fsquare_times(const bits320 in,uint64_t count)
static inline bits320 fsquare_times(const bits320 in,uint64_t count)
{
limb output[10],input[10]; int32_t i;
for (i=0; i<10; i++)
@ -776,7 +776,7 @@ bits256 curve25519(bits256 mysecret,bits256 theirpublic)
// x2 z2: long form && x3 z3: long form
// x z: short form, destroyed && xprime zprime: short form, destroyed
// qmqp: short form, preserved
static inline void force_inline
static inline void
fmonty(bits320 *x2, bits320 *z2, // output 2Q
bits320 *x3, bits320 *z3, // output Q + Q'
bits320 *x, bits320 *z, // input Q
@ -804,7 +804,7 @@ fmonty(bits320 *x2, bits320 *z2, // output 2Q
// long. Perform the swap iff @swap is non-zero.
// This function performs the swap without leaking any side-channel information.
// -----------------------------------------------------------------------------
static inline void force_inline swap_conditional(bits320 *a,bits320 *b,uint64_t iswap)
static inline void swap_conditional(bits320 *a,bits320 *b,uint64_t iswap)
{
int32_t i; const uint64_t swap = -iswap;
for (i=0; i<5; ++i)
@ -846,7 +846,7 @@ void cmult(bits320 *resultx,bits320 *resultz,bits256 secret,const bits320 q)
}
// Shamelessly copied from donna's code that copied djb's code, changed a little
inline bits320 force_inline crecip(const bits320 z)
inline bits320 crecip(const bits320 z)
{
bits320 a,t0,b,c;
/* 2 */ a = fsquare_times(z, 1); // a = 2
@ -1888,4 +1888,4 @@ uint8_t *_SuperNET_decipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher
return(0);
}
#undef force_inline
//#undef force_inline

129
crypto777/iguana_OS.c

@ -107,14 +107,14 @@ void *mycalloc(uint8_t type,int32_t n,long itemsize)
while ( (item= calloc(1,sizeof(struct allocitem) + allocsize + 16)) == 0 )
{
char str[65];
printf("mycalloc: need to wait for memory.(%d,%ld) %s to be available\n",n,itemsize,mbstr(str,allocsize));
printf("mycalloc.%c: need to wait for memory.(%d,%ld) %s to be available\n",type,n,itemsize,mbstr(str,allocsize));
sleep(1);
}
//printf("calloc origptr.%p retptr.%p size.%ld\n",item,(void *)(long)item + sizeof(*item),allocsize);
item->allocsize = (uint32_t)allocsize;
item->type = type;
//portable_mutex_unlock(&MEMmutex);
return((void *)(long)item + sizeof(*item));
return((void *)((long)item + sizeof(*item)));
}
void *queueitem(char *str)
@ -429,7 +429,7 @@ void *iguana_memalloc(struct OS_memspace *mem,long size,int32_t clearflag)
#endif
if ( (mem->used + size) <= mem->totalsize )
{
ptr = (void *)(long)((long)(mem->ptr + mem->used));
ptr = (void *)(long)(((long)mem->ptr + mem->used));
mem->used += size;
if ( size*clearflag != 0 )
memset(ptr,0,size);
@ -584,9 +584,9 @@ void OS_ensure_directory(char *dirname)
} else fclose(fp);//, printf("%s exists\n",fname);
}
int64_t OS_filesize(char *fname)
unsigned long OS_filesize(char *fname)
{
FILE *fp; uint64_t fsize = 0;
FILE *fp; unsigned long fsize = 0;
if ( (fp= fopen(fname,"rb")) != 0 )
{
fseek(fp,0,SEEK_END);
@ -641,7 +641,7 @@ int64_t OS_copyfile(char *src,char *dest,int32_t cmpflag)
return(len);
}
int32_t OS_releasemap(void *ptr,uint64_t filesize)
int32_t OS_releasemap(void *ptr,unsigned long filesize)
{
int32_t retval;
if ( ptr == 0 )
@ -728,7 +728,7 @@ long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag)
int32_t OS_openmap(struct OS_mappedptr *mp)
{
uint64_t allocsize = mp->allocsize;
unsigned long allocsize = mp->allocsize;
if ( mp->actually_allocated != 0 )
{
if ( mp->fileptr == 0 )
@ -757,9 +757,9 @@ int32_t OS_openmap(struct OS_mappedptr *mp)
return(0);
}
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,uint64_t allocsize,int32_t rwflag,char *fname)
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,unsigned long allocsize,int32_t rwflag,char *fname)
{
uint64_t filesize;
unsigned long filesize;
mp->actually_allocated = 0;//!os_supports_mappedfiles();
if ( fname != 0 )
{
@ -876,7 +876,7 @@ void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite) // win and pna
return(OS_portable_mapfile(fname,filesizep,enablewrite));
}
int32_t OS_syncmap(struct OS_mappedptr *mp,long len) // pnacl doesnt implement sync
/*int32_t OS_syncmap(struct OS_mappedptr *mp,long len) // pnacl doesnt implement sync
{
return(OS_portable_syncmap(mp,len));
}
@ -884,7 +884,7 @@ int32_t OS_syncmap(struct OS_mappedptr *mp,long len) // pnacl doesnt implement s
void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize) // no syncmap no tmpalloc
{
return(OS_portable_tmpalloc(dirname,name,mem,origsize));
}
}*/
void OS_init()
{
@ -893,7 +893,7 @@ void OS_init()
decode_hex(GENESIS_PUBKEY.bytes,sizeof(GENESIS_PUBKEY),GENESIS_PUBKEYSTR);
decode_hex(GENESIS_PRIVKEY.bytes,sizeof(GENESIS_PRIVKEY),GENESIS_PRIVKEYSTR);
SaM_PrepareIndices();
return(OS_portable_init());
OS_portable_init();
}
int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr)
@ -931,3 +931,108 @@ int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr)
line[strlen(line)-1] = 0;
return((int32_t)strlen(line));
}
//////////// test suite for:
/*
int64_t OS_filesize(char *fname);
void OS_ensure_directory(char *dirname);
long OS_ensurefilesize(char *fname,long filesize,int32_t truncateflag);
int32_t OS_truncate(char *fname,long filesize);
int32_t OS_renamefile(char *fname,char *newfname);
int32_t OS_removefile(char *fname,int32_t scrubflag);
void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_releasemap(void *ptr,uint64_t filesize);
double OS_milliseconds();
void OS_randombytes(uint8_t *x,long xlen);
*/
int32_t iguana_OStests()
{
static uint16_t pairs[0x100][0x100],mappairs[0x100][0x100];
uint8_t buf[4096],*bufptr; int32_t val,min,minij,maxij,max,i,j,histo[0x100],retval = 0,n=0; double startmilli,endmilli; FILE *fp; char *name,*name2,*dirname; long filesize; void *fileptr;
startmilli = OS_milliseconds();
printf("\n>>>>>>>>>> starting tests. Please count the seconds (or use stopwatch)\n");
name = "OStests";
name2 = "OStests2";
dirname = "tmp";
fp = fopen(name,"wb");
memset(histo,0,sizeof(histo));
memset(pairs,0,sizeof(pairs));
memset(mappairs,0,sizeof(mappairs));
for (i=0; i<4096; i++)
{
OS_randombytes(buf,sizeof(buf));
for (j=0; j<sizeof(buf); j++)
{
if ( (n++ % 100000) == 0 )
printf("%02x ",buf[j]);
if ( fp != 0 )
fputc(buf[j],fp);
histo[buf[j]]++;
if ( j > 0 )
pairs[buf[j-1]][buf[j]]++;
}
}
fclose(fp);
printf("\nend of random bytes\n\n");
if ( OS_filesize(name) != n )
printf("FAIL OS_filesize %lld != %d error and if OS_filesize doesnt work, nothing else will work\n",(long long)OS_filesize(name),n), retval--;
else
{
printf("PASS OS_filesize.(%s) matches %d\n",name,n);
OS_renamefile(name,name2);
if ( OS_filesize(name2) != n )
printf("FAIL OS_renamefile returns filesize %lld != %d\n",(long long)OS_filesize(name2),n), retval--;
else printf("PASS OS_renamefile (%s) -> (%s) worked\n",name,name2);
if ( (fileptr= OS_mapfile(name2,&filesize,0)) == 0 )
printf("FAIL OS_mapfile.(%s) returns null\n",name2), retval--;
else if ( filesize != n )
printf("FAIL OS_mapfile.(%s) returns %ld != %d\n",name2,filesize,n), retval--;
else
{
bufptr = fileptr;
for (i=0; i<4096; i++)
{
memcpy(buf,bufptr,sizeof(buf));
bufptr += sizeof(buf);
for (j=1; j<sizeof(buf); j++)
mappairs[buf[j-1]][buf[j]]++;
}
if ( memcmp(pairs,mappairs,sizeof(pairs)) != 0 )
printf("FAIL OS_mapfile.(%s) %ld data error pairs[][] != mappairs[][]\n",name2,filesize), retval--;
else printf("PASS OS_mapfile.(%s) %ld regenerated identical pairs[][]\n",name2,filesize);
if ( OS_releasemap(fileptr,filesize) != 0 )
printf("FAIL OS_releasemap.(%s) %ld returns error\n",name2,filesize), retval--;
else printf("PASS OS_releasemap.(%s) %ld returns success\n",name2,filesize);
}
OS_removefile(name2,0);
if ( OS_filesize(name2) == n )
printf("FAIL OS_removefile.(%s) didnt work\n",name2), retval--;
else if ( (fp= fopen(name2,"rb")) != 0 )
printf("FAIL OS_removefile.(%s) didnt work fopen fp.%p\n",name2,fp), fclose(fp), retval--;
else printf("PASS OS_removefile.(%s) worked\n",name2);
}
minij = min = (1 << 30);
maxij = max = -1;
for (i=0; i<0x100; i++)
{
if ( (val= histo[i]) > max )
max = val;
else if ( val < min )
min = val;
for (j=0; j<0x100; j++)
{
if ( (val= pairs[i][j]) > maxij )
maxij = val;
else if ( val < minij )
minij = val;
}
}
endmilli = OS_milliseconds();
printf("\n\nDid that take %.3f seconds? If not, there is a problem with OS_milliseconds\n\nMake sure above numbers look random and the min/max are within specified range:\n<3%% %.2f%% min %d max %d | <75%% %.3f%% minij %d maxij %d\n",(endmilli - startmilli)/1000.,100*(double)max/min - 100.,min,max,100*(double)maxij/minij - 100.,minij,maxij);
return(retval);
}

6
crypto777/iguana_utils.c

@ -1079,7 +1079,7 @@ void calc_md2str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
bits128 x;
calc_md2(hexstr,buf,msg,len);
decode_hex(buf,sizeof(x),hexstr);
memcpy(buf,x.bytes,sizeof(x));
//memcpy(buf,x.bytes,sizeof(x));
}
void calc_md4str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
@ -1087,7 +1087,7 @@ void calc_md4str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
bits128 x;
calc_md4(hexstr,buf,msg,len);
decode_hex(buf,sizeof(x),hexstr);
memcpy(buf,x.bytes,sizeof(x));
//memcpy(buf,x.bytes,sizeof(x));
}
void calc_md5str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
@ -1095,7 +1095,7 @@ void calc_md5str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
bits128 x;
calc_md5(hexstr,msg,len);
decode_hex(buf,sizeof(x),hexstr);
memcpy(buf,x.bytes,sizeof(x));
//memcpy(buf,x.bytes,sizeof(x));
}
void calc_crc32str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)

2
crypto777/inet.c

@ -24,7 +24,9 @@
#ifdef _WIN32
#define in6_addr sockaddr
#define in_addr_t struct sockaddr_storage
#ifndef NATIVE_WINDOWS
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#endif
struct sockaddr_in6 {
short sin6_family;

5
crypto777/jpeg/jconfig.h

@ -20,6 +20,7 @@
/* Define "boolean" as unsigned char, not int, on Windows systems. */
#ifdef _WIN32
#define USE_MSDOS_MEMMGR
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
@ -29,7 +30,11 @@ typedef unsigned char boolean;
#ifdef JPEG_INTERNALS
/* #undef RIGHT_SHIFT_IS_UNSIGNED */
#ifdef WIN32
#define INLINE
#else
#define INLINE __inline__
#endif
/* These are for configuring the JPEG memory manager. */
/* #undef DEFAULT_MAX_MEM */
/* #undef NO_MKTEMP */

1
crypto777/jpeg/jmemsys.h

@ -154,6 +154,7 @@ typedef struct backing_store_struct {
/* For the MS-DOS manager (jmemdos.c), we need: */
handle_union handle; /* reference to backing-store storage object */
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
FILE *temp_file;
#else
#ifdef USE_MAC_MEMMGR
/* For the Mac manager (jmemmac.c), we need: */

2
crypto777/jpeg/unix/jmemname.c

@ -11,7 +11,7 @@
* Also, the problem of determining the amount of memory available
* is shoved onto the user.
*/
#include <unistd.h>
//#include <unistd.h>
#define JPEG_INTERNALS
#include "../jinclude.h"

7
crypto777/scrypt.c

@ -344,7 +344,12 @@ static inline void scrypt_core(uint32_t *X, uint32_t *V, int N)
void scrypt_1024_1_1_256(const uint32_t *input,uint32_t *output,uint32_t *midstate,uint8_t *scratchpad, int N)
{
uint32_t *V,tstate[8],ostate[8],X[32] __attribute__((aligned(128)));
uint32_t *V,tstate[8],ostate[8],X[32]
#ifndef WIN32
__attribute__((aligned(128)))
#endif
;
V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
memcpy(tstate, midstate, 32);
HMAC_SHA256_80_init(input, tstate, ostate);

24
datachain/datachain_KOMODO.c

@ -78,12 +78,12 @@ bits256 datachain_opreturn_convert(uint8_t *txidbytes,int32_t *txlenp,struct igu
int32_t datachain_genesis_verify(struct gecko_genesis_opreturn *opret)
{
int32_t txlen,datalen; bits256 txid,threshold,hash2; uint8_t serialized[1024],txidbytes[1024]; struct iguana_msgblock msg; char str[65],str2[65];
txid = datachain_opreturn_convert(txidbytes,&txlen,&msg,opret);
int32_t txlen,datalen; bits256 txid,threshold,hash2; uint8_t serialized[1024],txidbytes[1024]; struct iguana_msgzblock zmsg; char str[65],str2[65];
txid = datachain_opreturn_convert(txidbytes,&txlen,(void *)&zmsg,opret);
if ( opret->nBits >= GECKO_EASIESTDIFF )
threshold = bits256_from_compact(GECKO_EASIESTDIFF);
else threshold = bits256_from_compact(opret->nBits);
datalen = iguana_rwblockhdr(1,0,serialized,&msg);
datalen = iguana_rwblockhdr(1,0,serialized,&zmsg);
hash2 = iguana_calcblockhash("virtual",blockhash_sha256,serialized,datalen);
//for (i=0; i<datalen; i++)
// printf("%02x",serialized[i]);
@ -101,7 +101,7 @@ int32_t datachain_genesis_verify(struct gecko_genesis_opreturn *opret)
int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,char *coinaddr,int64_t PoSvalue,uint32_t nBits,uint16_t blocktime,uint16_t port,uint8_t p2shval,uint8_t wifval)
{
int32_t i,len,datalen,txlen; struct gecko_genesis_opreturn opret; bits256 threshold,txid,hash2; struct iguana_info *btcd; struct iguana_msgblock msg; uint8_t txidbytes[1024];
int32_t i,len,datalen,txlen; struct gecko_genesis_opreturn opret; bits256 threshold,txid,hash2; struct iguana_info *btcd; struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; uint8_t txidbytes[1024];
btcd = iguana_coinfind("BTCD");
memset(&opret,0,sizeof(opret));
opret.type[0] = 'N', opret.type[1] = 'E', opret.type[2] = 'W';
@ -117,14 +117,14 @@ int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,ch
opret.timestamp = (uint32_t)time(NULL);
OS_randombytes((void *)&opret.netmagic,sizeof(opret.netmagic));
bitcoin_addr2rmd160(&opret.pubval,opret.rmd160,coinaddr);
txid = datachain_opreturn_convert(txidbytes,&txlen,&msg,&opret);
txid = datachain_opreturn_convert(txidbytes,&txlen,msg,&opret);
if ( nBits >= GECKO_EASIESTDIFF )
threshold = bits256_from_compact(GECKO_EASIESTDIFF);
else threshold = bits256_from_compact(nBits);
for (i=0; i<100000000; i++)
{
opret.nonce = msg.H.nonce = i;
datalen = iguana_rwblockhdr(1,0,serialized,&msg);
opret.nonce = msg->H.nonce = i;
datalen = iguana_rwblockhdr(1,0,serialized,&zmsg);
hash2 = iguana_calcblockhash(symbol,btcd->chain->hashalgo,serialized,datalen);
if ( bits256_cmp(threshold,hash2) > 0 )
break;
@ -140,7 +140,7 @@ int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,ch
void datachain_events_processKOMODO(struct supernet_info *myinfo,struct datachain_info *dPoW,struct datachain_event *event)
{
struct gecko_chain *chain; bits256 hash2,threshold; struct gecko_genesis_opreturn opret; int32_t datalen,i,j,len,txlen; char symbol[16],name[64],magicstr[16],blockstr[8192],nbitstr[16],issuer[64],hashstr[65],str2[65],argbuf[1024],chainname[GECKO_MAXNAMELEN]; cJSON *valsobj; struct iguana_msgblock msg; uint8_t serialized[256],txidbytes[1024],buf[4]; struct iguana_info *virt,*btcd;
struct gecko_chain *chain; bits256 hash2,threshold; struct gecko_genesis_opreturn opret; int32_t datalen,i,j,len,txlen; char symbol[16],name[64],magicstr[16],blockstr[8192],nbitstr[16],issuer[64],hashstr[65],str2[65],argbuf[1024],chainname[GECKO_MAXNAMELEN]; cJSON *valsobj; struct iguana_msgzblock zmsg; uint8_t serialized[256],txidbytes[1024],buf[4]; struct iguana_info *virt,*btcd;
if ( (btcd= iguana_coinfind("BTCD")) != 0 && memcmp(event->opreturn,"NEW",3) == 0 )
{
//int32_t i; for (i=0; i<76; i++)
@ -151,13 +151,13 @@ void datachain_events_processKOMODO(struct supernet_info *myinfo,struct datachai
datachain_genesis_verify(&opret);
memset(symbol,0,sizeof(symbol)), memcpy(symbol,opret.symbol,sizeof(opret.symbol));
memset(name,0,sizeof(name)), memcpy(name,opret.name,sizeof(opret.name));
hash2 = datachain_opreturn_convert(txidbytes,&txlen,&msg,&opret);
hash2 = datachain_opreturn_convert(txidbytes,&txlen,(void *)&zmsg,&opret);
if ( opret.nBits >= GECKO_EASIESTDIFF )
threshold = bits256_from_compact(GECKO_EASIESTDIFF);
else threshold = bits256_from_compact(opret.nBits);
msg.txn_count = 1;
zmsg.txn_count = 1;
//n = iguana_serialize_block(virt->chain,&hash2,serialized,newblock);
datalen = iguana_rwblockhdr(1,0,serialized,&msg);
datalen = iguana_rwblockhdr(1,0,serialized,&zmsg);
hash2 = iguana_calcblockhash(symbol,btcd->chain->hashalgo,serialized,datalen);
for (i=0; i<datalen; i++)
printf("%02x",serialized[i]);
@ -179,7 +179,7 @@ void datachain_events_processKOMODO(struct supernet_info *myinfo,struct datachai
init_hexbytes_noT(blockstr,serialized,datalen);
strcat(blockstr,"01"), datalen++;
init_hexbytes_noT(&blockstr[datalen << 1],txidbytes,txlen);
sprintf(argbuf,"{\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%02x\",\"p2shval\":\"%02x\",\"wifval\":\"%02x\",\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nBits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",name,symbol,magicstr,opret.port,opret.blocktime,opret.pubval,opret.p2shval,opret.wifval,(opret.nBits >> 24) & 0xff,hashstr,opret.timestamp,nbitstr,opret.nonce,bits256_str(str2,msg.H.merkle_root),blockstr);
sprintf(argbuf,"{\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%02x\",\"p2shval\":\"%02x\",\"wifval\":\"%02x\",\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nBits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",name,symbol,magicstr,opret.port,opret.blocktime,opret.pubval,opret.p2shval,opret.wifval,(opret.nBits >> 24) & 0xff,hashstr,opret.timestamp,nbitstr,opret.nonce,bits256_str(str2,zmsg.zH.merkle_root),blockstr);
if ( (valsobj= cJSON_Parse(argbuf)) != 0 )
{
printf("datachain.NEW (%s/%s port.%u blocktime.%d) issuer.%s (%s)\n",opret.symbol,opret.name,opret.port,opret.blocktime,issuer,jprint(valsobj,0));

2
deprecated/iguana_instantdex.c

@ -225,7 +225,7 @@ struct instantdex_event *instantdex_addevent(struct instantdex_stateinfo *states
for (i=0; i<numstates; i++)
printf("%s[%d] ",states[i].name,i);
printf("cant add event (%s -> %s) without existing state and nextstate\n",statename,nextstatename);
exit(-1);
iguana_exit(0);
return(0);
}
}

498
deprecated/obsolete.h

@ -18656,3 +18656,501 @@ len = 0;
}
#endif
#endif
//#define ENABLE_RAMCHAIN
#ifdef oldway
void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp)
{
//return;
#ifdef ENABLE_RAMCHAIN
int32_t hdrsi;
//portable_mutex_lock(&coin->RTmutex);
if ( coin->utxotable != 0 )
{
printf("free RTramchain\n");
//iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables
coin->lastRTheight = coin->RTheight = 0;//(coin->bundlescount-1) * coin->chain->bundlesize;
coin->RTgenesis = 0;
iguana_utxoaddrs_purge(coin);
iguana_ramchain_free(coin,&coin->RTramchain,1);
if ( bp != 0 )
bp->ramchain = coin->RTramchain;
iguana_mempurge(&coin->RTmem);
iguana_mempurge(&coin->RThashmem);
for (hdrsi=coin->bundlescount-1; hdrsi>0; hdrsi--)
if ( (bp= coin->bundles[hdrsi]) == 0 && bp != coin->current )
{
iguana_volatilespurge(coin,&bp->ramchain);
if ( iguana_volatilesmap(coin,&bp->ramchain) != 0 )
printf("error mapping bundle.[%d]\n",hdrsi);
}
coin->RTdatabad = 0;
printf("done RTramchain\n");
}
//portable_mutex_unlock(&coin->RTmutex);
#endif
}
void *iguana_ramchainfile(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block)
{
//return(0);
#ifdef ENABLE_RAMCHAIN
char fname[1024]; long filesize; int32_t err; void *ptr=0;
if ( block == bp->blocks[bundlei] && (ptr= iguana_bundlefile(coin,fname,&filesize,bp,bundlei)) != 0 )
{
if ( iguana_mapchaininit(fname,coin,R,bp,bundlei,block,ptr,filesize) >= 0 )
{
if ( dest != 0 && dest->H.data != 0 )
err = iguana_ramchain_iterate(myinfo,coin,dest,R,bp,bundlei);
else err = 0;
if ( err != 0 || dest->H.data == 0 || bits256_cmp(R->H.data->firsthash2,block->RO.hash2) != 0 )
{
char str[65];
printf("ERROR [%d:%d] %s vs ",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2));
printf("mapped.%s\n",bits256_str(str,R->H.data->firsthash2));
} else return(ptr);
}
iguana_blockunmark(coin,block,bp,bundlei,1);
iguana_ramchain_free(coin,R,1);
} //else printf("ramchainfile ptr.%p block.%p\n",ptr,block);
#endif
return(0);
}
void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp)
{
//return;
#ifdef ENABLE_RAMCHAIN
uint32_t i,changed = 0; struct iguana_ramchaindata *rdata; struct iguana_ramchain *dest = &coin->RTramchain; struct iguana_blockRO *B; struct iguana_bundle *tmpbp;
//portable_mutex_lock(&coin->RTmutex);
if ( (rdata= dest->H.data) != 0 )
{
i = 0;
if ( coin->RTheight != coin->lastRTheight )
changed++;
else
{
B = RAMCHAIN_PTR(rdata,Boffset);
for (i=0; i<rdata->numblocks; i++)
if ( bits256_cmp(B[i].hash2,bp->hashes[i]) != 0 )
{
char str[65],str2[65]; printf("mismatched hash2 at %d %s vs %s\n",bp->bundleheight+i,bits256_str(str,B[i].hash2),bits256_str(str2,bp->hashes[i]));
changed++;
iguana_blockunmark(coin,bp->blocks[i],bp,i,1);
break;
}
}
if ( changed != 0 )
{
printf("RTramchain changed %d bundlei.%d | coin->RTheight %d != %d bp->bundleheight + %d coin->RTramchain.H.data->numblocks\n",coin->RTheight,i,coin->RTheight,bp->bundleheight,rdata->numblocks);
iguana_RTramchainfree(coin,bp);
}
}
if ( coin->RTramchain.H.data == 0 )
{
iguana_ramchainopen(fname,coin,dest,&coin->RTmem,&coin->RThashmem,bp->bundleheight,bp->hashes[0]);
printf("ALLOC RTramchain.(%s) RTrdata %p rdata.%p\n",fname,coin->RTramchain.H.data,bp->ramchain.H.data);
dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti;
dest->externalind = dest->H.stacksize = 0;
dest->H.scriptoffset = 1;
if ( 1 )
{
for (i=0; i<bp->hdrsi; i++)
if ( (tmpbp= coin->bundles[i]) != 0 )
{
iguana_volatilespurge(coin,&tmpbp->ramchain);
iguana_volatilesmap(coin,&tmpbp->ramchain);
}
sleep(1);
}
}
//portable_mutex_unlock(&coin->RTmutex);
#endif
}
void iguana_rdataset(struct iguana_ramchain *dest,struct iguana_ramchaindata *rdest,struct iguana_ramchain *src)
{
//return;
#ifdef ENABLE_RAMCHAIN
*dest = *src;
dest->H.data = rdest;
*rdest = *src->H.data;
rdest->numpkinds = src->pkind;
rdest->numexternaltxids = src->externalind;
rdest->numtxids = src->H.txidind;
rdest->numunspents = src->H.unspentind;
rdest->numspends = src->H.spendind;
//printf("RT set numtxids.%u numspends.%u\n",rdest->numtxids,rdest->numspends);
#endif
}
void iguana_rdatarestore(struct iguana_ramchain *dest,struct iguana_ramchaindata *rdest,struct iguana_ramchain *src)
{
//return;
#ifdef ENABLE_RAMCHAIN
*src = *dest;
*src->H.data = *rdest;
src->pkind = rdest->numpkinds;
src->externalind = rdest->numexternaltxids;
src->H.txidind = rdest->numtxids;
src->H.unspentind = rdest->numunspents;
src->H.spendind = rdest->numspends;
printf("RT restore numtxids.%u numspends.%u\n",rdest->numtxids,rdest->numspends);
#endif
}
void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t numaddrs)
{
//return;
#ifdef ENABLE_RAMCHAIN
int32_t datalen,i; uint8_t serialized[512]; char str[65]; struct iguana_peer *addr;
if ( coin->peers == 0 )
return;
datalen = iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0]));
for (i=0; i<numaddrs && i<coin->peers->numranked; i++)
{
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
if ( coin->chain->hasheaders == 0 )
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,coin->blocks.hwmchain.RO.hash2)),1);
if ( (addr= coin->peers->ranked[i]) != 0 && addr->usock >= 0 && addr->dead == 0 && datalen > 0 )
{
iguana_send(coin,addr,serialized,datalen);
//addr->pendhdrs++;
}
}
#endif
}
void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp)
{
//return;
#ifdef ENABLE_RAMCHAIN
int32_t iterate,lasti,num,hdrsi,orignumemit; struct iguana_ramchain R; struct iguana_ramchaindata RDATA;
if ( bp->hdrsi <= 0 )
return;
printf("RTspendvectors [%d]\n",bp->hdrsi);
bp->ramchain = coin->RTramchain;
iguana_rdataset(&R,&RDATA,&coin->RTramchain);
if ( (lasti= (coin->RTheight - ((coin->RTheight/bp->n)*bp->n))) >= bp->n-1 )
lasti = bp->n - 1;
orignumemit = bp->numtmpspends;
iterate = 0;
if ( iguana_spendvectors(myinfo,coin,bp,&coin->RTramchain,coin->RTstarti%coin->chain->bundlesize,lasti,0,iterate) < 0 )
{
printf("RTutxo error -> RTramchainfree\n");
coin->RTdatabad = 1;
return;
}
else
{
//printf("RTspendvectors calculated to %d [%d]\n",coin->RTheight,bp->hdrsi);
bp->converted = 1;
for (hdrsi=num=0; hdrsi<bp->hdrsi; hdrsi++)
{
#ifdef __APPLE__
if ( coin->bundles[hdrsi]->lastprefetch == 0 )
{
iguana_ramchain_prefetch(coin,&coin->bundles[hdrsi]->ramchain,2);
coin->bundles[hdrsi]->lastprefetch = (uint32_t)time(NULL);
}
#endif
num += iguana_convert(coin,IGUANA_NUMHELPERS,coin->bundles[hdrsi],1,orignumemit);
}
//printf("RTspendvectors converted.%d to %d\n",num,coin->RTheight);
//iguana_rdatarestore(&R,&RDATA,&bp->ramchain);
bp->converted = (uint32_t)time(NULL);
if ( iguana_balancegen(coin,1,bp,coin->RTstarti,coin->RTheight > 0 ? coin->RTheight-1 : bp->bundleheight+bp->n-1,orignumemit) < 0 )
{
printf("balancegen error\n");
coin->RTdatabad = 1;
}
else if ( coin->RTgenesis == 0 && coin->firstRTgenesis == 0 )
coin->firstRTgenesis++, printf(">>>>>> IGUANA %s READY FOR REALTIME RPC <<<<<<\n",coin->symbol);
//printf("iguana_balancegen [%d] (%d to %d)\n",bp->hdrsi,coin->RTstarti,(coin->RTheight-1)%bp->n);
coin->RTstarti = coin->RTheight;
}
#endif
}
int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info *coin)
{
int32_t flag = 0;
//return(0);
#ifdef ENABLE_RAMCHAIN
double startmillis0; static double totalmillis0; static int32_t num0;
struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t offset,bundlei,i,n; bits256 hash2,*ptr; struct iguana_peer *addr;
struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR;
if ( coin->peers == 0 && coin->virtualchain == 0 )
return(0);
offset = 0;//(strcmp("BTC",coin->symbol) != 0);
if ( coin->RTheight >= (coin->current->hdrsi+1)*coin->chain->bundlesize )
{
printf("inversion RT %d >= %d\n",coin->RTheight,(coin->current->hdrsi+1)*coin->chain->bundlesize);
coin->lastRTheight = coin->RTheight = coin->current->hdrsi*coin->chain->bundlesize;
iguana_utxoaddrs_purge(coin);
}
if ( coin->current != 0 && (coin->blocks.hwmchain.height % coin->chain->bundlesize) == coin->chain->bundlesize-1 && coin->blocks.hwmchain.height/coin->chain->bundlesize == coin->longestchain/coin->chain->bundlesize )
{
block = coin->current->blocks[coin->current->n - 1];
if ( _iguana_chainlink(coin,block) <= 0 )
{
printf("RT edge case couldnt link\n");
}
else
{
printf("RT edge case.%d\n",block->height);
if ( (bp= coin->bundles[coin->RTheight / coin->chain->bundlesize]) != 0 )
iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,0,0);
iguana_update_balances(coin);
}
}
if ( coin->spendvectorsaved <= 1 )
{
//printf("%s spendvectorsaved not yet\n",coin->symbol);
usleep(100000);
return(0);
}
//portable_mutex_lock(&coin->RTmutex);
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) != 0 && (i > 0 && bp->utxofinish == 0) && bp != coin->current )
{
if ( iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,0,0) < 0 )
{
//portable_mutex_unlock(&coin->RTmutex);
printf("error generating spendvectors.[%d], skipping\n",i);
return(0);
} // else printf("generated UTXO.[%d]\n",i);
coin->spendvectorsaved = 1;
}
}
//portable_mutex_unlock(&coin->RTmutex);
bp = coin->current;
if ( bp == 0 )//|| iguana_validated(coin) < bp->hdrsi )
{
//printf("bp.%p validated.%d vs hdrsi.%d\n",bp,iguana_validated(coin),bp->hdrsi);
return(0);
}
if ( 0 && coin->RTheight > 0 && coin->spendvectorsaved != 1 && coin->bundlescount-1 != coin->balanceswritten )
{
printf("RT mismatch %d != %d\n",coin->bundlescount-1,coin->balanceswritten);
iguana_RTramchainfree(coin,coin->current);
coin->spendvectorsaved = 0;
coin->lastRTheight = coin->RTheight = 0;
iguana_utxoaddrs_purge(coin);
/*while ( coin->spendvectorsaved <= 1 )
{
fprintf(stderr,"wait for spendvectorsaved\n");
sleep(3);
}*/
return(0);
}
if ( coin->RTdatabad == 0 && bp->hdrsi >= (coin->longestchain/coin->chain->bundlesize)-1 && bp->hdrsi >= coin->balanceswritten-2 && ((coin->RTheight < coin->blocks.hwmchain.height-offset && time(NULL) > bp->lastRT) || time(NULL) > bp->lastRT+1) ) //coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n &&
{
if ( coin->RTheight < bp->hdrsi*coin->chain->bundlesize )
{
coin->lastRTheight = coin->RTheight = bp->hdrsi*coin->chain->bundlesize;
iguana_utxoaddrs_purge(coin);
}
if ( (block= bp->blocks[0]) == 0 || block->txvalid == 0 || block->mainchain == 0 )
{
if ( block != 0 )
{
if ( _iguana_chainlink(coin,block) <= 0 )
{
iguana_blockunmark(coin,block,bp,0,0);
bp->issued[0] = 0;
hash2 = bp->hashes[0];
//char str[65]; printf("RT[0] [%d:%d] %s %p\n",bp->hdrsi,0,bits256_str(str,hash2),block);
if ( coin->peers != 0 )
{
addr = coin->peers->ranked[rand() % 8];
if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 )
iguana_sendblockreqPT(coin,addr,bp,0,hash2,0);
}
}
}
}
//char str[65]; printf("check longest.%d RTheight.%d hwm.%d %s %p\n",coin->longestchain,coin->RTheight,coin->blocks.hwmchain.height,bits256_str(str,bp->hashes[0]),block);
if ( bits256_cmp(coin->RThash1,bp->hashes[1]) != 0 )
coin->RThash1 = bp->hashes[1];
//bp->lastRT = (uint32_t)time(NULL);
if ( coin->peers != 0 && coin->RTheight <= coin->longestchain-offset && coin->peers->numranked > 0 && time(NULL) > coin->RThdrstime+16 )
{
iguana_RThdrs(coin,bp,coin->peers->numranked);
coin->RThdrstime = (uint32_t)time(NULL);
}
bp->lastRT = (uint32_t)time(NULL);
iguana_RTramchainalloc("RTbundle",coin,bp);
bp->isRT = 1;
//printf("%s rdata.%p RTheight.%d hwm.%d RTdatabad.%d\n",coin->symbol,coin->RTramchain.H.data,coin->RTheight,coin->blocks.hwmchain.height,coin->RTdatabad);
while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height-offset && coin->RTdatabad == 0 )
{
dest = &coin->RTramchain;
B = RAMCHAIN_PTR(rdata,Boffset);
bundlei = (coin->RTheight % coin->chain->bundlesize);
if ( (block= iguana_bundleblock(coin,&hash2,bp,bundlei)) != 0 )
{
iguana_bundlehashadd(coin,bp,bundlei,block);
//printf("RT.%d vs hwm.%d starti.%d bp->n %d block.%p/%p ramchain.%p databad.%d prevnonz.%d\n",coin->RTheight,coin->blocks.hwmchain.height,coin->RTstarti,bp->n,block,bp->blocks[bundlei],dest->H.data,coin->RTdatabad,bits256_nonz(block->RO.prev_block));
}
else
{
//printf("cant find bundleblock [%d:%d]\n",bp->hdrsi,bundlei);
iguana_blockQ("RTmissing",coin,bp,bundlei,hash2,1);
break;
}
if ( coin->RTdatabad == 0 && block != 0 && (block->height == 0 || bits256_nonz(block->RO.prev_block) != 0) )
{
//printf("bundlei.%d blockht.%d RTheight.%d\n",bundlei,block->height,coin->RTheight);
iguana_blocksetcounters(coin,block,dest);
startmillis0 = OS_milliseconds();
if ( iguana_ramchainfile(myinfo,coin,dest,&blockR,bp,bundlei,block) == 0 )
{
for (i=0; i<bp->n; i++)
if ( GETBIT(bp->haveblock,i) == 0 )
bp->issued[i] = 0;
if ( (n= iguana_bundleissuemissing(coin,bp,3,1.)) > 0 )
printf("RT %s issued %d priority requests [%d] to unstick stuckiters.%d\n",coin->symbol,n,bp->hdrsi,coin->stuckiters);
for (i=bundlei; i<bp->n; i++)
{
block = iguana_bundleblock(coin,&hash2,bp,i);
if ( bits256_nonz(hash2) != 0 && (block == 0 || block->txvalid == 0) )
{
uint8_t serialized[512]; int32_t len; struct iguana_peer *addr;
//char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block);
if ( coin->peers != 0 )
{
addr = coin->peers->ranked[rand() % 8];
if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 )
iguana_send(coin,addr,serialized,len);
}
coin->RTgenesis = 0;
}
if ( bits256_nonz(hash2) != 0 )
iguana_blockQ("RTerr",coin,bp,i,hash2,1);
//break;
}
return(-1);
} else iguana_ramchain_free(coin,&blockR,1);
B[bundlei] = block->RO;
totalmillis0 += (OS_milliseconds() - startmillis0);
num0++;
flag++;
//coin->blocks.RO[bp->bundleheight+bundlei] = block->RO;
coin->RTheight++;
coin->lastRTheight = coin->RTheight;
//printf(">>>> RT.%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize);
if ( coin->RTramchain.H.data != 0 )
coin->RTramchain.H.data->numblocks = bundlei + 1;
else break;
} else break;
}
}
else
{
if ( coin->virtualchain == 0 )
{
//printf("%s skip RT.(%d %d %d %d %d %d %d %u)\n",coin->symbol,coin->RTdatabad,bp->hdrsi,coin->longestchain/coin->chain->bundlesize,coin->balanceswritten,coin->RTheight,bp->bundleheight,coin->blocks.hwmchain.height,bp->lastRT);
//sleep(1);
}
}
n = 0;
if ( coin->RTdatabad == 0 && dest != 0 && flag != 0 && coin->RTheight >= coin->blocks.hwmchain.height-offset )
{
printf("ramchainiterate.[%d] ave %.2f micros, total %.2f seconds starti.%d num.%d\n",num0,(totalmillis0*1000.)/num0,totalmillis0/1000.,coin->RTstarti,coin->RTheight%bp->n);
if ( (n= iguana_walkchain(coin,1)) == coin->RTheight-1+offset )
{
//printf("RTgenesis verified\n");
if ( (coin->RTheight % coin->chain->bundlesize) > 3 )
{
//portable_mutex_lock(&coin->RTmutex);
iguana_RTspendvectors(myinfo,coin,bp);
//portable_mutex_unlock(&coin->RTmutex);
coin->RTgenesis = (uint32_t)time(NULL);
}
}
else
{
printf("walkchain error n.%d != %d\n",n,coin->RTheight-1+offset);
coin->RTdatabad = 1;
}
}
if ( dest != 0 && flag != 0 )
printf("<<<< flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld balance %.8f + %.8f - %.8f = supply %.8f\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,dest->H.data!=0?(long)dest->H.data->allocsize:-1,dstr(coin->histbalance),dstr(coin->RTcredits),dstr(coin->RTdebits),dstr(coin->histbalance + coin->RTcredits - coin->RTdebits));
if ( coin->RTdatabad != 0 )
{
bits256 lastbundle;
//portable_mutex_lock(&coin->RTmutex);
printf("START DATABAD fixing\n");
iguana_RTramchainfree(coin,bp);
if ( coin->RTdatabad < 0 )
{
memset(lastbundle.bytes,0,sizeof(lastbundle));
iguana_initfinal(myinfo,coin,lastbundle);
}
coin->RTdatabad = 0;
//memset(bp->hashes,0,sizeof(bp->hashes));
memset(bp->blocks,0,sizeof(bp->blocks));
if ( 0 && bp->speculative != 0 )
{
ptr = bp->speculative;
bp->speculative = 0;
memset(ptr,0,sizeof(*bp->speculative)*bp->n);
myfree(ptr,(bp->n+1)*sizeof(*bp->speculative));
}
iguana_RTramchainalloc("RTbundle",coin,bp);
printf("DONE DATABAD fixing\n");
//portable_mutex_unlock(&coin->RTmutex);
}
#endif
return(flag);
}
#endif
/*if ( (checklen= iguana_vinscriptdecode(coin,ramchain,&metalen,_script,&Kspace[rdata->scriptspace],Kspace,s)) != vinscriptlen || (vinscript != 0 && memcmp(_script,vinscript,vinscriptlen) != 0) )
{
static uint64_t counter;
if ( counter++ < 100 )
{
for (i=0; i<checklen; i++)
printf("%02x",_script[i]);
printf(" decoded\n");
for (i=0; i<vinscriptlen; i++)
printf("%02x",vinscript[i]);
printf(" vinscript\n");
printf("A addspend: vinscript expand error (%d vs %d) %d\n",checklen,vinscriptlen,vinscript!=0?memcmp(_script,vinscript,vinscriptlen):0);
}
}*/
//ramchain->H.scriptoffset += metalen;
/*static uint64_t good,bad;
if ( 0 && iguana_metascript(coin,RAMCHAIN_ARG,s,vinscript,vinscriptlen,0) < 0 )
{
static long errlen,err2len; char errbuf[1024];
errlen += vinscriptlen;
if ( iguana_metascript(coin,RAMCHAIN_ARG,s,vinscript,vinscriptlen,1) < 0 )
{
err2len += vinscriptlen;
errbuf[0] = 0;
for (i=0; i<vinscriptlen; i++)
sprintf(errbuf+strlen(errbuf),"%02x",vinscript[i]);
printf("%s <- second error with ",errbuf);
printf(" vinscript.%d errlens %ld %ld\n",vinscriptlen,errlen,err2len);
}
else if ( 0 && vinscriptlen > 138 )
{
errbuf[0] = 0;
for (i=0; i<vinscriptlen; i++)
sprintf(errbuf+strlen(errbuf),"%02x",vinscript[i]);
printf("%s bigscript ",errbuf);
}
bad += vinscriptlen;
} else good += vinscriptlen;
if ( 0 && (rand() % 100000) == 0 )
printf("good.%llu bad.%llu vinstats\n",(long long)good,(long long)bad);*/
//s->hdrsi = hdrsi;
//s->bundlei = bundlei;
//char str[65]; printf("%s set prevout.%d -> %d\n",bits256_str(str,prev_hash),prev_vout,s->prevout);
//if ( pkind != 0 )
// s->prevspendind = A[pkind].lastspendind;

6
gecko/gecko.c

@ -179,9 +179,9 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo
virt->chain = calloc(1,sizeof(*virt->chain));
virt->enableCACHE = 1;
serialized = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr);
iguana_chaininit(virt->chain,1,valsobj);
iguana_chaininit(myinfo,virt->chain,1,valsobj);
virt->chain->isPoS = 1;
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr);
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgzblockhdr) : sizeof(struct iguana_msgblockhdr);
if ( gecko_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits,0,0) > 0 )
{
virt->chain->genesishash2 = iguana_calcblockhash(symbol,virt->chain->hashalgo,serialized,hdrsize);
@ -212,7 +212,7 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo
if ( virt->blocks.hwmchain.height == 0 )
{
memset(&txdata,0,sizeof(txdata));
if ( (n= iguana_gentxarray(virt,&virt->TXMEM,&txdata,&len,serialized,datalen) == datalen) || n == datalen-1 )
if ( (n= iguana_gentxarray(myinfo,virt,&virt->TXMEM,&txdata,&len,serialized,datalen) == datalen) || n == datalen-1 )
{
txdata.zblock.height = 0;
txdata.zblock.RO.allocsize = iguana_ROallocsize(virt);

16
gecko/gecko_blocks.c

@ -121,7 +121,7 @@ struct iguana_bundle *gecko_ensurebundle(struct iguana_info *virt,struct iguana_
int32_t gecko_hwmset(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,uint8_t *data,int32_t datalen,int32_t depth,int32_t verifyonly)
{
struct iguana_peer *addr; int32_t i,hdrsi; struct iguana_bundle *bp,*prevbp; struct iguana_block *block;
struct iguana_peer *addr; int32_t i,hdrsi; struct iguana_bundle *bp=0,*prevbp; struct iguana_block *block;
if ( (block= iguana_blockhashset("gecko_hwmset",virt,txdata->zblock.height,txdata->zblock.RO.hash2,1)) != 0 )
{
iguana_blockcopy(virt->chain->zcash,virt->chain->auxpow,virt,block,(struct iguana_block *)&txdata->zblock);
@ -132,7 +132,7 @@ int32_t gecko_hwmset(struct supernet_info *myinfo,struct iguana_info *virt,struc
printf("no bundle for %s.%d\n",virt->symbol,block->height);
return(-1);
}
if ( iguana_ramchain_data(virt,addr,txdata,txarray,block->RO.txn_count,data,datalen) >= 0 )
if ( iguana_ramchain_data(virt,addr,txdata,txarray,block->RO.txn_count,data,datalen,bp,block) >= 0 )
{
block->fpipbits = (uint32_t)addr->ipbits;
block->RO.recvlen = datalen;
@ -169,7 +169,7 @@ int32_t gecko_hwmset(struct supernet_info *myinfo,struct iguana_info *virt,struc
prevbp->emitfinish = (uint32_t)(time(NULL) - 3600);
iguana_bundlepurgefiles(virt,prevbp);
iguana_savehdrs(virt);
iguana_bundlevalidate(virt,prevbp,1);
iguana_bundlevalidate(myinfo,virt,prevbp,1);
for (i=0; i<block->RO.txn_count; i++)
gecko_txidpurge(virt,txarray[i].txid);
}
@ -186,7 +186,7 @@ char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_info *virt,c
struct iguana_txblock txdata; int32_t height,valid,adjacent,gap,n,i,j,len = -1; struct iguana_block *block,*prev; struct iguana_txid tx; char str[65],str2[65]; bits256 txid,threshold; struct iguana_msgtx *txs;
memset(&txdata,0,sizeof(txdata));
iguana_memreset(&virt->TXMEM);
if ( (n= iguana_gentxarray(virt,&virt->TXMEM,&txdata,&len,data,datalen)) == datalen || n == datalen-1 )
if ( (n= iguana_gentxarray(myinfo,virt,&virt->TXMEM,&txdata,&len,data,datalen)) == datalen || n == datalen-1 )
{
if ( bits256_cmp(hash2,txdata.zblock.RO.hash2) != 0 )
{
@ -212,7 +212,7 @@ char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_info *virt,c
} else printf("%s is new txid ht.%d i.%d\n",bits256_str(str,txid),virt->blocks.hwmchain.height,i);
}
txdata.zblock.RO.allocsize = iguana_ROallocsize(virt);
if ( iguana_blockvalidate(virt,&valid,(struct iguana_block *)&txdata.zblock,1) < 0 )
if ( iguana_blockvalidate(myinfo,virt,&valid,(struct iguana_block *)&txdata.zblock,1) < 0 )
{
char str[65]; printf("got block that doesnt validate? %s\n",bits256_str(str,txdata.zblock.RO.hash2));
return(clonestr("{\"error\":\"gecko block didnt validate\"}"));
@ -312,11 +312,11 @@ char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *a
printf("REJECT: duplicate block %s\n",bits256_str(str,hash2));
return(clonestr("{\"error\":\"duplicate block rejected\"}"));
}
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr);
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgzblockhdr) : sizeof(struct iguana_msgblockhdr);
//nBits = gecko_nBits(virt,&prevtimestamp,(struct iguana_block *)&virt->blocks.hwmchain,GECKO_DIFFITERS);
//if ( gecko_blocknonce_verify(virt,data,hdrsize,nBits,virt->blocks.hwmchain.RO.timestamp,prevtimestamp) > 0 )
{
iguana_rwblock(symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,&msg,datalen);
iguana_rwblock(myinfo,symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,(void *)&msg,datalen);
if ( bits256_cmp(hash2,checkhash2) == 0 )
{
if ( gecko_blocknonce_verify(virt,data,hdrsize,msg.H.bits,0,0) > 0 )
@ -341,7 +341,7 @@ int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *bt
if ( jobj(retjson,"error") == 0 )
{
valsobj = cJSON_CreateObject();
jaddnum(valsobj,"minresults",NUMRELAYS - 1);
jaddnum(valsobj,"numrequired",NUMRELAYS - 1);
jaddnum(valsobj,"timeout",3000);
jaddnum(valsobj,"fanout",-1);
jaddnum(valsobj,"height",height);

12
gecko/gecko_headers.c

@ -28,7 +28,7 @@ int32_t basilisk_respond_geckogetheaders(struct supernet_info *myinfo,struct igu
{
if ( block != 0 )
{
if ( (n= iguana_headerget(virt,&serialized[len],maxsize-len,block)) > 0 )
if ( (n= iguana_headerget(myinfo,virt,&serialized[len],maxsize-len,block)) > 0 )
len += n;
}
hash2 = iguana_blockhash(virt,height+i+1);
@ -53,7 +53,7 @@ void gecko_blockhashupdate(struct iguana_info *virt,bits256 hash2,int32_t height
char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt,char *remoteaddr,uint8_t *data,int32_t datalen,bits256 firsthash2)
{
bits256 hash2,prevhash2; struct iguana_block *block; int32_t height,firstheight,i,len=0,n,num; struct iguana_msgblock msgB; char str[65],str2[65];
bits256 hash2,prevhash2; struct iguana_block *block; int32_t height,firstheight,i,len=0,n,num; struct iguana_msgzblock zmsgB; char str[65],str2[65];
num = (int32_t)(datalen / 84);
printf("headers.%s arrived.%d from %s\n",virt->symbol,num,bits256_str(str,firsthash2));
if ( (block= iguana_blockfind("geckohdrs",virt,firsthash2)) != 0 && (firstheight= block->height) >= 0 )
@ -62,14 +62,14 @@ char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt
prevhash2 = firsthash2;
for (i=0; i<num; i++)
{
if ( (n= iguana_rwblock(virt->symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&hash2,&data[len],&msgB,datalen-len)) > 0 )
if ( (n= iguana_rwblock(myinfo,virt->symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&hash2,&data[len],&zmsgB,datalen-len)) > 0 )
{
if ( bits256_cmp(msgB.H.prev_block,prevhash2) == 0 )
if ( bits256_cmp(zmsgB.zH.prev_block,prevhash2) == 0 )
{
height = (firstheight + i + 1);
gecko_blockhashupdate(virt,hash2,height);
printf("ht.%d %s %08x t.%u\n",height,bits256_str(str,hash2),msgB.H.bits,msgB.H.timestamp);
} else printf("ht.%d non prevhash i.%d %s %s\n",height,i,bits256_str(str,prevhash2),bits256_str(str2,msgB.H.prev_block));
printf("ht.%d %s\n",height,bits256_str(str,hash2));
} else printf("ht.%d non prevhash i.%d %s %s\n",height,i,bits256_str(str,prevhash2),bits256_str(str2,zmsgB.zH.prev_block));
len += n;
prevhash2 = hash2;
}

9
gecko/gecko_mempool.c

@ -226,10 +226,10 @@ int32_t basilisk_respond_geckogettx(struct supernet_info *myinfo,struct iguana_i
char *gecko_txarrived(struct supernet_info *myinfo,struct iguana_info *virt,char *remoteaddr,uint8_t *serialized,int32_t datalen,bits256 txid)
{
struct gecko_mempool *pool; int64_t txfee,vinstotal,voutstotal; uint64_t value; int32_t i,numvins,numvouts,txlen,spentheight,minconf,maxconf,unspentind; struct iguana_msgtx msg; char *rawtx; struct gecko_memtx *memtx; struct iguana_info *btcd; struct iguana_outpoint outpt;
struct gecko_mempool *pool; int64_t txfee,vinstotal,voutstotal; uint64_t value; int32_t i,numvins,numvouts,txlen,spentheight,minconf,maxconf; struct iguana_msgtx msg; char *rawtx; struct gecko_memtx *memtx; struct iguana_info *btcd; struct iguana_outpoint outpt;
memset(&msg,0,sizeof(msg));
iguana_memreset(&virt->TXMEM);
txlen = iguana_rwtx(virt->chain->zcash,0,&virt->TXMEM,serialized,&msg,datalen,&txid,virt->chain->isPoS,strcmp("VPN",virt->symbol) == 0);
txlen = iguana_rwtx(myinfo,virt->chain->zcash,0,virt,&virt->TXMEM,serialized,&msg,datalen,&txid,virt->chain->isPoS,strcmp("VPN",virt->symbol) == 0);
vinstotal = voutstotal = 0;
maxconf = virt->longestchain;
minconf = virt->chain->minconfirms;
@ -237,11 +237,8 @@ char *gecko_txarrived(struct supernet_info *myinfo,struct iguana_info *virt,char
{
for (i=0; i<numvins; i++)
{
if ( (unspentind= iguana_RTunspentindfind(myinfo,virt,0,0,0,&value,&spentheight,msg.vins[i].prev_hash,msg.vins[i].prev_vout,virt->bundlescount-1,1)) != 0 )
if ( iguana_RTunspentindfind(myinfo,virt,&outpt,0,0,0,&value,&spentheight,msg.vins[i].prev_hash,msg.vins[i].prev_vout,virt->bundlescount-1,1) == 0 )
{
memset(&outpt,0,sizeof(outpt));
outpt.hdrsi = spentheight / virt->chain->bundlesize;
outpt.unspentind = unspentind;
if ( iguana_unspentavail(myinfo,virt,outpt,minconf,maxconf) != value )
{
printf("vin.%d already spent\n",i);

20
gecko/gecko_miner.c

@ -215,20 +215,20 @@ char *gecko_blockconstruct(struct supernet_info *myinfo,struct iguana_info *virt
threshold = bits256_from_compact(newblock->RO.bits);
if ( (newblock->RO.nonce= *noncep) == 0 )
{
struct iguana_msgblock msg;
memset(&msg,0,sizeof(msg));
msg.H.version = newblock->RO.version;
msg.H.prev_block = newblock->RO.prev_block;
msg.H.merkle_root = newblock->RO.merkle_root;
msg.H.timestamp = newblock->RO.timestamp;
msg.H.bits = newblock->RO.bits;
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg;
memset(&zmsg,0,sizeof(zmsg));
msg->H.version = newblock->RO.version;
msg->H.prev_block = newblock->RO.prev_block;
msg->H.merkle_root = newblock->RO.merkle_root;
msg->H.timestamp = newblock->RO.timestamp;
msg->H.bits = newblock->RO.bits;
for (i=0; i<GECKO_MAXMINERITERS; i++)
{
OS_randombytes((void *)noncep,sizeof(*noncep));
msg.H.nonce = *noncep;
msg->H.nonce = *noncep;
//n = iguana_serialize_block(virt->chain,&hash2,serialized,newblock);
//char str[65]; printf("nonce.%08x %s\n",newblock->RO.nonce,bits256_str(str,newblock->RO.hash2));
len = iguana_rwblockhdr(1,virt->chain->zcash,serialized,&msg);
len = iguana_rwblockhdr(1,virt->chain->zcash,serialized,&zmsg);
hash2 = iguana_calcblockhash(virt->symbol,virt->chain->hashalgo,serialized,len);
if ( bits256_cmp(threshold,hash2) > 0 )
{
@ -247,7 +247,7 @@ char *gecko_blockconstruct(struct supernet_info *myinfo,struct iguana_info *virt
}
}
newblock->RO.nonce = *noncep;
n = iguana_serialize_block(virt->chain,&newblock->RO.hash2,serialized,newblock);
n = iguana_serialize_block(myinfo,virt->chain,&newblock->RO.hash2,serialized,newblock);
while ( 1 && time(NULL) <= newblock->RO.timestamp + GECKO_MAXFUTUREBLOCK )
{
//printf("wait for block to be close enough to now: lag %ld\n",time(NULL) - newblock->RO.timestamp);

297
iguana.vcxproj

@ -0,0 +1,297 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{80F58B93-D1FC-4FC4-A880-1F40A1FC851B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ConsoleApplication3</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<ProjectName>iguana</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level2</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="basilisk\basilisk.h" />
<ClInclude Include="crypto777\jpeg\cderror.h" />
<ClInclude Include="crypto777\jpeg\cdjpeg.h" />
<ClInclude Include="crypto777\jpeg\jconfig.h" />
<ClInclude Include="crypto777\jpeg\jdct.h" />
<ClInclude Include="crypto777\jpeg\jerror.h" />
<ClInclude Include="crypto777\jpeg\jinclude.h" />
<ClInclude Include="crypto777\jpeg\jmemsys.h" />
<ClInclude Include="crypto777\jpeg\jmorecfg.h" />
<ClInclude Include="crypto777\jpeg\jpegint.h" />
<ClInclude Include="crypto777\jpeg\jpeglib.h" />
<ClInclude Include="crypto777\jpeg\jversion.h" />
<ClInclude Include="crypto777\jpeg\transupp.h" />
<ClInclude Include="crypto777\OS_portable.h" />
<ClInclude Include="datachain\datachain.h" />
<ClInclude Include="gecko\gecko.h" />
<ClInclude Include="iguana\exchanges777.h" />
<ClInclude Include="iguana\iguana777.h" />
<ClInclude Include="iguana\mini-gmp.h" />
<ClInclude Include="includes\iguana_defines.h" />
<ClInclude Include="includes\iguana_funcs.h" />
<ClInclude Include="includes\iguana_structs.h" />
<ClInclude Include="OSlibs\win\mingw.h" />
<ClInclude Include="OSlibs\win\mman.h" />
<ClInclude Include="OSlibs\win\pthread.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="basilisk\basilisk.c" />
<ClCompile Include="crypto777\bitcoind_RPC.c" />
<ClCompile Include="crypto777\cJSON.c" />
<ClCompile Include="crypto777\curve25519-donna.c" />
<ClCompile Include="crypto777\curve25519.c" />
<ClCompile Include="crypto777\hmac_sha512.c" />
<ClCompile Include="crypto777\iguana_OS.c" />
<ClCompile Include="crypto777\iguana_serdes.c" />
<ClCompile Include="crypto777\iguana_utils.c" />
<ClCompile Include="crypto777\inet.c" />
<ClCompile Include="crypto777\jpeg\jaricom.c" />
<ClCompile Include="crypto777\jpeg\jcapimin.c" />
<ClCompile Include="crypto777\jpeg\jcapistd.c" />
<ClCompile Include="crypto777\jpeg\jcarith.c" />
<ClCompile Include="crypto777\jpeg\jccoefct.c" />
<ClCompile Include="crypto777\jpeg\jccolor.c" />
<ClCompile Include="crypto777\jpeg\jcdctmgr.c" />
<ClCompile Include="crypto777\jpeg\jchuff.c" />
<ClCompile Include="crypto777\jpeg\jcinit.c" />
<ClCompile Include="crypto777\jpeg\jcmainct.c" />
<ClCompile Include="crypto777\jpeg\jcmarker.c" />
<ClCompile Include="crypto777\jpeg\jcmaster.c" />
<ClCompile Include="crypto777\jpeg\jcomapi.c" />
<ClCompile Include="crypto777\jpeg\jcparam.c" />
<ClCompile Include="crypto777\jpeg\jcprepct.c" />
<ClCompile Include="crypto777\jpeg\jcsample.c" />
<ClCompile Include="crypto777\jpeg\jctrans.c" />
<ClCompile Include="crypto777\jpeg\jdapimin.c" />
<ClCompile Include="crypto777\jpeg\jdapistd.c" />
<ClCompile Include="crypto777\jpeg\jdarith.c" />
<ClCompile Include="crypto777\jpeg\jdatadst.c" />
<ClCompile Include="crypto777\jpeg\jdatasrc.c" />
<ClCompile Include="crypto777\jpeg\jdcoefct.c" />
<ClCompile Include="crypto777\jpeg\jdcolor.c" />
<ClCompile Include="crypto777\jpeg\jddctmgr.c" />
<ClCompile Include="crypto777\jpeg\jdhuff.c" />
<ClCompile Include="crypto777\jpeg\jdinput.c" />
<ClCompile Include="crypto777\jpeg\jdmainct.c" />
<ClCompile Include="crypto777\jpeg\jdmarker.c" />
<ClCompile Include="crypto777\jpeg\jdmaster.c" />
<ClCompile Include="crypto777\jpeg\jdmerge.c" />
<ClCompile Include="crypto777\jpeg\jdpostct.c" />
<ClCompile Include="crypto777\jpeg\jdsample.c" />
<ClCompile Include="crypto777\jpeg\jdtrans.c" />
<ClCompile Include="crypto777\jpeg\jerror.c" />
<ClCompile Include="crypto777\jpeg\jfdctflt.c" />
<ClCompile Include="crypto777\jpeg\jfdctfst.c" />
<ClCompile Include="crypto777\jpeg\jfdctint.c" />
<ClCompile Include="crypto777\jpeg\jidctflt.c" />
<ClCompile Include="crypto777\jpeg\jidctfst.c" />
<ClCompile Include="crypto777\jpeg\jidctint.c" />
<ClCompile Include="crypto777\jpeg\jmemmgr.c" />
<ClCompile Include="crypto777\jpeg\jquant1.c" />
<ClCompile Include="crypto777\jpeg\jquant2.c" />
<ClCompile Include="crypto777\jpeg\jutils.c" />
<ClCompile Include="crypto777\jpeg\unix\jmemname.c" />
<ClCompile Include="crypto777\OS_nonportable.c" />
<ClCompile Include="crypto777\OS_portable.c" />
<ClCompile Include="crypto777\OS_time.c" />
<ClCompile Include="crypto777\ramcoder.c" />
<ClCompile Include="crypto777\SaM.c" />
<ClCompile Include="crypto777\scrypt.c" />
<ClCompile Include="crypto777\tweetnacl.c" />
<ClCompile Include="datachain\datachain.c" />
<ClCompile Include="gecko\gecko.c" />
<ClCompile Include="iguana\iguana777.c" />
<ClCompile Include="iguana\iguana_accept.c" />
<ClCompile Include="iguana\iguana_bitmap.c" />
<ClCompile Include="iguana\iguana_blocks.c" />
<ClCompile Include="iguana\iguana_bundles.c" />
<ClCompile Include="iguana\iguana_chains.c" />
<ClCompile Include="iguana\iguana_exchanges.c" />
<ClCompile Include="iguana\iguana_init.c" />
<ClCompile Include="iguana\iguana_interpreter.c" />
<ClCompile Include="iguana\iguana_json.c" />
<ClCompile Include="iguana\iguana_mofn.c" />
<ClCompile Include="iguana\iguana_msg.c" />
<ClCompile Include="iguana\iguana_passport.c" />
<ClCompile Include="iguana\iguana_payments.c" />
<ClCompile Include="iguana\iguana_peers.c" />
<ClCompile Include="iguana\iguana_ramchain.c" />
<ClCompile Include="iguana\iguana_realtime.c" />
<ClCompile Include="iguana\iguana_recv.c" />
<ClCompile Include="iguana\iguana_rpc.c" />
<ClCompile Include="iguana\iguana_scripts.c" />
<ClCompile Include="iguana\iguana_secp.c" />
<ClCompile Include="iguana\iguana_sign.c" />
<ClCompile Include="iguana\iguana_spendvectors.c" />
<ClCompile Include="iguana\iguana_stake.c" />
<ClCompile Include="iguana\iguana_tradebots.c" />
<ClCompile Include="iguana\iguana_tx.c" />
<ClCompile Include="iguana\iguana_txidfind.c" />
<ClCompile Include="iguana\iguana_unspents.c" />
<ClCompile Include="iguana\iguana_volatiles.c" />
<ClCompile Include="iguana\iguana_wallet.c" />
<ClCompile Include="iguana\main.c" />
<ClCompile Include="iguana\mini-gmp.c" />
<ClCompile Include="iguana\ramchain_api.c" />
<ClCompile Include="iguana\secp256k1\src\secp256k1.c" />
<ClCompile Include="iguana\SuperNET_keys.c" />
<ClCompile Include="OSlibs\win\mingw.c" />
</ItemGroup>
<ItemGroup>
<Library Include="pthreadVC2.lib" />
<Library Include="OSlibs\win\libpthreadGC2.a" />
<Library Include="OSlibs\win\libpthreadGC2_64.a" />
</ItemGroup>
<ItemGroup>
<None Include="pthreadvc2.dll" />
<None Include="ucrtbased.dll" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

146
iguana.vcxproj.filters

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="basilisk\basilisk.c" />
<ClCompile Include="crypto777\bitcoind_RPC.c" />
<ClCompile Include="crypto777\cJSON.c" />
<ClCompile Include="crypto777\curve25519-donna.c" />
<ClCompile Include="crypto777\curve25519.c" />
<ClCompile Include="crypto777\hmac_sha512.c" />
<ClCompile Include="crypto777\iguana_OS.c" />
<ClCompile Include="crypto777\iguana_serdes.c" />
<ClCompile Include="crypto777\iguana_utils.c" />
<ClCompile Include="crypto777\inet.c" />
<ClCompile Include="crypto777\jpeg\jaricom.c" />
<ClCompile Include="crypto777\jpeg\jcapimin.c" />
<ClCompile Include="crypto777\jpeg\jcapistd.c" />
<ClCompile Include="crypto777\jpeg\jcarith.c" />
<ClCompile Include="crypto777\jpeg\jccoefct.c" />
<ClCompile Include="crypto777\jpeg\jccolor.c" />
<ClCompile Include="crypto777\jpeg\jcdctmgr.c" />
<ClCompile Include="crypto777\jpeg\jchuff.c" />
<ClCompile Include="crypto777\jpeg\jcinit.c" />
<ClCompile Include="crypto777\jpeg\jcmainct.c" />
<ClCompile Include="crypto777\jpeg\jcmarker.c" />
<ClCompile Include="crypto777\jpeg\jcmaster.c" />
<ClCompile Include="crypto777\jpeg\jcomapi.c" />
<ClCompile Include="crypto777\jpeg\jcparam.c" />
<ClCompile Include="crypto777\jpeg\jcprepct.c" />
<ClCompile Include="crypto777\jpeg\jcsample.c" />
<ClCompile Include="crypto777\jpeg\jctrans.c" />
<ClCompile Include="crypto777\jpeg\jdapimin.c" />
<ClCompile Include="crypto777\jpeg\jdapistd.c" />
<ClCompile Include="crypto777\jpeg\jdarith.c" />
<ClCompile Include="crypto777\jpeg\jdatadst.c" />
<ClCompile Include="crypto777\jpeg\jdatasrc.c" />
<ClCompile Include="crypto777\jpeg\jdcoefct.c" />
<ClCompile Include="crypto777\jpeg\jdcolor.c" />
<ClCompile Include="crypto777\jpeg\jddctmgr.c" />
<ClCompile Include="crypto777\jpeg\jdhuff.c" />
<ClCompile Include="crypto777\jpeg\jdinput.c" />
<ClCompile Include="crypto777\jpeg\jdmainct.c" />
<ClCompile Include="crypto777\jpeg\jdmarker.c" />
<ClCompile Include="crypto777\jpeg\jdmaster.c" />
<ClCompile Include="crypto777\jpeg\jdmerge.c" />
<ClCompile Include="crypto777\jpeg\jdpostct.c" />
<ClCompile Include="crypto777\jpeg\jdsample.c" />
<ClCompile Include="crypto777\jpeg\jdtrans.c" />
<ClCompile Include="crypto777\jpeg\jerror.c" />
<ClCompile Include="crypto777\jpeg\jfdctflt.c" />
<ClCompile Include="crypto777\jpeg\jfdctfst.c" />
<ClCompile Include="crypto777\jpeg\jfdctint.c" />
<ClCompile Include="crypto777\jpeg\jidctflt.c" />
<ClCompile Include="crypto777\jpeg\jidctfst.c" />
<ClCompile Include="crypto777\jpeg\jidctint.c" />
<ClCompile Include="crypto777\jpeg\jmemmgr.c" />
<ClCompile Include="crypto777\jpeg\jquant1.c" />
<ClCompile Include="crypto777\jpeg\jquant2.c" />
<ClCompile Include="crypto777\jpeg\jutils.c" />
<ClCompile Include="crypto777\jpeg\unix\jmemname.c" />
<ClCompile Include="crypto777\OS_nonportable.c" />
<ClCompile Include="crypto777\OS_portable.c" />
<ClCompile Include="crypto777\OS_time.c" />
<ClCompile Include="crypto777\ramcoder.c" />
<ClCompile Include="crypto777\SaM.c" />
<ClCompile Include="crypto777\scrypt.c" />
<ClCompile Include="crypto777\tweetnacl.c" />
<ClCompile Include="datachain\datachain.c" />
<ClCompile Include="gecko\gecko.c" />
<ClCompile Include="iguana\iguana777.c" />
<ClCompile Include="iguana\iguana_accept.c" />
<ClCompile Include="iguana\iguana_bitmap.c" />
<ClCompile Include="iguana\iguana_blocks.c" />
<ClCompile Include="iguana\iguana_bundles.c" />
<ClCompile Include="iguana\iguana_chains.c" />
<ClCompile Include="iguana\iguana_exchanges.c" />
<ClCompile Include="iguana\iguana_init.c" />
<ClCompile Include="iguana\iguana_interpreter.c" />
<ClCompile Include="iguana\iguana_json.c" />
<ClCompile Include="iguana\iguana_mofn.c" />
<ClCompile Include="iguana\iguana_msg.c" />
<ClCompile Include="iguana\iguana_passport.c" />
<ClCompile Include="iguana\iguana_payments.c" />
<ClCompile Include="iguana\iguana_peers.c" />
<ClCompile Include="iguana\iguana_ramchain.c" />
<ClCompile Include="iguana\iguana_realtime.c" />
<ClCompile Include="iguana\iguana_recv.c" />
<ClCompile Include="iguana\iguana_rpc.c" />
<ClCompile Include="iguana\iguana_scripts.c" />
<ClCompile Include="iguana\iguana_secp.c" />
<ClCompile Include="iguana\iguana_sign.c" />
<ClCompile Include="iguana\iguana_spendvectors.c" />
<ClCompile Include="iguana\iguana_stake.c" />
<ClCompile Include="iguana\iguana_tradebots.c" />
<ClCompile Include="iguana\iguana_tx.c" />
<ClCompile Include="iguana\iguana_txidfind.c" />
<ClCompile Include="iguana\iguana_unspents.c" />
<ClCompile Include="iguana\iguana_volatiles.c" />
<ClCompile Include="iguana\iguana_wallet.c" />
<ClCompile Include="iguana\main.c" />
<ClCompile Include="iguana\mini-gmp.c" />
<ClCompile Include="iguana\ramchain_api.c" />
<ClCompile Include="iguana\secp256k1\src\secp256k1.c" />
<ClCompile Include="iguana\SuperNET_keys.c" />
<ClCompile Include="OSlibs\win\mingw.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="basilisk\basilisk.h" />
<ClInclude Include="crypto777\jpeg\cderror.h" />
<ClInclude Include="crypto777\jpeg\cdjpeg.h" />
<ClInclude Include="crypto777\jpeg\jconfig.h" />
<ClInclude Include="crypto777\jpeg\jdct.h" />
<ClInclude Include="crypto777\jpeg\jerror.h" />
<ClInclude Include="crypto777\jpeg\jinclude.h" />
<ClInclude Include="crypto777\jpeg\jmemsys.h" />
<ClInclude Include="crypto777\jpeg\jmorecfg.h" />
<ClInclude Include="crypto777\jpeg\jpegint.h" />
<ClInclude Include="crypto777\jpeg\jpeglib.h" />
<ClInclude Include="crypto777\jpeg\jversion.h" />
<ClInclude Include="crypto777\jpeg\transupp.h" />
<ClInclude Include="crypto777\OS_portable.h" />
<ClInclude Include="datachain\datachain.h" />
<ClInclude Include="gecko\gecko.h" />
<ClInclude Include="iguana\exchanges777.h" />
<ClInclude Include="iguana\iguana777.h" />
<ClInclude Include="iguana\mini-gmp.h" />
<ClInclude Include="includes\iguana_defines.h" />
<ClInclude Include="includes\iguana_funcs.h" />
<ClInclude Include="includes\iguana_structs.h" />
<ClInclude Include="OSlibs\win\mingw.h" />
<ClInclude Include="OSlibs\win\mman.h" />
<ClInclude Include="OSlibs\win\pthread.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<Library Include="pthreadVC2.lib" />
<Library Include="OSlibs\win\libpthreadGC2.a" />
<Library Include="OSlibs\win\libpthreadGC2_64.a" />
</ItemGroup>
<ItemGroup>
<None Include="pthreadvc2.dll" />
<None Include="ucrtbased.dll" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
</Project>

2
iguana/SuperNET_keys.c

@ -309,7 +309,7 @@ int32_t _SuperNET_encryptjson(struct supernet_info *myinfo,char *destfname,char
wallet2shared = SuperNET_wallet2shared(wallethash,wallet2priv);
wallet2pub = curve25519(wallet2shared,curve25519_basepoint9());
sprintf(destfname,"%s/%s",GLOBAL_CONFSDIR,bits256_str(str,wallet2pub));
printf("SAVE ARGJSON.(%s) [%s, %s] -> destfname.(%s)\n",jprint(argjson,0),passphrase,fname2fa,destfname);
//printf("SAVE ARGJSON.(%s) [%s, %s] -> destfname.(%s)\n",jprint(argjson,0),passphrase,fname2fa,destfname);
//printf("shared.%llx -> pub.%s\n",(long long)wallet2shared.txid,bits256_str(str,wallet2pub));
SuperNET_savejsonfile(myinfo,destfname,wallethash,wallet2pub,argjson);
return(0);

8
iguana/coins/allofus

@ -17,3 +17,11 @@ sleep 5
../agents/iguana coins/genuno.json &
sleep 5
../agents/iguana coins/genzet.json &
sleep 5
../agents/iguana coins/genbtm.json &
sleep 5
../agents/iguana coins/gencarb.json &
sleep 5
../agents/iguana coins/genanc.json &
sleep 5
../agents/iguana coins/genfrk.json &

6
iguana/coins/basilisk

@ -1,4 +1,4 @@
curl --url "http://127.0.0.1:7778" --data "{\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":16,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":14631}"
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":16,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":8333}"
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":11,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":16,\"newcoin\":\"LTC\",\"name\":\"Litecoin\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fbc0b6db\",\"p2p\":9333,\"rpc\":9334,\"pubval\":48,\"p2shval\":5,\"wifval\":176,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2\",\"genesis\":{\"version\":1,\"timestamp\":1317972665,\"nBits\":\"1e0ffff0\",\"nonce\":2084524493,\"merkle_root\":\"97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9\"},\"alertpubkey\":\"040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9\",\"protover\":70002}"
curl --url "http://127.0.0.1:7778" --data "{\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":16,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":14631,\"rpc\":14632}"
#curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":16,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":8333}"
#curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":11,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":16,\"newcoin\":\"LTC\",\"name\":\"Litecoin\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fbc0b6db\",\"p2p\":9333,\"rpc\":9334,\"pubval\":48,\"p2shval\":5,\"wifval\":176,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2\",\"genesis\":{\"version\":1,\"timestamp\":1317972665,\"nBits\":\"1e0ffff0\",\"nonce\":2084524493,\"merkle_root\":\"97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9\"},\"alertpubkey\":\"040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9\",\"protover\":70002}"

0
iguana/coins/genanc

0
iguana/coins/genanc.json

1
iguana/coins/genblk

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"maxpeers\":256,\"newcoin\":\"BLK\",\"name\":\"BlackCoin\",\"netmagic\":\"70352205\",\"p2p\":15714,\"rpc\":15715,\"pubval\":25,\"p2shval\":85,\"wifval\":153,\"txfee_satoshis\":\"10000\",\"minconfirms\":2,\"genesishash\":\"000001faef25dec4fbcf906e6242621df2c183bf232f263d0ba5b101911e4563\",\"genesis\":{\"hashalgo\":\"scrypt\",\"version\":1,\"timestamp\":1393221600,\"nBits\":\"1e0fffff\",\"nonce\":164482,\"merkle_root\":\"12630d16a97f24b287c8c2594dda5fb98c9e6c70fc61d44191931ea2aa08dc90\"},\"alertpubkey\":\"0486bce1bac0d543f104cbff2bd23680056a3b9ea05e1137d2ff90eeb5e08472eb500322593a2cb06fbf8297d7beb6cd30cb90f98153b5b7cce1493749e41e0284\",\"isPoS\":1}"

2
iguana/coins/genbtc

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":64,\"endpend\":2,\"services\":128,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":11,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"

2
iguana/coins/genbtc.json

@ -1 +1 @@
{"numhelpers":8,"prefetchlag":-1,"poll":1,"active":1,"agent":"iguana","method":"addcoin","newcoin":"BTC","startpend":512,"endpend":512,"services":129,"maxpeers":512,"RELAY":1,"VALIDATE":1,"portp2p":8333}
{"numhelpers":1,"prefetchlag":11,"poll":1,"active":1,"agent":"iguana","method":"addcoin","newcoin":"BTC","startpend":16,"endpend":16,"services":129,"maxpeers":512,"RELAY":1,"VALIDATE":1,"portp2p":8333}

1
iguana/coins/genbtc8.json

@ -0,0 +1 @@
{"numhelpers":8,"prefetchlag":11,"poll":1,"active":1,"agent":"iguana","method":"addcoin","newcoin":"BTC","startpend":16,"endpend":16,"services":129,"maxpeers":512,"RELAY":1,"VALIDATE":1,"portp2p":8333}

2
iguana/coins/genbtcd

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":8,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632}"
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":11,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"minconfirms\":7}"

1
iguana/coins/genbtcdsigs

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":8,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"RELAY\":1,\"VALIDATE\":2,\"portp2p\":14631,\"rpc\":14632}"

0
iguana/coins/genbtm

0
iguana/coins/genbtm.json

0
iguana/coins/gencarb

0
iguana/coins/gencarb.json

0
iguana/coins/genfrk

0
iguana/coins/genfrk.json

2
iguana/coins/gengmc

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"startpend\":8,\"endpend\":2,\"services\":129,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"maxpeers\":256,\"newcoin\":\"GMC\",\"name\":\"GameCredits\",\"netmagic\":\"fbc0b6db\",\"p2p\":40002,\"rpc\":40001,\"pubval\":38,\"p2shval\":5,\"wifval\":166,\"txfee_satoshis\":\"100000\",\"minconfirms\":2,\"genesishash\":\"91ec5f25ee9a0ffa1af7d4da4db9a552228dd2dc77cdb15b738be4e1f55f30ee\",\"genesis\":{\"hashalgo\":\"scrypt\",\"version\":1,\"timestamp\":1392757140,\"nBits\":\"1e0ffff0\",\"nonce\":2084565393,\"merkle_root\":\"d849db99a14164f4b4c8ad6d2d8d7e2b1ba7f89963e9f4bf9fad5ff1a4754429\"},\"alertpubkey\":\"04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284\",\"auxpow\":1,\"protover\":80006,\"isPoS\":0}"
curl --url "http://127.0.0.1:7778" --data "{\"startpend\":8,\"endpend\":4,\"services\":129,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"maxpeers\":256,\"newcoin\":\"GMC\",\"name\":\"GameCredits\",\"netmagic\":\"fbc0b6db\",\"p2p\":40002,\"rpc\":40001,\"pubval\":38,\"p2shval\":5,\"wifval\":166,\"txfee_satoshis\":\"100000\",\"minconfirms\":2,\"genesishash\":\"91ec5f25ee9a0ffa1af7d4da4db9a552228dd2dc77cdb15b738be4e1f55f30ee\",\"genesis\":{\"hashalgo\":\"scrypt\",\"version\":1,\"timestamp\":1392757140,\"nBits\":\"1e0ffff0\",\"nonce\":2084565393,\"merkle_root\":\"d849db99a14164f4b4c8ad6d2d8d7e2b1ba7f89963e9f4bf9fad5ff1a4754429\"},\"alertpubkey\":\"04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284\",\"auxpow\":1,\"protover\":80006,\"isPoS\":0,\"fixit\":0}"

2
iguana/coins/genkmd

@ -0,0 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"unitval\":\"20\",\"zcash\":1,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":32,\"newcoin\":\"KMD\",\"name\":\"Komodo\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"f9eee48d\",\"p2p\":7770,\"rpc\":7771,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0}"

1
iguana/coins/gensxc

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"protover\":60002,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"maxpeers\":256,\"newcoin\":\"SXC\",\"name\":\"Sexcoin\",\"netmagic\":\"fbc0b6db\",\"p2p\":16814,\"rpc\":31812,\"pubval\":62,\"p2shval\":5,\"txfee_satoshis\":\"10000000\",\"minconfirms\":2,\"genesishash\":\"f42b9553085a1af63d659d3907a42c3a0052bbfa2693d3acf990af85755f2279\",\"genesis\":{\"version\":1,\"timestamp\":1369146359,\"nBits\":\"1e7fffff\",\"nonce\":244086,\"merkle_root\":\"661de12dc8dd26989adb169733b5a99150d52b8b6e8332976277856e246101f4\"},\"alertpubkey\":\"04a5814813115273a109cff99907ba4a05d951873dae7acb6c973d0c9e7c88911a3dbc9aa600deac241b91707e7b4ffb30ad91c8e56e695a1ddf318592988afe0a\",\"isPoS\":1}"

2
iguana/coins/gensys

@ -1,2 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":18,\"endpend\":18,\"services\":129,\"maxpeers\":256,\"newcoin\":\"SYS\",\"name\":\"SYScoin\",\"hasheaders\":0,\"useaddmultisig\":0,\"netmagic\":\"f9beb4d9\",\"p2p\":8369,\"rpc\":8370,\"pubval\":0,\"p2shval\":5,\"wifval\":128,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"0000072d66e51ab87de265765cc8bdd2d229a4307c672a1b3d5af692519cf765\",\"genesis\":{\"version\":1,\"timestamp\":1450473723,\"nBits\":\"1e0ffff0\",\"nonce\":5258726,\"merkle_root\":\"5215c5a2af9b63f2550b635eb2b354bb13645fd8fa31275394eb161944303065\"},\"protover\":70012,\"auxpow\":1}"
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":18,\"endpend\":18,\"services\":129,\"maxpeers\":256,\"newcoin\":\"SYS\",\"name\":\"SYScoin\",\"hasheaders\":0,\"useaddmultisig\":0,\"netmagic\":\"f9beb4d9\",\"p2p\":8369,\"rpc\":8370,\"pubval\":0,\"p2shval\":5,\"wifval\":128,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"0000072d66e51ab87de265765cc8bdd2d229a4307c672a1b3d5af692519cf765\",\"genesis\":{\"version\":1,\"timestamp\":1450473723,\"nBits\":\"1e0ffff0\",\"nonce\":5258726,\"merkle_root\":\"5215c5a2af9b63f2550b635eb2b354bb13645fd8fa31275394eb161944303065\"},\"protover\":70012,\"auxpow\":1,\"fixit\":0}"

2
iguana/coins/gentaz

@ -0,0 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"unitval\":\"20\",\"zcash\":1,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":32,\"newcoin\":\"TAZ\",\"name\":\"Test Zcash\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"a5f1e726\",\"p2p\":18233,\"rpc\":18232,\"pubval\":111,\"p2shval\":196,\"wifval\":239,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"0cdf00b25a93ded11d73ebe1728cf7867f18e1f62aca9554b95e0f3026174e33\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a0000000000000000000000000000000000000000000000000000000000000000dae5494d0f0f0f200900000000000000000000000000000000000000000000000000000000000000fd4005003423da3e41f916bf3ff0ee770eb844a240361abe08a8c9d46bd30226e2ad411a4047b6ddc230d173c60537e470e24f764120f5a2778b2a1285b0727bf79a0b085ad67e6266fb38fd72ef17f827315c42f921720248c983d4100e6ebd1c4b5e8762a973bac3bec7f7153b93752ebbb465f0fc9520bcfc30f9abfe303627338fed6ede9cf1b9173a736cf270cf4d9c6999ff4c3a301a78fd50dab6ccca67a0c5c2e41f216a1f3efd049a74bbe6252f9773bc309d3f9e554d996913ce8e1cec672a1fa4ea59726b61ea9e75d5ce9aa5dbfa96179a293810e02787f26de324fe7c88376ff57e29574a55faff7c2946f3e40e451861c32bf67da7377de3136858a18f34fab1bc8da37726ca2c25fc7b312a5427554ec944da81c7e27255d6c94ade9987ff7daedc2d1cc63d7d4cf93e691d13326fb1c7ee72ccdc0b134eb665fc6a9821e6fef6a6d45e4aac6dca6b505a0100ad56ea4f6fa4cdc2f0d1b65f730104a515172e34163bdb422f99d083e6eb860cf6b3f66642c4dbaf0d0fa1dca1b6166f1d1ffaa55a9d6d6df628afbdd14f1622c1c8303259299521a253bc28fcc93676723158067270fc710a09155a1e50c533e9b79ed5edba4ab70a08a9a2fc0eef0ddae050d75776a9804f8d6ad7e30ccb66c6a98d86710ca7a4dfb4feb159484796b9a015c5764aa3509051c87f729b9877ea41f8b470898c01388ed9098b1e006d3c30fc6e7c781072fa3f75d918505ee8ca75840fc62f67c57060666aa42578a2dd022eda62e3f1e447d7364074d34fd60ad9b138f60422afa6cfcb913fd6c213b496144dbfda7bfc7c24540cfe40ad0c0fd5a8c0902127f53d3178ba1b2a87bf1224d53d3a15e49ccdf121ae872a011c996d1b9793153cdcd4c0a7e99f8a35669788551cca2b62769eda24b6b55e2f4e0ac0d30aa50ecf33c6cdb24adfc922006a7bf434ced800fefe814c94c6fc8caa37b372d5088bb31d2f6b11a7a67ad3f70abbac0d5c256b637828de6cc525978cf151a2e50798e0c591787639a030291272c9ced3ab7d682e03f8c7db51f60163baa85315789666ea8c5cd6f789a7f4a5de4f8a9dfefce20f353cec606492fde8eab3e3b487b3a3a57434f8cf252a4b643fc125c8a5948b06744f5dc306aa587bdc85364c7488235c6edddd78763675e50a9637181519be06dd30c4ba0d845f9ba320d01706fd6dd64d1aa3cd4211a4a7d1d3f2c1ef2766d27d5d2cdf8e7f5e3ea309d4f149bb737305df1373a7f5313abe5986f4aa620bec4b0065d48aafac3631de3771f5c4d2f6eec67b09d9c70a3c1969fecdb014cb3c69832b63cc9d6efa378bff0ef95ffacdeb1675bb326e698f022c1a3a2e1c2b0f05e1492a6d2b7552388eca7ee8a2467ef5d4207f65d4e2ae7e33f13eb473954f249d7c20158ae703e1accddd4ea899f026618695ed2949715678a32a153df32c08922fafad68b1895e3b10e143e712940104b3b352369f4fe79bd1f1dbe03ea9909dbcf5862d1f15b3d1557a6191f54c891513cdb3c729bb9ab08c0d4c35a3ed67d517ffe1e2b7a798521aed15ff9822169c0ec860d7b897340bc2ef4c37f7eb73bd7dafef12c4fd4e6f5dd3690305257ae14ed03df5e3327b68467775a90993e613173fa6650ffa2a26e84b3ce79606bf234eda9f4053307f344099e3b10308d3785b8726fd02d8e94c2759bebd05748c3fe7d5fe087dc63608fb77f29708ab167a13f32da251e249a544124ed50c270cfc6986d9d1814273d2f0510d0d2ea335817207db6a4a23ae9b079967b63b25cb3ceea7001b65b879263f5009ac84ab89738a5b8b71fd032beb9f297326f1f5afa630a5198d684514e242f315a4d95fa6802e82799a525bb653b80b4518ec610a5996403b1391\",\"debug\":0}"

0
iguana/coins/genvia

111
iguana/confs/BTCD_hdrs.txt

@ -1,4 +1,4 @@
1251510
1287010
0 0000044966f40703b516c5af180582d53f783bfd319bb045e2dc3e05ea695d46 a5d211145f8e6ba0920b2893d307c5d7c207ae0800a80955299678d1706ea8ac 000000000c4682089c916de89eb080a877566494d4009c0089baf35fe94de22f
500 000000000680a9a697eb71155b18a5827e0889fca28afb81fcbb46469ed7877e 79f80a8f54c6762d6408347c6dd7dfd2f8b8c191077c1d7881dfc5b7ec6a408e 0000000002b868fe717dc60b8d146de4d9aecf779b7314224908566e01847769
1000 0000000000000cf908c887020f8970b7fe952f8b81164d83a87621dfdb581d08 3356ec4296ff2f04281492b0dedbaed80edeb6dd9170b87230ff79f6b0daade7 0000000000001e7c6d28962a03b3d75ffa1355ecc6d3021893b2727a1ccfc669
@ -2334,15 +2334,15 @@
1166000 a0fac4b306c379866b4c01b909610b9e7e1f2ca794fb5c590aaa2c83a666effc 4b67f68a8adf5d50d262ceb7a95cd82ebf00065db0ab242f696e0a082b7f8151 fa111449ad59977279759470503b67df2cdbea065862f5d3b6ca61b62a34fe1b
1166500 2c79c6b923aec6eefa4951ed06fac160d02c82caaa0a1c11bd49fd6ff59d8ead ec655e3e7f55442ae0e5282b8f91a6d2a88ee19668e0df9d92eed382eba50069 7e597d5b821b7140cd3c10445409fc1f11b4f209df0b7f394c31d7b7f9f954c8
1167000 f20f0ba0c20fab2a4990bb6d31a736d1f444457af660cdc05d133228e8d15047 2166fd932a979f00318f6616c3c2184055c29c214d49a68454be63731fb380d8 63c980d73fad3a22262d71955940980544682a37c1939e259463faae424f1b6d
1167500 a401abd7e22dd4c5857bbecffbbdb575ef2f3b1cbeaccc1ff90aa3cb7ba4d03e cd245140f4ed7ca46bd7dc30295cce6db884a18f06a644408b3122f53d85eb7b 20c8c957ce0424d4a03c4ce971c2e1bde4732d10fe316b1dcf52e3683ea914fd
1168000 169f9da4c456d381a672847adc804eaaa695bc4c50a4b536ee753bab29ed0224 8fca11c8318d16f1364d2663f6cdaaa47a92d008daa7519846f22a68fbff6d44 e66b572b3c4b692d4c2ac327643cd16fd00a7a4ecb91fa4bd2e97d23030301ec
1167500 a401abd7e22dd4c5857bbecffbbdb575ef2f3b1cbeaccc1ff90aa3cb7ba4d03e 0fad862612c685191b30b3116b3bdae78404f3cb3850f4cde5f13f7ec0db7cb5 20c8c957ce0424d4a03c4ce971c2e1bde4732d10fe316b1dcf52e3683ea914fd
1168000 169f9da4c456d381a672847adc804eaaa695bc4c50a4b536ee753bab29ed0224 952e85e8eadb2831ac7a843af4f9e11479ddb10e353bd596c25e4c10fcd6773c e66b572b3c4b692d4c2ac327643cd16fd00a7a4ecb91fa4bd2e97d23030301ec
1168500 54757c8dd834113d79ebeb28a73535972d005c345e33d34d9b9f0d1b5092d71b 3fd4ecda5d6a11063d66ce9a849038ff370c6244d14917ec8c87b2cc3e8e9142 2b9f660ccf344bc479ae9cb412b7f1af7d18e08d585f10d4eb41f77ec366e438
1169000 0408e4fe84a28338f1ac1f36fd6915bcfe05dd3a08ec6c1248c5df58542dff6d bf97ed6cc13fdb2e9817a702a24b264aaf746c67e7a7bf077376dc08ee1ab9dd 1103ca26dab6666385aa27a932c63487da46a44a6c13ee27804a22bb78d9bedf
1169500 e8e952c72e3b1730dcfcc4d73c5c7ca6f64806b1c350cf127e09b05c5e03dffb ccb974938643549c6dbd2eb11bd60cfc7c4a977f88eb2f935ab81f111500dbbe 392391fd3ae91091d658218b2866be420097c4bfaaf209f37aa1961e3e380927
1170000 74283d0f2aad17892d0d4832778bd1f3a55879d8ddbe1314e410bac40f6a6c02 59407452382c4869286b028e35e69940a81ba9c9fff7eb427c0cb4650b18e7fb 25ec2c456054fef281ac033f1160df826f8458a5f7f24be4faf503b6ab9ca070
1170500 038c3e9a4f8af3e1f89208f1e10152279998e4c56c28ee571b64c1b1a2576b11 1c50f607d118aa4bf311d63ea309ac5fd6c023bd73937dfa60ae685684d5d0ca bca5f157ce2ba2f4b2fe57e949e84052ca934dee1d685460e7a207b1ac4f1dcd
1171000 657b4ad8cda15f1fac5b96ee4c78d30d24a202cbff03b05eb42b8a64a9fb3f85 b5ab985da7441c00c83a521cc8191c7b255e45996560aa7b5614c9a85ed10382 441326a82f1c67280dbd7d42d06c41e7f2b131c9b591b7b9f95bee52dc354bb0
1171500 57a6596c7a9b14774681db13f91c27e8d10a2a4a3afb4932bc0e99a352d616b8 a37e46a4e94337bc220479a47c7bcbcc512f9235e06f7cb3ca4af02e2d1784c2 2971d7353bedf68e705796a109ef562fd54215bff4d23e130940de8ff28b2abc
1171500 57a6596c7a9b14774681db13f91c27e8d10a2a4a3afb4932bc0e99a352d616b8 88479e26ee3bc7057bfaaeeda3b7ffe957c16b15f1556406412d28224b76c7e0 2971d7353bedf68e705796a109ef562fd54215bff4d23e130940de8ff28b2abc
1172000 c8c332595916c25863c065b8164053b7306c9b91280395899646a89ef5c7efb9 79045e4de4c46ea93c7531b2983c6cca978a870f81e69caab499819eed84ff97 1ab7491c615a897bf0e521a4da4b85476a0a578946b53af637d95a25426ba645
1172500 de2a9b82e5b0fed78938dfb45b5d03486a9e8f918bd1d10e9a5dc3a5d2ebd375 ba34eb6149f1c2d4a8fda76bea4c0126d2ffb924554b02d46a7dfa3af7a42a95 8cf00395570c76499738996b0ad071319f08337efef9ba5cad46f908b9b495d0
1173000 ba3a9dccb5269e6c3c3b4372dd5473799a479d5f1bfec6f1495704a031cb7257 a5a363ac0a854dcf3b3d461a01bbcd7c23b527a5ff7b1bd80c2556a39b1611a9 be41baa05f09e1eecb3149a981ea9fc7772546695219c581cd96e3acdd89307d
@ -2356,7 +2356,7 @@
1177000 6ffa6c3fdfebe30cf1a7e8ef456d706423ca7370d250108a345c921a43f6d361 e96c39acf261f3f79139e4cae812888ca292b61de0f49a6f14f724458ce941a8 0d27963c7629d5e24f8848666af214eb3753764fb839bd5b3b18b6d5c9f4b4f7
1177500 21944d33335de6e7be3eab1afed00a8840ed09059769a4cc8c95ada2b739bac7 d88e2a0c9645654dfb23354a9f0f90e41735a796e184a969ee32f38e0761f0b6 bb28cb1b9f1156ec25ba4346c69f25bb4a1a30f230199fe560394344a08ff569
1178000 8766dd180ff2d647439a5cbad9b1f79ab7e85c6c9fd748eca22f707a7544985e e250fc2eef43908fd12d91b90828486f99db25f9fa749deed0b9959c3554f667 eef4af40225d005aefb2d36e2d6b6375b78ddbc16712d82598e2e4ed351c41f9
1178500 0bfe9b952084a9906d48fc53724099d6bc735bed7b327ef362f32eebe8c59b08 4053aa9f0b929b2d3f7475fda64edbfa8a5567c3280fe8979da8cddb43e194fc acb4f384b6d271f82cd521ba1753b687b27aced918d9e5c37e4a0a2cfd91a226
1178500 0bfe9b952084a9906d48fc53724099d6bc735bed7b327ef362f32eebe8c59b08 cd078860ede646ae1128e84b2d909892ac34570c9b1ac0eb55aae1e804425110 acb4f384b6d271f82cd521ba1753b687b27aced918d9e5c37e4a0a2cfd91a226
1179000 9052cbdd7759a7dc740c100cfbf1f599192393b4dd166177eab203eef214fd5e a64cb29918db51c90ffca1e590956df66a3b47eead5018e56b6f894376d0f1fd 583a6a580f3062017f6a7ef8b0a51fe13b2f40659101a4bb3bd4cc3ef79c327c
1179500 2d24b0b8f56ac3c5d7016923fcbb74c9a7f2bc5cae1302edcb2a02c9ead8e285 1e8ef0170644ce900729fbf779c85a9f7c4e41913f38bedc655968799c0ec061 843a1a3ac0fb093a840dd998812c3ae7e2bd420f8e10dca85e7b153a2c99f390
1180000 5d7b2c7e019293bf5b7f4c5339aec0ce4e22fe103cb50213e8e7d3f4da3b29c7 10773667c0417cb9c8fb7028d932e840525495a92f5f0872ab2270f4dcf4c4d0 5cf1307b81e3621a6df541defdb59171a59c04a70662ad0423a8549204447215
@ -2393,7 +2393,7 @@
1195500 c224c284a418e9c6170393789ce17221b65b2cb4d01d78bab846023b01337c1c b2e46eb9bf71fbd3559c99029d84df9410d8ee1541662ba79303029dd46189da 6f9b3fdfcab00fc669b96bb50858ba0c41fa7922f7407da5e9683dd3adbe216e
1196000 4f5e727fd3c0c4316ede3129db86b088a9fb077fe6eb3ec9ad84f40e89ddebf0 cc941087965fca35754518a5d3eb21be92bb38882150dab8476b47cb95ac5241 274de1abc69b95db66bb8e1d0fab6cda37df4a00cb676496c08c8751e1e6b86e
1196500 8d8c392d670e068ed6621469c7a4adefabf064424208671109d94edfb0f2e203 16d66ea77ce1b52ef738ab4fa793819f09ad930124dbce9dce4e5e2c701c3d41 3879592b2b19c74ce6f54476140806a4ece95a60a6e107dc2095af40a8c308ba
1197000 1599a2fb940450bab2282542cb60c30afee5c195a4c63fad5ae4c6c2c42f74b9 f022f651ab7fcff2fbe8296d9a2f802ef70de273d05bc7c2dde74666b1ecd05c 04a77a5c3839707bb9a7f96ec74f9517c5b57dc6c4d1a5af5256bb667dec44ea
1197000 1599a2fb940450bab2282542cb60c30afee5c195a4c63fad5ae4c6c2c42f74b9 248bf18b9ef28c09806607778aed8ae2777178b4d946e00a79e70948b147955a 04a77a5c3839707bb9a7f96ec74f9517c5b57dc6c4d1a5af5256bb667dec44ea
1197500 4e570d3ec2424400ad95e0c98e9dacf5c35196d851df3eb410d5af0b58fe6f98 7cd9e67d5115385506704d38c17ae7409ba050d47cf8cdc4736adb935cc0a95a ae20af61def9617941f12b4a704115ad1a030d951db13abbc77cf9377ae3f78c
1198000 d090b0121d9b30c48647797b366e547aa147195753b6d24c9823b004a35d4f40 5f6b352ba1f84934e13d2f144c8313723fe382d05f720f25a175fc3684032e92 fb7e3b75ad79622ea55fe9503327f342125f6f51f1a6aeecb249332bd0a9443a
1198500 33ffa7f777060cb4a65edc50deade02100c9ba4b044351b7cf8483335f1f33a4 6312888eafa2beeee15eba13879b11e753d460a9b54bd14c16cfbd92fed6622a 0c80a80a15684581a2f10b63a58635ae575217b04101066ed6875e519c2cc8e3
@ -2423,7 +2423,7 @@
1210500 65d1e575763ab257869cf3836d24033f4dc201af30420d753da99cf756afc957 04297b9ad1a6a46395ff05e3646a0774ae926119210b7f9518a34ee451ff7876 b7a78eb78dc0de0269e85aad99f6159e0c62cf1896bbbc4d57644ee6841e66e9
1211000 63f7824e59c39582208dba5f1103259d967f57347aa09e9c11a5faeaeddfd1bc 16f8e67d3344c9dff651e1a2798f7dd1b0e99e7cbc11f5e44ec98f6880cf443c b57a7be6b38c613f08919ebe694196097ee2bea41e01401fbcb98a3904362926
1211500 d899dbddf39d3b7ffb4f7fe28de5acb406d425ca8e045d3f781add82186f937a d3e071c935166ebd9ce6c5eb2c0ef7830b6774887cca37a5f1d36a2b256a05a2 c6a78f9b427a055d4a667cb08a74bdb1ab24077de9e7992c570e96c0af7daa4f
1212000 f90c9ee5bc12c59ec108657fe98e9324f9c85aa1f9cab7204edf6730d70422c3 0150577230ba870ebb96c21f7e3ec7ae1dff39cb722ed7b48cbc60d330be744a 088ff4328e9147a7563fa07206b6171840b291d53785164da29e62623b1feeba
1212000 f90c9ee5bc12c59ec108657fe98e9324f9c85aa1f9cab7204edf6730d70422c3 76812de9f7d63b6412f310ea3814b3a4aa29e4d79b85b9d5c01f3336a0a8d75d 088ff4328e9147a7563fa07206b6171840b291d53785164da29e62623b1feeba
1212500 f8cc7adcb309ff208a7a740eceb0517c8d3b3a88c06ce005b37f17ffeb4905f2 ca2fd2e44948441520e2e9bd79528e0bfb8077ce313cea0190b229e2a8977d5b de0c8389fbf4d54b78748152d6a1b909a032a7292dcb52068fc18014d973a5ce
1213000 754d66c3a3828b61aa7e5a15c8fe95981fcc17ade1030484f91c11c8610afa8d 0a736f7cbc44dea49246af39c1db3b9f98a482f3263278ccd9d7e2c42427badd 7dfaff65e0b6b9ee50eaa81d8a30304d9f258f0da1966d390cf169bdd9cee31b
1213500 a44133bc1878ee0a11110db3b1e216a32e3c1dd7871242184906e37707c4c3a4 9a49bc0837e480d6feb51cdb641412c1fbf83ebd07aedf5f5b52bcadb0262efb 41d16e41364828cf2cb397e50f0536c53f9a165f51dbac05ff80eaf2ed63f6a7
@ -2432,8 +2432,8 @@
1215000 aa91d090e9109a62f7bf56969cffff445b7458ba7a5d37d333ac0f6ecf33bee7 fce092c00141d26053f0cc948b1c9e6909798b2e48a5d6c2a2234455e1260ab7 1f39cd37ed092c6703ec9a4d52d68f4193f0c09277b8a60b4bbf7e0ce0a502de
1215500 4a3cba5107b521f2fec4838c56ba42075bea7b56111407c3e1a5d29f268e39c5 d148409fb60d5fda12f14be6d10aee9d40193b64d09c2990c3cb5a457ef18cf9 bf15c48150f64d7002923b94b5cacf0ba7ebd9ec8d5e47aad52fab003e70506a
1216000 2a224b00ee3a56ee499bba718b11b688f789d44a11c42b566464204f51f2ec33 0769fbba3f55367e95375dfefa08dcab6f53c9c5e5609a0422f73d75f04a4f53 40d9e49dd70d4f1aebce07bf99ed706b3adaa207d2eab29c843e7bca0e69f9e7
1216500 d9943902065c4b0823cd64a62d37b532c6d62d0ed1d8828927ac39089207b9ae c83f557b4e2cc04d4375f91003054dbca728cbd9626fa9e9420ecc77aeb70e6f 32fe72cc551ce71177df0895e2f384649fa4f137e4d6f7b6c93eec53d2eee53d
1217000 382d47307ca74e43ab3cf0152c65cdf01ea2348b1ea1b25113e6b5fdda458a34 835103782e04e0e8bd18c741ecd1a8238eee814973ab7ad40eebe58e2fffc100 5f1d7ac4471b7dbf2927f5a3dc7212cc025e8deb674f87559ae7bb80c81ba2c4
1216500 d9943902065c4b0823cd64a62d37b532c6d62d0ed1d8828927ac39089207b9ae a5acc122a9f9a8969f84685d22e76d090f5c4ea7bac3fbdeb32d56535570ed7b 32fe72cc551ce71177df0895e2f384649fa4f137e4d6f7b6c93eec53d2eee53d
1217000 382d47307ca74e43ab3cf0152c65cdf01ea2348b1ea1b25113e6b5fdda458a34 38b01c4fd857554451c9e4f7481ef4dc491e230779bb1efa92f7fc6ce58955d8 5f1d7ac4471b7dbf2927f5a3dc7212cc025e8deb674f87559ae7bb80c81ba2c4
1217500 2e165b64031b2e689a8e6cf9b24f4a928d7f9de6777ce918aaaf99991562c603 84f608ddd07f0e6c7307570ad6ec5bb0b7361c779d1c18e8cb0c9e08a29cee0c 0ea9e4d3b33c19fbda78146bc486343b4717edf67573392742a697bbf34778ed
1218000 c62fb3c42177536ab92a97c2d8fc21f72ca1499aca8bc9b604d8265cd8630771 375f71108b5160a7a7990288ef3394cdcfcfcf77955f21f28368d101ba93eb66 b51ab010fef2ea591827977f896d80a4dd63cf94bded139805169c581849068f
1218500 a162e27d52028d27ace91149cd6526e41f6ac23e67378f81f51836f7326fed9d 28c6848464f675c93a357833cbd7af6fe0d1881723c9b1dfa731a7ee2c08536f 898dea8a454aa96a0931532a0eb7e181de7f83359f7433c520e4693b5fdf4948
@ -2444,15 +2444,15 @@
1221000 fada98b054fa44944ae7f458255ac03af0bbef0f4711e0fea4dcb3071f4af719 ff619e93f10311744a6bad4ce2add55afb6c258beb2570d825489a6901c493b4 b6ff3aa01bcdbc9e4206838490e78dc4ac9ed06171dcdbbaf7807211fb3047bf
1221500 867936e9456a796ae62e181d029e150d63ed8d7fa0b91dc96f0610101e96bb07 f283a4dd8854af5b6419c79ce98c6326283ef8b8f3295d8912c5465cb99c9b7a af190d37c2900db674adacdc741c59fbd8431bd71cc6cb70cf420f616964b083
1222000 92d956413724e3e5fc5e7386ec1f9717fb6f080203d7cd464cbc1cc46e40b1a1 d2212c160766ac9464f0f3b7433614303114af00a95d746177ce70af39b97fdf ac8bf70a3e63d097dcc407247331b10d4fe125d9b53358079b3e0ee7900af8b8
1222500 988b9749da4643c17df869d68c4c6afc39c6427bc79eea82a2c2d23262319003 b2e29bbb854e916e259c68907d86603bea9f63c174cca8483cd6a806e0687cc1 016cda454ed0574524c3ec1cc40c5aac64f90ab0cb7599669ad04793021a48af
1223000 ba1cfd983bae07bb33f094aa313ad4e27773ab1316291ed338ec784638a17fa0 6a6e92ab4ba2174d2fa9ea9d518f1dba0d7b4b02b6f208cdcb191cc8d9743ff6 56a23b35c73f1a6a2f63530304cf2b4a7b314d8c44911337c7529a3bb72c2999
1222500 988b9749da4643c17df869d68c4c6afc39c6427bc79eea82a2c2d23262319003 63383c371f1f25f45ec916233c94344c0030962306379ea8d9c90c925b3d7daa 016cda454ed0574524c3ec1cc40c5aac64f90ab0cb7599669ad04793021a48af
1223000 ba1cfd983bae07bb33f094aa313ad4e27773ab1316291ed338ec784638a17fa0 e65128c850a743e68dcd65aaefb16e71eae209d940250b98e390e32d6d96a281 56a23b35c73f1a6a2f63530304cf2b4a7b314d8c44911337c7529a3bb72c2999
1223500 c9d4b54460eebaebe3dac55af5a41c92b93f2cbce7dc15a6a83d0ce32624da27 a7dc5399fff2ecf6f31036f2859a8fd6dd455cba0f36cb066198d196366a07e0 38742e5537cbdede5af65f69ba51e038fd50a4861daf98eefdf2547f92d30091
1224000 9eced849f18584d868e2b2203d7c8e670ec4b3de64040d4a83107bd4f83478ac b7833aa659aced32c8af2cede17974e2034248b77e1d8234e353f25aa2ac0f58 e61b4c8274aaa6954ffa72836f4b6f2a765bf42dc4480dd60321addfaefda699
1224500 e8efa9a9da8c7457cefe2c10edbe2ea4b9d41b1db527fedbda3cd04321a5c111 e957aee3ef528beac7121c3104a2a43fa436c729322b813de1d67312680d4083 bb24fb54ae90008799f9aca682ab21eac31ae86d517e2d332c7a9ea814a61730
1225000 4e12cd3ab7e05f9e285315c668939da5701bf4fb82d36d6d3e594de1cd0900c5 eb57dc646237d51bd9a1a2f8cb8c7f9d886f4f2cecf5d357a84ed677a2f261d2 1d313c9945672934be9457c33f639259391e674f70a03af4dcaa90adaedeff33
1225500 c688db4d88ed9d2df5c2f27c6835603c51901d117b6d1b84e758ed295fa48944 9a8422e25e95aff28f97a49c8c92b710d2444263b8d2da7a0808d175c0ee4347 c11b772a420b555ac5e6b924ad5c423f163ebffb82dae741a238d989b634e52f
1226000 c4e1d256b6489e0bfba212ee15761336138eecf8979b7723efa734ee1ff26b18 1e448b947cbdefc052935c120b1f5c6ea572b9b6e57db325ef6854f6d3163c43 a7577442c1b52b71f18ec372828203737f4135d9860b9b1cd4c37817e8a241d0
1226500 97c6e37ce3aaede301449d315b6121ad209d7c05bf1e1009e28ca4c9d9103c60 9210e0c390ee24dbac3246141271a88596a901e27e827c8ea57e3a5c7a75e4a2 6eaf28adcb51c7a25e69644a00d3aa5cfadb46b5561f47befd9dd8f469dd0373
1226500 97c6e37ce3aaede301449d315b6121ad209d7c05bf1e1009e28ca4c9d9103c60 bc898655ff32b905aa999fd3341f0ca399cdf4aa3997be7d83f3d4dc6e4dafda 6eaf28adcb51c7a25e69644a00d3aa5cfadb46b5561f47befd9dd8f469dd0373
1227000 329572ad3b9215cd69211538c61554eccfdad3bb5d2580d7319bd4e610a178b5 f2ac70bcea88b98c36bcdd15d050ea30f4ab11690e125ea3b9edb317a05312ba c55ee0f1638c5e7164ce7f58f5a39b36fbd7800576af58591468dd72848e4e9f
1227500 a116bdc25d0d36cec3fd5feeeb19ecd338d3c9db329114bf9a97e30f08bb96e6 2d1c9941a6d1fcb265b5ce131b77f4f24b3c41005531012ed24a89a271ad25fa 2589707edbce375faa11ccad06df92ddde9e531d1ef0a3633d78151b3f9d0f0a
1228000 84f4f33c057c0e992a875e7a96f06bf7c348e70730dae4d4c92ade46c2a7e116 049ed2ddedf886363d6fd427bf42206e294ccc455ff2f83fec7c10f74cb38a5c 4970249edfa5de8eb69588783f9ec8d9b20467efb4f4924d17894fb2ff3dfdbe
@ -2461,20 +2461,20 @@
1229500 e2eee37aa2938c02f852b9ea2bf88737f87203154bfa499db7577fd97c1cbd81 ed8ec1aa4e346b93d4f5a9016a5582df83cda6d59f71c910a778dbd8087039f6 a4dca6bda7027ce0c275b175ad2a725c65ddd4cc03f997deecac29824b1bbe19
1230000 6f65311001ece9092002e408d232b04a3958a801ce14745bbb33bc50b3d3e434 e92c307817b8555133defa5001453f674d64975f118469dac59022b47b1b2875 ef025f195d124354b0987f05b7d46a547e19cbff077dd162bd1d4cc4ebc51f2a
1230500 756a4e8628e68dd8833f1160a9438b5082b81dc62d57e2fea4c7f2ad73d4d361 3f201a9f0e46b64d4ee464133e142ec08efda7d70035e2bc87a9115578f01ca9 00419dbbd698d08b0f89b4669237468bc366a853ef0bfeb9074c29d1ed4b4f73
1231000 c8e6f0e59ddf904a7b2d085ca6cd5b1f243b75ac09ad637ba72a91125d6211d8 2c3762cb6d023147d669b4ca877aff07b7194d6da09215863f4fe199f67198c6 9bf01e88b22df0e00bff6bda68ab7087e573c3155dd093d7461f14288455ff04
1231500 61ef9b1c57fb9764e6bf4805a520b4fb74566e1fbb4eee699f517f62e22e64b1 acc8c1c0739411ca10405ccb0c49b403967cade11fdbf8811a8ebab9e46a6e27 2d9742b07b1a54cd422958e68b59b0cd5db43a876a5063427f138386d4a7fe2d
1231000 c8e6f0e59ddf904a7b2d085ca6cd5b1f243b75ac09ad637ba72a91125d6211d8 9643bff43c642fcf08b6cfe1b08065042e7d4ff70154aa883503257d1414470e 9bf01e88b22df0e00bff6bda68ab7087e573c3155dd093d7461f14288455ff04
1231500 61ef9b1c57fb9764e6bf4805a520b4fb74566e1fbb4eee699f517f62e22e64b1 b2df081747be0041571a8cdb62144a08408fb8911d5967717afd3117fbd5f05f 2d9742b07b1a54cd422958e68b59b0cd5db43a876a5063427f138386d4a7fe2d
1232000 391308af085a5484df59509f31a00f63833180fc69dace72a38461c8e51c0a86 f98e065e8818fd81b6b3f0a8da64ab17013dc010096e6c34ec3eb5f9fe8a3724 fa28fd3a2fc93ccc283fe42d924fc7492ec45cffec7d3eef82ea249e8a1aa855
1232500 3f8da017a3767553a874c1f2f5596700b6eebde54b1f27a119de031e94a5d70a d00e3a3b2a29c5f0f0ba83c5066cd3b0f4794a98768be0c7326fb82b17679185 994cace05d26e4ad89d275f8f45e9aa058fdccbe54d0fbbad58d87df2059089f
1233000 248b1955a1c0cf58366a949e73cd07abc509709e30a427a55e2edfff5d8c8677 88110fccf2c71332b30536569a6fc46fe183d3a2847ee627213ef66bbf0bcdd8 ccc0873dcdf1b09702ed7b3e6ffb8d00e9afa59d77e4f7f86ae0566879565b18
1233500 381e2949e83693efbb0e432f83034aa5ef6cd569428a3f5dc0ea46721d58a571 3e7cd9eb6c797ee4f40837dc8a437b417036a2ee6f6d8d0eb8cdb9d0143bbe51 c2a8f947967184ebb6a31b47961bd4f37252e5ae81380562dcc6165a85fc9a49
1233500 381e2949e83693efbb0e432f83034aa5ef6cd569428a3f5dc0ea46721d58a571 5e4fc7b3c7d55d2f0f236af9b89acc1edaf638427adbaf959d72297623ba683c c2a8f947967184ebb6a31b47961bd4f37252e5ae81380562dcc6165a85fc9a49
1234000 cb6e218e6b06db72e9ebd1a779c6fbda5c8967d527731d8e5ab48676aa9a1d97 27d02fde617293d42a4de35098f148deefd85340bb2b038a2ba17602eb26fa41 db87890c8ffa7bbf7c093729078598d598ad11b73a393bae34836641a393ba5b
1234500 5b0df15f60febb52c49aba4936bf83f9bdd2654d4ff883ae326c081fa7b3fa8c 802c5a78bd41f37f08ed7c395023a4661d743d59f98c6b7afeb231716fad6829 3b035a4d24d0cbdf71c38dfd81423d32d8cbfcea642da34d64aed0855044824d
1235000 48f8a254d98836c4d8559df0ff42f13c8b62ea04052381bf411cf47b99900884 d59adf1c51d0d1f8b261320e990593686f75c1f8f2f405758179b058946873a2 d83461b796e705769281bb9e53d7b7c951f9073a399cde0c567aa9916456a534
1235500 eb8ac12b006d0cfc692173d0a970260435c7c7ac1e67bc54807345a13f7557fe 1e716e5508018cddde941f3079be2608509a9e319684ef8144245f613ff46713 6db77cbcf3e70b684552735f0ba034057ca13ad7cfcb8d698eb9e4f5a188060c
1236000 524ce04d135aa08543baa6052549f6736395eda2ab3b5d8fe5fab430c014562a f1ad0c14cb9cdea0f4cd5847d1c256cae712d24621a29afec0f54677c1510706 d2371119849dec5a03d380b18a65b43981676db7a59ab13f989991317cc0ec12
1236500 88275a75fc986491ce9dd6d2cb83243060e61d6c4e81ebe7e7c7643fb8bab0f1 2a73a779cade5defd59863657468f9985adabf08572a23192060672b14e2de75 4e2f3e795940126c02e8a0479561df998e82ae5ac4839f07f28d130e9a32adbf
1235500 eb8ac12b006d0cfc692173d0a970260435c7c7ac1e67bc54807345a13f7557fe 43c9ff4e1ead86165b6f3976cf5904e5af8fe53cc313c11cfcea03714d3fbe6a 6db77cbcf3e70b684552735f0ba034057ca13ad7cfcb8d698eb9e4f5a188060c
1236000 524ce04d135aa08543baa6052549f6736395eda2ab3b5d8fe5fab430c014562a 6a0498d4a62c53e08fa49b0749b75848bf0ba3d3cfa9b6d11b082e56e8d1d605 d2371119849dec5a03d380b18a65b43981676db7a59ab13f989991317cc0ec12
1236500 88275a75fc986491ce9dd6d2cb83243060e61d6c4e81ebe7e7c7643fb8bab0f1 eb0fa72267b5a91ab4b257bb7d2913630e230bf9fca0bc7a207cb716c518e44c 4e2f3e795940126c02e8a0479561df998e82ae5ac4839f07f28d130e9a32adbf
1237000 4b99f3d475c781dc2caac67ffab7c53d84dbeff79678922694955a9854590018 554600aac19287681afe0e9765da07a02f1a1aa493dfd43addd9f31edb78e875 e60302e3377c7fc2b9109912f015bbe23b4b2ac8ad628c7d6e3837ac71f7b1a5
1237500 73c09a49ed9f47f700d4554cd0a94c1b01b802a3cb3c61946c74d40a443540ff 1775952f2d8dc63bcc08ea478fd4714838a31f7f683a8b83d5d26435b8b3b6c3 59f24ceb689173661dfaa9bf80b396831d5e7dcde15bf806ed7160f75a988274
1237500 73c09a49ed9f47f700d4554cd0a94c1b01b802a3cb3c61946c74d40a443540ff e1ad250e45509a15694363cf3dcf684d69ec8ce27538720f20171d4a02400b50 59f24ceb689173661dfaa9bf80b396831d5e7dcde15bf806ed7160f75a988274
1238000 29489c531b3419cea99dddefb9b19111f5baa184f287ebddb3e760a2663014d1 dce39dcb5a1a2d072fc999d3f662bcfb16685cb8922386cccba187b68b6d5947 32dcdcfc9c0d815a79435b769a35954dc71df347a2ac1a810929f765c39218bc
1238500 c0555685b80e5d5d0f53434a8ae44eadc953dced274ceadc80de36c44078283f 16dbb1b2bbd5d13aee22743ed27c7dc4dbf1dbb221cb45325d188889d6101dd8 c44cb9916bdb7e6c7dfa417da3be72bd5987cf345024ebfa68402bf3f3994189
1239000 a3f94a2821165fb910806ff75928c5255a4358b5062288571e00e6646abc5203 175a8f872f777325f2444b94ccd55602b3bd8204733f86af40713fb0a0474106 c637a21fdda667d21d172bdeedd54fe7f09095a015229dc6854eb37d917da596
@ -2502,4 +2502,75 @@
1250000 ff909ef870867e5408ec24ec40a290802f79bea220c8f4a92db22965fcd4f626 03e5b1fcdc2862ced4fbac3aaa81d1e0085c14d6f6d06c6ae592f74afaa16f34 c4f52d30fd52f73e6c5a8e27d3727b17887edddc5400dfb9ca1cce4703e3809a
1250500 8f0c2debaa498a5f78b8b247d1867ef6ade586bdfa823596d09f72abb489a91c ebbc2c14544a97d0bd12993dde913e52f2ef78450c1ce0fa2ca17274b6850836 de78b1c377adec4d78d5e4875569e052cc1d4eb959149a28783d3a14e05a365e
1251000 e484a8dae7eb5135538bf13009824a60f2e01446f7eccd39d7b6ba4ab7c02f6e 832e2c77cc85a51df16361177033632ca54768944daf778522cfec04a1968805 9d3db1d547f74210714713bf27f88dded8e2ac50a618afe41220ac606fecbf7a
1251500 d39df71c033cc3435949073db5f0dfdcc0665a7cb4f948704c30a36198d4354f
1251500 d39df71c033cc3435949073db5f0dfdcc0665a7cb4f948704c30a36198d4354f 6a635908c166d3caf33af6623f5653dd7a3a4139a0db2395634326fecd5db79c d63c2672584eea742c19e89c2e355a1102051a4494c76ce8be9590813d2f9fd5
1252000 ff536638f8d7f8cce1ac36b65a6f64dd4223d06a8969d6f6f64febd4d8f4befb 187604f03a82305b18747acd7c90d12648f5a37f045e326b657afaf4224f9d98 25ec47454fde992b5ac1e02e2c9d34c3d825946b9dc7e0a5c2ea71f96ff0499d
1252500 7658e586ed7df96fc8e00fea09f92a693a09c7d335c5a55454f3ce2339536225 2d0b4cab008310e0a67f36158c504ae840169b751a852aaffdb1c1672ad17bb3 81bdeb301eb2e6f4e06affd7c5bcb3f22918ed9d11c310b634f77d738b83ef79
1253000 bfe9a15bfaae2127653f9a072b7a3a9ee018c11077a7d7526bb10560c2cbb53c fe37841e2be751fd9648b697d20d7b5c3443a3ab39c2f913bab716e6bc91ab5f df64f68f75427ee2003331955ee1a0827b3b344445f577aded9614b48c8ab5a5
1253500 54621a5564053c3d3c3453d26ef0135bc1fdbb4b09021c5c33b7d85768e0bf31 e534ee517a9e71318bc9aaa5027b2957b6259efa66fd42096f8d6372567b876c 83a7dab72690b7fd940713f271903f7bac10f3bf077b0e6dcef9701e56f47ab1
1254000 e6d1922c5d41fe5427db84660db3f4182c69ef901ff569fe947118f2825501f7 7a1746032319ad8c92c7eacbf3a650d1f042d51c811eebf5a416b0b6dc249148 5525f731e53e110f43c70a42abf78f5166a800d8ef0821dff2b8e706f994b05a
1254500 fab487c24234505c8c8f7e1cf2dacba1a900a9d7811f9f59e43e1a7a18c64473 d8cbe61a2e9a9b2fa09620b37f62d9ace603e22072ab453da531f97df482137f a1f29b818a6c6a1be19dde40773903a794e6c2fbed8dc133e3f8106b4807a3dd
1255000 2b2763d4fed34ea05261387b94fcae12ce56b3769588f2f49bdbf05ae8cc64ae a827b0415a46a3b9a936352b43c32acf85b613f4d0cbf1d951fe1be18bbef819 f99426d0923bc2c972ac884261fe45c16610b8ab844e4db4c536a4b67b5748e8
1255500 da061eadf21c010d1390f8658a679293592c0ba5a5c66d4e5be8e10534304bec 59700e24b9b859bca6543abeb81bc64bcf219ae2787b92bdac617f57cacacfa3 151234c7997bc8682241978fb74052cb79bea8371f20055982e45b5fd62f3ff2
1256000 c58a7fe56facd3e1ead7304cbe4c0cd9c9855a5edbce2383ecc554f9ea8f2e46 d17fa10880ecdb2bec979b16b760f9aad490f6c985133dd26900f92d8a17a1ee 22c14c88a589109dea128ddcb4d27e650bdfdb75434d51a979b7e0fecc7173f9
1256500 e092fb1e2060e4bea4c6125245089220a7a6b48ad5c129a91d2d95e8fd34ca70 480fad310a88d8715313cc62c5724d786004e5b041daa8276c5d4948c4ba90f6 38e6b6dd573466bb4a147ccdf26a022ff750e3d0adb847b87b1eb54b074ba3f8
1257000 bf539bfb1eca8f36f36e5fb821bcf78e9c5890c9bc490541f3012952b8f86125 5d95c9140a50bc2cce9de1965f0a071f63f377a9dc5ea3e35886045824212ff9 d715e23670a3a4bc72654be1a716df874bbfa61f053b9c8fcf76dc7a989a6fe4
1257500 f44dd8dface0150c62c461b1ceadeb51ce2004caafbc4fef9f7e29175cec0442 8f59e207c888b79b3937e6d86cda3d271b755af290cd67b84623847ba8a4b1b4 f56de880992d59006c76fb6575599460a3cc7ed1e623528d4ffa5c1a58143a8d
1258000 cb6cce5ca0c669ef304d5e236eb8ca7bd5c340bcb33f469c8888595ead0037c1 4f014015e8549cf6ba7bcb1583f0dd758f456cf8dbad0d23067d61ac89746649 a7cb39492cbab14ea097c62c47a6301454d8d8673011cc23aaf9774aa6bbb97b
1258500 5fc18d3aa7a6ee374f73d3c2eab53dce9348015cefed3cce9c80577003312a14 bae86b9cff37f003d1483b5c13a6a1f7c8ae3d1e3df71f0706ba40abaa6866af fe16cc9840c10195bccbd7ab5279a61f58c4581e320d10f7a013fc17874bdaab
1259000 fa80a9bb10191b19d85e8719edb1fa72e47d3dce38fd3f46a19206c4a588fc39 d75ded4868c1cb6899e08ca1665febff4d2064ce9a0e2829f30d3ed1b0cdf3a7 17493055bfe1b927937afaa9695c2dbc309cea3fcec846134d02452403908fee
1259500 ee2e7f98e80b3a1ad13b83d1451fa0a2c14ec79b919457e399598c2b5ea4232d 670a0ffbc4369d6db1fc09ccb771fcd8a522cb2a4eafe45fc54a6d714e6ec4b8 4172cb25e40679f04e304ccbe391990fe8c499c742c161dd6b81fc13f7b7e0ff
1260000 b9f897897344dff04b69437c82d2e8ed7fb33138f1c986199abf2bf9dfb2e522 da2d970ab83aa94031ac3ea434a4eed07cc3f4c1b18805b290506980406592a8 06001c15b92d41a1731598f70f614c9526c0bfdbbcb652194c317b80b96ad8a5
1260500 e3cef70b0e598426ca78f8ec7bfc327f60604c26cc600d0bce48426fc2946016 3d7e42cb25d348b579bbc4442478b59a8546fba105b06acef26e4fcbc9d8377e 3a5d6f868759505e83290c567690d6d87f44fdb73afb64f191ce94e47e684e6f
1261000 9443d63a89847cffc74318c290e3f87138cc88036784c30b48793c2a5f6c9218 b1b83731e4c67fc8f472881f2b2bcbc29875c57fa0a130be65e7e33b7b8511ff 056aa8f7598212bce414a3a6a076ab722847c41169b640efc62477737a50b6ed
1261500 7babf7d11087d87c3683058eee9503e4ea41b91bdf3509a5132372ab7125178a 0fc234c5928abe54bb6b12aa3f033d380d2db44174d832f53260547e9c9e072d 97ca0cb26141b0cd7cea1383c2b7ee512c2bb4b8052ed1eea710a38e1ebb9409
1262000 67f9f917d49c6ba84183791ab7b56889b349dde7a1745001d011fa5827bfdbd2 65eb240a9878fe26fca01678bad9e92d24b572db7cda511f121226ae5f4bd065 5c439ea8b47d73906eca78e9392560614e1d15c16436bc562fa5d5cd12c92613
1262500 8a1cc98ca400fe611f7e620e8648602ce22d333a8159f22f2497e00c3722e9f8 1f5020780af98dbed16ede13f9904a89f3960a7c881afedec23a700ec9fa3463 be09717e36d77eb3e8cd38a61c86447319811fe5b2ddc41fe82c7ef1ee2096e1
1263000 55a8e34e3eeff1106fe3cdf12c1d44bf5de872477f5a8865c76996e36764f87e b2d872a076739d50f465345fe2799893e97eb15affd70741a7a3d3db6133e709 28f7e07c950049c73a85f1e67c37fba655bf8c511f9b000e5d472160c2e2a542
1263500 3e2ab5f78b443f66e459c642f93d98e2b95fce2d27c7a4d39020f79865cae4c1 a0365ca0ad690d08bb075c7a33057e091ecf0bec936f3558196245024f053519 f0a960b82c0283271c38bc0614f0cd10bd6bec28afc2cafadebd7309ff35b1cb
1264000 012540d25436c7713348010a3e444934425c28c53fb7c3a0986f73d2782561fa 004442787bc8f9e55c854913e2572913397baa9e06fedaacff5e0fd5b1253467 b6dfc77fda7bde9351d150c28b1dfd30ad08119b2e8ba4521f312e2a1663a4c7
1264500 bd8186b47cd23bbe3cdfb71e7347a0d2291ed697090d92d94681d168eb17bce5 a2627ddcc0b79311eb6c4fbb979883a57bee5ce66b27079ee9345dc564a97d74 555a546eacb99ffa4b4a0634739a5f55176d31fd194598a801b92ddce87327a1
1265000 dc6f4c1b94e3c7fd674f285bfccb376d816b7b9d25639442888c90417c6e1928 b8eac66eb748d10262da557855712118ef39ce59cabdb301c6bbba7dc85fb029 58803ea037bbdfcb26040bd14d176df795b2238b1a75f3819548b3890d5685ab
1265500 cc65848c358b799451503a3c57fd8618e27a1a1d1e9af32cbf33ae4f48d90a25 19b5b42b15691677fe764058e57fe87577aae10d89a3d293045383faaf22e76b 780a43c5a21945f6a95796eb3ae0b9ca82d07d90efb8196b848ca4e0999283e7
1266000 f69c6da50eb22f5946f080c1b73eb8f84d2770945deba271f9dde36047cc9643 3de5cf725b49edff7aef2ffa9ddd1e7b5664d8b338092b126baebf26d2af9787 c7768453c6cf0fb612236b79a19c9aeb8abbb967090bd8b2e0e031b2b5865dc5
1266500 8091893e7baa0a88b9300f71616afa17dc5b9b0a5eca5367b4a69baf985b1ac8 d02bbf77beb68fd0ae78d670aeca4ed42c4f60bf34be33c827a9cc7dac7b3122 340c352d09dc30eff28f85ae5d1fb18f14aac32055b06369ecc89019cee7cc0b
1267000 128f33161f9bc0e2c83fbee3cfb1c2fa50ccb383053d09306af0547ed9b68505 a66be448d6c66756535e0ef764429a9fac0478101d17e05289741801e2c2ee03 169041ca942e04e3aa28d626544f519adc2be4690c6aa08ab0928a5e5c67448f
1267500 31a9129736b2c3b254d11ca449fb0eaaffced86d9a48cdc39a884ca6b06f255f a4698e69577f70436ff7e0a35fb2585bc4fa1add1972bc891cddd2277ca20348 7438112570e3522daf7286af5aa53e8bf7ffe5c1625d3cce3b45f9fc579c89de
1268000 16c0c54660fabda9e221fdcd808b55d50276ce9d7d871ade48ec03fb00885f8f a6b879ad3a1e39b77530d98d41a6b4c7b9975e2edf28e1a8548625096429a863 a0ff752370334aea4a585bf357e49c7003c7143b08fe7bd6ebbf27bcf1efd3f6
1268500 785311a0eca2b874f5bb33c7a89dcd1f070687c83097a3d0e19fc321794b2973 16daaf3f6dd6f9297e476c1937f5a6b94a34f6c0f61e632a721589d41dcca399 725bb8b8ecde7acd94587f99aa26e0437aa2adae8708173139b7531893430803
1269000 27c720ef7d52372b85a5b9c00dcf65093d4f1e36f1eaf6d60396669475269188 ce3578d69e986a47bd79f4f6ea1af7faeed33b524968a2daf0c46cbe2d7ab897 68a147f7750ce84596b0a924b9d1be5e4d38bfa7b4db35bbd2ea5c4e0f2d0d80
1269500 ab31f7ec6924dba82608d0090da6cf1082847e4d0e45afb860c6438e4e192dd9 663524bb675195f8be51daaaed5719e708ae88417ef8ac17b17d8012d0790862 f899334618382fee4f71a82dde3f2b19efadffe200616de3add2a59233b86968
1270000 047cb08100d236280b31144337c8099e728ddd05f1d7f88ce1ac18f29171c276 5165759c24f5324535815114fb1a4624a80e727cf51a8423f656a332805e35f4 69bde7b7be62447e487a37a550002b1f5e65c936f1c619f816205c42c6f30c4b
1270500 e5476f3643be6062c57e6d106cec58735f5e9634240057116f69c51c48cdd7df cdf1c3a1616b92af6dee00860e080f993816d0853c8b566bcb9cf39fa9f841d2 b0379e835b76365f46d60033d0f38e4be68517375a8e20e38c4d893151ad47d9
1271000 bc9d66c3a41ec1563d87a039dc160a62fa03f140b64aa201fb0e0d85196936f6 6561056eea7e542a19122f3bbb7de349f81b7958a285673261fb1aa50d19fc45 2f71eef960e939f4e0bd002354aecd03aaa7e150db63f301825cf4634a2b3097
1271500 683fa8faac9cac93518e65747a4794bf851029955dc68f7d35013b15848bedc8 96877e23c45469226569a2c19534da7c3eacfe00fc446001c2e59032327314f7 45132f28d37713688fd6162da9da162967fdd8f127f9870b207d6a123252852e
1272000 039015360bb09f948495ff398aac0d7fad64c21647ba87172417ff5965daaa5a 9bf6c52d052bc7e8767cd0c3e82974b9e7ab395cfe420530667158f064083954 f35e325a482acc4b19cc370901c0137953bacb47bfa4350801e4c432e5df337a
1272500 10483769977f89699e290bdd63de97278c5402a84d7a6afc9da4300cbb2f5ad3 f52b3cce02c295ff33170712c0311f9a905208e33905a659475bb48c2232dd51 1b5847abd3c3fbe363cc8beb223fcad2d47e6edbdefea894fb8a6a466a608167
1273000 5abbe45e929f9799d10f24d845a2c2bdfe92eb4badc58cdcd80a67253db03046 89c39b33025754778ae61b21ed02f00269b7e8f95b0d84d5dba24315e78017f5 f2acf3d6432d8a064a16e614d2f295bbd7f0cbc6e276eaa8911fc6ac34e60fdd
1273500 6963355dc1a4f110d432f2ec4937c9a864c097eb8f4860d8e86e0145accd7a5e 747860bcd450d1a413130ef9c0d70e9c0457286e8a42fdf8bd4bec9acc4de6c9 c2b2b6e933d2712db73a3e2783752f2e6ebf7fdd8ca098a8b1fef45585601ce3
1274000 5f3e0cc50258520df89de7bff9b8f189e3bad9a3b56262f49eeb6c030e0c0d37 9e64e2b2c81cd3ae1678d99c25bb7d23dafe547e0fbebe7231055f2b23919d33 d2581fa580e0919d0deca17b8f5cc9b15fddd1238b6b2dfc1955bbbbfd69c429
1274500 da872f704465d6cc09095c465849ef587002034ad2eec621f711f59aa4f5442c 285c67087a1c1b81ce26a75dc784b3bfa44d1ed3917c2ab39523baf5551df4cd d177183bcab01307731283ea7a463ef5f6e8ef9abd3879965492a708faa94ce1
1275000 d31a4ddcafca32ed48e102811726ccf4dd0e70bf6e31ed1573e72533290338e2 7fd218c9b9c8859cd9740ff17f4405e793d900a087b44243a80141c9a4ab9f87 790cef1e25930ddc308b3af55d25c14c4165f51ee49d1ecb2c16a23965fdd22e
1275500 e8b9859c7fc85a2f449e7beb5b67c8a5a4ac9852743c258037c5b7d18c7e6775 7089285b9581c23e207655b5731972f426e3906536dd3c54fe6000bf69a47081 1a2db31610a7f4fa48368c08d23b8fde80c38c855eb2d2dcd84a850d6ffb8593
1276000 d0938a0f2049afec1c7cdf43b5d367c005e7f1110a86ea2ab4573088fe951893 b764de4aab5446cd85df183d57b0269d720d42e39d8427ac2fa05bc971b24f46 5593a08c66a43c78dd4995c96fb2e787c9cea457f558acb8ec2347b561f0913b
1276500 b318359130123cac42618d6daf142377a50f3955dd3c2eb6bca23ed122c95cd9 5a71e9ba231a41ae838e4e1edb15bdb0cce8c278a8ee4cf3fd0e87a5649e2e3b 1f5e5701670c35765199e23d0ecaea1c2cf7264db6d239b557b64554c414c440
1277000 30c579043d579fb723c282f54d7366e1ca7d926d2b0212da79a146f8d7eefcff 10cc0b462735bbf385786898251366abebde01aa9ff5c75747b96b5d5be5de74 d012018784a6ae276ab06f0b9cc48fb4a7b545acb42d38be0eb0f19ae976da9a
1277500 3bb84fa3412fd76df538a6ecc2764240cc5178700f333e18374d68ca55dbd8be b7e210f4d8a2fa776b541976e4ffe67b33ae77d2aa56fedd989e9a02c27f7e1d 698697a763f740bdc4f7cf1e3044c7a84cfb77cfcb25c2779f93dd00005cb8ed
1278000 48d9155ff3d4e83243191a29cfe0198827862b0848b7a9125237bb28480ba779 5cd0556aa6e4bb2f9de705d581341bb460cb3ff882223c0392ae02ee3fd88779 ac1a1cee86ec42d6dfef08e13f08e034bb5d273d810a5acb727548aca5a675c8
1278500 d10b8cff3e5e37a480c5eca736b4e4d1b707b2ed9d44ba4fe4da8ef17f94ec05 d52a09dd904985a347a4ee0957a1c10f92d11323b0f1e63c604d4263aa73bebb d7462919c815ced10749fb5484e6462ee3e763aaca0120748cd013242c80ac3b
1279000 65adc4b476e699248abbf1a79a032eaca65a62018c6fb410a3b081b50e2119f3 e5b4bdd0b64145f87a36aaecbd4adeddb304f3811c99249b41ccaa61aecdb63a 537297de7b81d984b28effe3aaad242c613dec3e33019d53499b94c33f621214
1279500 7477ca04f254d3dfc24b5d939bd9ffac2d82fc95df2de2102c979fc74c0ad11c f5b195948767156ed2dbca0911e56d96fd2154d6f00b24e6df7e60cebaefdc66 bacae9d41d64289ccf9bd44bd02f4313c9ba42edc23801fdc648d739b9dc534a
1280000 c1f9c7eae3832cfb9a173e2b3d127b318fd9c0ad4e7f7166cb02d45fa3ffb0cc 49296641f1fc718614a5a9fafc86fd9028b575022bada11f89a6b27706f8d3ea fd52322c2ee1d3621084caac172d0fc7a75e53869d75198e3efc2d869665f282
1280500 8d750e9deb9e57ce2a7a4e896594cdf8e1dea273a15e68919a2f3224dbf97d0f 5dec7ca354f5cd8959829830e6cea8b8618d364bf8e0552df0e68f2820ba7437 74f2a4ea67ac6383799aeb14eab12814e291bef087296461c65e5fc062a955fa
1281000 33f4f1b24dcb9f14a2e0e23709437d08d200fa37d9f3e876e038873c74134cd4 68179c760d4c48863244ce5fe6395f89cfd49a28853fd39cf3509149ad4ae1a1 81e405df4a3c3416b476ff1d1d4bee7fdb8bd957c773bf2d2cf7a1a6c4dc116b
1281500 3e5656fde2e644c01052ce8c0ac4825e1aeb02325de493366a345aae44c9b595 ea8a070d45f666477dbe9bf61b1e2bfa4abcb98484df696fddde5e3e9cc6b2b0 507b84013d2b60d24e96ef587f60fd6ae4e1068e1a712860cd0668b9e0c6d463
1282000 460dc5a8b00f670a71a6a810916e85394638898eec053c2c29f71f1b8106c260 1ec4300fc8c5b3ee0fa37da8175eea93aff328294f67ade579f5841d90b6de60 59aee7ec52f1f420543f0015e0a3f4751cb633ac20e01e0d8e9bc5d4acb55b15
1282500 53ca6a167b471af842c2bdbce872fbef28c0929645493f443f1ffa132b8ef74e 6f47f28baf258a131365e86ce4aea0a0ed6f8ff724effc39a6d6e9ecdd37469e 493917b99595fada5561f1fb2ec0efa7e24f2db194e42514d75b3a45d8a2636d
1283000 ef26b129d493fb802fe635d458049a2f111aef0e2ad1301d014d5ac852c8017c 010b034dafccba6d4ecb8cc6b00045a3a15f641c6a5435e67b34a58eee3031cd 4f44bae6dded24a72e8cf6346c3080bd050596c85d895daecc2223b8612253ed
1283500 909285e4f9c7027f23527957968bcdf63e1b808c978d8fa77aa31630749aad91 283247be02994f4f902ce749b431d94abaa8bee68190a98168efcaa7c07ce5fc 700a7723f0290335db92346681c67125133271e165bb1dd5371da9b66098fb75
1284000 076257928b85090d0ddb6990b1d407989bff6a40bd01fa44055aec204d93928c 92753e55543543c1be66988e74806a08dbaea8c54263dbfd80473db9ec8aea95 1eda23256e68c54b26322745da4f209c00ff2f146c34f148563002714f12b84c
1284500 5c21a60192ce74b58394dfe188e8b3bcf9cb86b8e71424f0a447b11d82fb7d2f 3a7cfaeb0ea7162993fc607af16989ba8d27f1b89b1f5a5be5312b87dbc35cdb 6a1ac2fdf33bf732648facc31e64ffa9c7415de9ae28e8c699ac41b93f29880d
1285000 23a194e22d5302e4f2feaa1d1b1906e91f8c7808075c55f0a8fc2f5ee6617df2 9b9849c2152e8f8467970090e2adf6a52e22a2abb255bfe8d3c9d17673555bc1 d59bf5def0f1ca0fb97dc1d368c3c5175b847a4c507630452a69dd38661dda89
1285500 47d91223c2513842f9833d26630079872e58b3c29ab1c2860704513ff817a017 4c4befed95e81a843b315466a3c459b61de781f68a4eb3e545a1168779f84fc2 1c4f2e61bde40eddbc29137cf4aefeca2b1445dbed4b642fa778dd481d70a7f9
1286000 d68322938435a8915aaa0a1755c5ef11294bac81d64a76bc576424b373079ae1 010ae35ee9093052277dcba8a3456effe7a0eccbe26a32a8e3dbe41df5b02409 72ef60d505eeeb89e538c243b860d03597bbd75e972e698f1a604d4523cc20c3
1286500 b68cca2dcb4aed574ecfd888f2d87711b3939b05ab5798c5671395b6b032a90d a4037221fe0b9fe5c4611d77d50c661d2efc4038d983e17c463236ca0412896b 23910f32c4f9ed70129db37cdcd238c217b255c806cacacf196e3524f8b37850
1287000 20df89c8172f75ebf33e232d4b3ad8b4e81039a413952c625b8e8d661ec3d0ff

1
iguana/confs/BTCD_peers.txt

@ -6,6 +6,7 @@
89.248.160.242
89.248.160.243
89.248.160.244
89.248.160.245
85.25.217.233
65.15.37.140
62.75.145.171

4293
iguana/confs/BTC_hdrs.txt

File diff suppressed because it is too large

17301
iguana/confs/DGB_peers.txt

File diff suppressed because it is too large

28
iguana/confs/GMC_peers.txt

@ -1,26 +1,8 @@
5.196.20.189
45.32.1.137
104.255.67.131
104.236.84.230
142.4.218.175
58.168.10.110
101.173.217.38
194.135.81.138
80.229.155.158
85.214.23.49
104.168.148.143
46.105.118.15
198.27.97.172
101.173.200.202
89.36.212.56
45.48.9.204
104.172.24.79
85.25.200.157
216.146.143.177
203.7.43.162
101.173.197.85
85.214.23.49
194.135.81.138
111.99.55.252
192.52.166.35
193.192.37.135
209.126.119.209
155.254.49.27
104.172.24.79
104.236.84.230
104.255.67.131

3
iguana/confs/KMD_peers.txt

@ -0,0 +1,3 @@
176.9.26.39
5.9.102.210
78.47.196.146

11
iguana/confs/SXC_peers.txt

@ -0,0 +1,11 @@
104.238.221.17:16814
148.163.102.28:16814
167.160.36.152:16814
192.227.158.136:16814
213.46.197.237:16814
87.204.149.94:16814
45.43.26.103:16814
172.110.18.177:16814
172.110.18.178:16814
185.116.238.204:16814
84.242.207.225:16814

3
iguana/confs/TAZ_peers.txt

@ -0,0 +1,3 @@
176.9.26.39
5.9.102.210
78.47.196.146

14
iguana/confs/UNO_peers.txt

@ -1,8 +1,8 @@
195.154.223.134
216.146.143.177
173.183.179.144
144.76.176.12
87.189.45.29
188.138.94.6
144.76.239.66
144.76.64.123
85.25.217.233
104.172.24.79
188.165.42.51
45.32.244.201
52.23.179.46
192.95.29.72
185.50.213.123

8
iguana/exchanges/bitcoin.c

@ -144,14 +144,6 @@ int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype)
return((int32_t)strlen(wifstr));
}
int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin)
{
// multiple coins
// ro -> vouts collision, purgeable
//
return(0);
}
#ifdef bitcoincancalulatebalances
uint64_t bitcoin_parseunspent(struct iguana_info *coin,struct bitcoin_unspent *unspent,double minconfirms,char *account,cJSON *item)
{

4
iguana/exchanges777.h

@ -83,10 +83,10 @@ struct exchange_info
struct instantdex_msghdr
{
struct acct777_sig sig __attribute__((packed));
struct acct777_sig sig; // __attribute__((packed))
char cmd[8];
uint8_t serialized[];
} __attribute__((packed));
}; // __attribute__((packed))
#define NXT_ASSETID ('N' + ((uint64_t)'X'<<8) + ((uint64_t)'T'<<16)) // 5527630
#define INSTANTDEX_ACCT "4383817337783094122"

6
iguana/genbtcloop8

@ -0,0 +1,6 @@
while true
do
../agents/iguana coins/genbtc8.json
sleep 3
done

235
iguana/iguana777.c

@ -27,8 +27,10 @@ struct iguana_info *iguana_coinfind(char *symbol)
struct iguana_info *coin=0; uint32_t symbolcrc; struct supernet_info *myinfo = SuperNET_MYINFO(0);
while ( myinfo->allcoins_being_added != 0 )
{
printf("wait for coinadd to complete, OK if rare\n");
sleep(1);
sleep(3);
if ( myinfo->allcoins_being_added != 0 )
printf("wait for coinadd to complete, OK if rare\n");
sleep(3);
}
symbolcrc = calc_crc32(0,symbol,(int32_t)strlen(symbol));
//portable_mutex_lock(&myinfo->allcoins_mutex);
@ -55,7 +57,7 @@ struct iguana_info *iguana_coinadd(char *symbol,char *name,cJSON *argjson,int32_
}
else
{
coin->chain = iguana_chainfind((char *)symbol,argjson,1);
coin->chain = iguana_chainfind(myinfo,(char *)symbol,argjson,1);
coin->peers = calloc(1,sizeof(*coin->peers));
for (j=0; j<IGUANA_MAXPEERS; j++)
{
@ -164,7 +166,7 @@ int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin
{
coin->peers->topmetrics[i] = sortbuf[i*2];
ind = (int32_t)sortbuf[i*2 +1];
coin->peers->ranked[i] = &coin->peers->active[ind];
coin->peers->ranked[i] = addr = &coin->peers->active[ind];
if ( sortbuf[i*2] > SMALLVAL && (double)i/n > .8 && (time(NULL) - addr->ready) > 77 )
slowest = coin->peers->ranked[i];
//printf("(%.5f %s) ",sortbuf[i*2],coin->peers->ranked[i]->ipaddr);
@ -241,7 +243,8 @@ uint32_t iguana_updatemetrics(struct supernet_info *myinfo,struct iguana_info *c
printf("new peers.txt %ld vs (%s) %ld (%s)\n",ftell(fp),fname,(long)OS_filesize(fname),GLOBAL_CONFSDIR);
fclose(fp);
OS_renamefile(fname,oldfname);
OS_copyfile(tmpfname,fname,1);
OS_renamefile(tmpfname,fname);
//OS_copyfile(tmpfname,fname,1);
} else fclose(fp);
}
else
@ -265,23 +268,37 @@ void iguana_emitQ(struct iguana_info *coin,struct iguana_bundle *bp)
queue_enqueue("emitQ",&emitQ,&ptr->DL,0);
}
void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit)
void iguana_bundleQ(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit)
{
struct iguana_helper *ptr;
if ( 0 && bp->queued == 0 && bp->emitfinish <= 1 && iguana_bundleready(coin,bp,0) == bp->n )
struct iguana_helper *ptr; struct iguana_bundle *tmp; int32_t i,n = 0;
if ( 0 && bp->queued == 0 && bp->emitfinish <= 1 && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
printf("bundle.[%d] is ready\n",bp->hdrsi);
bp->queued = (uint32_t)time(NULL);
ptr = mycalloc('q',1,sizeof(*ptr));
ptr->allocsize = sizeof(*ptr);
ptr->coin = coin;
ptr->bp = bp, ptr->hdrsi = bp->hdrsi;
ptr->type = 'B';
ptr->starttime = (uint32_t)time(NULL);
ptr->timelimit = timelimit;
coin->numbundlesQ++;
if ( 0 && bp->hdrsi > 170 )
printf("%s %p bundle.%d[%d] ht.%d emitfinish.%u\n",coin->symbol,bp,ptr->hdrsi,bp->n,bp->bundleheight,bp->emitfinish);
queue_enqueue("bundlesQ",&bundlesQ,&ptr->DL,0);
if ( bp->queued != 0 )
return;
for (i=n=0; i<coin->bundlescount; i++)
{
if ( (tmp= coin->bundles[i]) != 0 && tmp->queued != 0 )
n++;
}
if ( n < coin->MAXBUNDLES )
{
bp->queued = (uint32_t)time(NULL);
ptr = mycalloc('q',1,sizeof(*ptr));
ptr->allocsize = sizeof(*ptr);
ptr->coin = coin;
ptr->bp = bp, ptr->hdrsi = bp->hdrsi;
ptr->type = 'B';
ptr->starttime = (uint32_t)time(NULL);
ptr->timelimit = timelimit;
coin->numbundlesQ++;
// printf("%s.%d %p bundle.%d[%d] ht.%d emitfinish.%u\n",coin->symbol,n,bp,ptr->hdrsi,bp->n,bp->bundleheight,bp->emitfinish);
queue_enqueue("bundlesQ",&bundlesQ,&ptr->DL,0);
}
else
{
bp->queued = 0;
//printf("MAXBUNDLES.%d reached.%d\n",coin->MAXBUNDLES,n);
}
}
void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp)
@ -302,7 +319,7 @@ void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp)
}*/
}
int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete)
int32_t iguana_emitfinished(struct supernet_info *myinfo,struct iguana_info *coin,int32_t queueincomplete)
{
struct iguana_bundle *bp; int32_t i,n = 0;
for (i=0; i<coin->bundlescount-1; i++)
@ -312,7 +329,7 @@ int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete)
if ( bp->emitfinish > 1 )
n++;
else if ( bp->emitfinish == 0 && bp->queued == 0 )
iguana_bundleQ(coin,bp,1000);
iguana_bundleQ(myinfo,coin,bp,1000);
}
}
return(n);
@ -371,7 +388,7 @@ int32_t iguana_helperA(struct supernet_info *myinfo,struct iguana_info *coin,int
return(-1);
}
//printf("helperid.%d validate gen utxo.[%d] utxofinish.%u\n",helperid,bp->hdrsi,bp->utxofinish);
if ( strcmp("BTC",coin->symbol) == 0 || iguana_bundlevalidate(coin,bp,0) == bp->n ) //
if ( iguana_bundlevalidate(myinfo,coin,bp,0) == bp->n ) //
{
retval = 0;
if ( bp->utxofinish > 1 || (retval= iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,convertflag,0)) >= 0 )
@ -387,7 +404,7 @@ int32_t iguana_helperA(struct supernet_info *myinfo,struct iguana_info *coin,int
else
{
printf("error validating.[%d], restart iguana\n",bp->hdrsi);
exit(-1);
iguana_exit(myinfo,bp);
}
return(num);
}
@ -436,9 +453,9 @@ void iguana_update_balances(struct iguana_info *coin)
{
iguana_volatilespurge(coin,&bp->ramchain);
sprintf(fname,"%s/%s/accounts/debits.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
OS_removefile(fname,0);
OS_removefile(fname,0);
sprintf(fname,"%s/%s/accounts/lastspends.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
OS_removefile(fname,0);
OS_removefile(fname,0);
iguana_volatilesalloc(coin,&bp->ramchain,0);//i < hdrsi);
}
printf("accounts files purged\n");
@ -466,6 +483,15 @@ void iguana_update_balances(struct iguana_info *coin)
sleep(3);
}// else printf("skip flush when max.%d and orig.%d\n",max,coin->origbalanceswritten);
}
else
{
for (i=0; i<max; i++)
if ( (bp= coin->bundles[i]) != 0 && bp != coin->current )
{
iguana_volatilespurge(coin,&bp->ramchain);
iguana_volatilesmap(coin,&bp->ramchain);
}
}
}
int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t helperid,int32_t convertflag)
@ -476,8 +502,6 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
printf("skip utxogen as spendvectorsaved.%u\n",coin->spendvectorsaved);
return(0);
}
//if ( (incr= IGUANA_NUMHELPERS) > 8 )
// incr = 8;
incr = IGUANA_NUMHELPERS;
max = coin->bundlescount;
if ( coin->bundles[max-1] == coin->current || coin->bundles[max-1] == 0 || (coin->bundles[max-1] != 0 && coin->bundles[max-1]->emitfinish <= 1) )
@ -490,9 +514,30 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
}
while ( (n= iguana_utxofinished(coin)) < max )
{
printf("helperid.%d utxofinished.%d vs %d\n",helperid,n,max);
printf("helperid.%d %s utxofinished.%d vs %d\n",helperid,coin->symbol,n,max);
sleep(IGUANA_NUMHELPERS+3);
}
/*if ( helperid < incr )
{
for (hdrsi=helperid; hdrsi<max; hdrsi+=incr)
{
if ( (bp= coin->bundles[hdrsi]) == 0 )
{
printf("unexpected null bp for [%d]\n",hdrsi);
continue;
}
if ( iguana_bundlevalidate(myinfo,coin,bp,0) != bp->n )
{
printf("validate.[%d] error. refresh page or restart iguana and it should regenerate\n",bp->hdrsi);
iguana_exit(myinfo);
} // else printf("%s helperid.%d validated.[%d]\n",coin->symbol,helperid,hdrsi);
}
}
while ( iguana_validated(coin) < max || iguana_utxofinished(coin) < max )
{
printf("%s helperid.%d waiting for spendvectorsaved.%u v.%d u.%d b.%d vs max.%d\n",coin->symbol,helperid,coin->spendvectorsaved,iguana_validated(coin),iguana_utxofinished(coin),iguana_balancefinished(coin),max);
sleep(2*IGUANA_NUMHELPERS+3);
}*/
if ( helperid < incr )
{
for (hdrsi=helperid; hdrsi<max; hdrsi+=incr)
@ -505,9 +550,9 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
}
if ( helperid == 0 )
{
printf("start iguana_update_balances\n");
printf("%s start iguana_update_balances\n",coin->symbol);
iguana_update_balances(coin);
printf("iguana_update_balances completed\n");
printf("%s iguana_update_balances completed\n",coin->symbol);
if ( 1 )
{
for (i=0; i<max; i++)
@ -520,27 +565,6 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
}
while ( iguana_balancefinished(coin) < max || coin->balanceflush != 0 )
sleep(3);
if ( helperid < incr )
{
for (hdrsi=helperid; hdrsi<max; hdrsi+=incr)
{
if ( (bp= coin->bundles[hdrsi]) == 0 )
{
printf("unexpected null bp for [%d]\n",hdrsi);
continue;
}
if ( iguana_bundlevalidate(coin,bp,0) != bp->n )
{
printf("validate.[%d] error. refresh page or restart iguana and it should regenerate\n",bp->hdrsi);
exit(-1);
} // else printf("%s helperid.%d validated.[%d]\n",coin->symbol,helperid,hdrsi);
}
}
while ( iguana_validated(coin) < max || iguana_utxofinished(coin) < max )
{
printf("%s helperid.%d waiting for spendvectorsaved.%u v.%d u.%d b.%d vs max.%d\n",coin->symbol,helperid,coin->spendvectorsaved,iguana_validated(coin),iguana_utxofinished(coin),iguana_balancefinished(coin),max);
sleep(2*IGUANA_NUMHELPERS+3);
}
//printf("helper.%d check validates\n",helperid);
//incr = IGUANA_NUMHELPERS;
//incr = 1;
@ -555,7 +579,7 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
if ( iguana_utxoaddr_gen(myinfo,coin,(coin->bundlescount - 1) * coin->chain->bundlesize) == 0 )
{
printf("restart iguana: fatal error generating ledger file for %s\n",coin->symbol);
exit(1);
iguana_exit(myinfo,0);
}
}
}
@ -568,7 +592,7 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
return(num);
}
int32_t iguana_coin_mainiter(struct iguana_info *coin,int32_t *numpeersp)
int32_t iguana_coin_mainiter(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numpeersp,struct OS_memspace *mem,struct OS_memspace *memB)
{
int32_t n,j,isRT = 0; struct iguana_bundle *bp;
if ( coin->RTheight == 0 && coin->firstRTheight == 0 && coin->current != 0 && coin->active != 0 && coin->started != 0 )
@ -578,30 +602,36 @@ int32_t iguana_coin_mainiter(struct iguana_info *coin,int32_t *numpeersp)
*numpeersp += coin->peers->numranked;
if ( 0 && (rand() % 10) == 0 )
printf("%s main.%u vs %u, svs %u %d vs %d\n",coin->symbol,(uint32_t)time(NULL),coin->startutc+10,coin->spendvectorsaved ,coin->blocks.hwmchain.height/coin->chain->bundlesize,(coin->longestchain-coin->minconfirms)/coin->chain->bundlesize);
if ( time(NULL) > coin->startutc+60 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->chain->bundlesize)/coin->chain->bundlesize )
if ( time(NULL) > coin->startutc+60 )
{
//if ( (bp= coin->current) != 0 && bp->numsaved >= coin->chain->bundlesize && bp->startutxo == 0 )
// iguana_bundlefinalize(myinfo,coin,bp,mem,memB);
n = coin->bundlescount-1;
//printf("%s n.%d emitfinished.%d coin->spendvectorsaved %d\n",coin->symbol,n,iguana_emitfinished(coin,1),coin->spendvectorsaved);
if ( iguana_emitfinished(coin,1) >= n )
if ( coin->spendvectorsaved == 0 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->chain->bundlesize)/coin->chain->bundlesize )
{
if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 )
{
for (j=0; j<n; j++)
if ( coin->bundles[j] != 0 )
iguana_alloctxbits(coin,&coin->bundles[j]->ramchain);
sleep(3);
}
if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n )
{
coin->spendvectorsaved = 1;
//printf("update volatile data, need.%d vs utxo.%d balances.%d validated.%d\n",n,iguana_utxofinished(coin),iguana_balancefinished(coin),iguana_validated(coin));
}
else
//printf("%s n.%d emitfinished.%d coin->spendvectorsaved %d\n",coin->symbol,n,iguana_emitfinished(myinfo,coin,1),coin->spendvectorsaved);
if ( iguana_emitfinished(myinfo,coin,1) >= n )
{
coin->spendvectorsaved = (uint32_t)time(NULL);
//printf("already done UTXOGEN (%d %d) (%d %d)\n",iguana_utxofinished(coin),n,iguana_balancefinished(coin),n);
if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 )
{
for (j=0; j<n; j++)
if ( coin->bundles[j] != 0 )
iguana_alloctxbits(coin,&coin->bundles[j]->ramchain);
sleep(3);
}
if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n )
{
coin->spendvectorsaved = 1;
printf("update volatile data, need.%d vs utxo.%d balances.%d validated.%d\n",n,iguana_utxofinished(coin),iguana_balancefinished(coin),iguana_validated(coin));
}
else
{
iguana_update_balances(coin);
coin->spendvectorsaved = (uint32_t)time(NULL);
printf("already done UTXOGEN (%d %d %d) n.%d\n",iguana_utxofinished(coin),iguana_validated(coin),iguana_balancefinished(coin),n);
}
}
} //else printf("only emit.%d vs %d\n",iguana_emitfinished(coin),n);
}
}
if ( (bp= coin->current) != 0 && coin->stucktime != 0 && coin->isRT == 0 && coin->RTheight == 0 && (time(NULL) - coin->stucktime) > coin->MAXSTUCKTIME )
{
@ -667,13 +697,23 @@ void iguana_helper(void *arg)
//printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid);
for (j=helperid; j<coin->bundlescount-1; j+=IGUANA_NUMHELPERS)
if ( (bp= coin->bundles[j]) != 0 )
iguana_bundlevalidate(coin,bp,0);
iguana_bundlevalidate(myinfo,coin,bp,0);
coin->spendvalidated |= (1 << helperid);
//printf("DONE %s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid);
}
else
{
for (j=helperid; j<coin->bundlescount; j+=IGUANA_NUMHELPERS)
if ( (bp= coin->bundles[j]) != 0 && bp->startutxo == 0 && bp->numsaved >= coin->chain->bundlesize && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
{
//printf("finalize.[%d]\n",bp->hdrsi);
if ( iguana_bundlefinalize(myinfo,coin,bp,&MEM,MEMB) > 0 )
continue;
}
}
}
if ( helperid == 0 )
iguana_coin_mainiter(coin,&numpeers);
iguana_coin_mainiter(myinfo,coin,&numpeers,&MEM,MEMB);
}
//portable_mutex_unlock(&myinfo->allcoins_mutex);
n = queue_size(&bundlesQ);
@ -691,7 +731,7 @@ void iguana_helper(void *arg)
allcurrent = 0;
//printf("h.%d [%d] bundleQ size.%d lag.%ld\n",helperid,bp->hdrsi,queue_size(&bundlesQ),time(NULL) - bp->nexttime);
coin->numbundlesQ--;
if ( coin->started != 0 && (bp->nexttime == 0 || time(NULL) >= bp->nexttime) && coin->active != 0 )
if ( bp->startutxo == 0 && coin->started != 0 && time(NULL) > bp->nexttime && coin->active != 0 )
{
flag += iguana_bundleiters(myinfo,ptr->coin,&MEM,MEMB,bp,ptr->timelimit,IGUANA_DEFAULTLAG);
}
@ -699,7 +739,7 @@ void iguana_helper(void *arg)
{
//printf("skip.[%d] nexttime.%u lag.%ld coin->active.%d\n",bp->hdrsi,bp->nexttime,time(NULL)-bp->nexttime,coin->active);
allcurrent--;
iguana_bundleQ(coin,bp,1000);
iguana_bundleQ(myinfo,coin,bp,1000);
}
}
else //if ( coin->active != 0 )
@ -753,7 +793,7 @@ void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin)
void iguana_coinloop(void *arg)
{
struct supernet_info *myinfo; int32_t flag,i,n; bits256 zero; uint32_t now; struct iguana_info *coin,**coins = arg;
struct supernet_info *myinfo; int32_t flag,i,j,n; struct iguana_peer *addr; bits256 zero; uint32_t now; struct iguana_info *coin,**coins = arg;
myinfo = SuperNET_MYINFO(0);
n = (int32_t)(long)coins[0];
coins++;
@ -772,8 +812,7 @@ void iguana_coinloop(void *arg)
if ( coin->peers == 0 )
{
printf("FATAL lack of peers struct\n");
exit(-1);
iguana_launchpeer(coin,"127.0.0.1",1);
iguana_exit(myinfo,0);
}
if ( coin->virtualchain == 0 )
{
@ -804,13 +843,7 @@ void iguana_coinloop(void *arg)
if ( coin->MAXPEERS > IGUANA_MINPEERS )
coin->MAXPEERS = IGUANA_MINPEERS;
}
/*if ( coin->isRT != 0 && coin->current != 0 && coin->numverified >= coin->current->hdrsi )
{
//static int32_t saved;
//if ( saved++ == 0 )
// iguana_coinflush(coin,1);
}*/
if ( RELAYID >= 0 )
if ( RELAYID < 0 )
{
if ( coin->bindsock >= 0 )
{
@ -826,8 +859,25 @@ void iguana_coinloop(void *arg)
{
if ( coin->MAXPEERS > 1 && coin->peers->numranked < ((7*coin->MAXPEERS)>>3) && now > coin->lastpossible+10 )
{
if ( coin->peers->numranked > 0 && (now % 60) == 0 )
iguana_send_ping(myinfo,coin,coin->peers->ranked[rand() % coin->peers->numranked]);
if ( coin->peers != 0 )
{
for (j=0; j<IGUANA_MAXPEERS; j++)
{
i = rand() % IGUANA_MAXPEERS;
addr = &coin->peers->active[(i+j) % IGUANA_MAXPEERS];
if ( addr->usock >= 0 && addr->msgcounts.verack == 0 )
{
//printf("i.%d j.%d mainloop %s\n",i,j,addr->ipaddr);
iguana_send_version(coin,addr,coin->myservices);
break;
}
}
}
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
if ( coin->peers->numranked > 0 )
iguana_send_ping(myinfo,coin,coin->peers->ranked[rand() % coin->peers->numranked]);
}
coin->lastpossible = iguana_possible_peer(coin,0); // tries to connect to new peers
}
}
@ -912,7 +962,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
if ( (coin->MAXRECVCACHE= maxrecvcache) == 0 )
coin->MAXRECVCACHE = IGUANA_MAXRECVCACHE;
if ( (coin->MAXPENDINGREQUESTS= maxrequests) <= 0 )
coin->MAXPENDINGREQUESTS = (strcmp(symbol,"BTC") == 0) ? IGUANA_MAXPENDINGREQUESTS : IGUANA_PENDINGREQUESTS;
coin->MAXPENDINGREQUESTS = (strcmp(symbol,"BTC") == 0) ? IGUANA_BTCPENDINGREQUESTS : IGUANA_PENDINGREQUESTS;
if ( jobj(json,"prefetchlag") != 0 )
coin->PREFETCHLAG = jint(json,"prefetchlag");
else if ( strcmp("BTC",coin->symbol) == 0 )
@ -1100,3 +1150,8 @@ char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *dest
printf("busdata_sync.(%s)\n",jsonstr);
return(0);
}
// getnewaddress, setaccount, validate address, restart, validate address
// importprivkey, setaccount, validate, restart, validate

27
iguana/iguana777.h

@ -16,9 +16,19 @@
#ifndef iguana777_net_h
#define iguana777_net_h
#if defined(_WIN32) || defined(_WIN64)
#define WIN32
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && \
!defined(WIN32) && !defined(__SYMBIAN32__)
#define WIN32
#endif
#ifdef WIN32
#define __MINGW
#else
#ifndef __MINGW
#include <arpa/inet.h>
@ -41,11 +51,7 @@ struct exchange_info;
#include "../includes/iguana_defines.h"
#include "../includes/iguana_types.h"
#include "../includes/iguana_structs.h"
#include "../includes/iguana_funcs.h"
#include "../includes/iguana_globals.h"
#include "../basilisk/basilisk.h"
#include "../gecko/gecko.h"
struct supernet_address
{
@ -72,7 +78,7 @@ struct supernet_info
struct iguana_waccount *wallet;
struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts;
portable_mutex_t bu_mutex,allcoins_mutex,gecko_mutex,basilisk_mutex,DEX_mutex,DEX_reqmutex,DEX_swapmutex;
struct queueitem *DEX_quotes;
struct queueitem *DEX_quotes; cJSON *Cunspents,*Cspends;
struct basilisk_swap *swaps[256]; int32_t numswaps;
struct basilisk_message *messagetable; portable_mutex_t messagemutex; queue_t msgQ;
void *ctx;
@ -87,4 +93,15 @@ struct supernet_info
struct message_info msgids[8192];
};
#include "../includes/iguana_funcs.h"
#include "../includes/iguana_globals.h"
#include "../gecko/gecko.h"
#ifndef MAX
#define MAX(a,b) ((a) >= (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#endif

43
iguana/iguana_accept.c

@ -98,18 +98,21 @@ void iguana_acceptloop(void *args)
}
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
expand_ipbits(ipaddr,ipbits);
printf("incoming (%s:%u)\n",ipaddr,cli_addr.sin_port);
printf("incoming %s (%s:%u)\n",coin->symbol,ipaddr,cli_addr.sin_port);
for (i=flag=0; i<IGUANA_MAXPEERS; i++)
{
if ( coin->peers->active[i].ipbits == (uint32_t)ipbits && coin->peers->active[i].usock >= 0 )
addr = &coin->peers->active[i];
if ( addr->ipbits == (uint32_t)ipbits && addr->usock >= 0 )
{
printf("found existing peer.(%s) in slot[%d]\n",ipaddr,i);
close(coin->peers->active[i].usock);
coin->peers->active[i].dead = 0;
coin->peers->active[i].usock = sock;
coin->peers->active[i].A.port = cli_addr.sin_port;
coin->peers->active[i].ready = (uint32_t)time(NULL);
//printf("found existing %s peer.(%s) in slot[%d]\n",coin->symbol,ipaddr,i);
close(addr->usock);
addr->dead = 0;
addr->usock = sock;
addr->A.port = cli_addr.sin_port;
addr->ready = (uint32_t)time(NULL);
flag = 1;
iguana_send_version(coin,addr,coin->myservices);
//instantdex_peerhas_clear(coin,&coin->peers->active[i]);
//iguana_iAkill(coin,&coin->peers->active[i],0);
//sleep(1);
@ -118,7 +121,7 @@ void iguana_acceptloop(void *args)
}
if ( flag != 0 )
continue;
printf("NEWSOCK.%d for %x (%s)\n",sock,ipbits,ipaddr);
printf("%s NEWSOCK.%d for %x (%s)\n",coin->symbol,sock,ipbits,ipaddr);
/*if ( (uint32_t)ipbits == myinfo->myaddr.myipbits )
{
@ -135,7 +138,7 @@ void iguana_acceptloop(void *args)
}
else
{
printf("LAUNCH DEDICATED THREAD for %s:%u\n",ipaddr,cli_addr.sin_port);
printf("LAUNCH %s DEDICATED THREAD for %s:%u\n",coin->symbol,ipaddr,cli_addr.sin_port);
addr->usock = sock;
addr->dead = 0;
addr->A.port = cli_addr.sin_port;
@ -154,7 +157,7 @@ int32_t iguana_pendingaccept(struct iguana_info *coin)
if ( (addr= iguana_peerslot(coin,ptr->ipbits,0)) != 0 )
{
expand_ipbits(ipaddr,ptr->ipbits);
printf("iguana_pendingaccept LAUNCH DEDICATED THREAD for %s\n",ipaddr);
printf("iguana_pendingaccept %s LAUNCH DEDICATED THREAD for %s\n",coin->symbol,ipaddr);
addr->usock = ptr->sock;
strcpy(addr->symbol,coin->symbol);
iguana_launch(coin,"accept",iguana_dedicatedglue,addr,IGUANA_CONNTHREAD);
@ -198,7 +201,7 @@ int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_in
{
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
if ( (addr= msg->addr) != 0 && (len= iguana_peerblockrequest(coin,coin->blockspace,(int32_t)(coin->blockspacesize - sizeof(struct iguana_msghdr)),0,msg->hash2,0)) > 0 )
if ( (addr= msg->addr) != 0 && (len= iguana_peerblockrequest(myinfo,coin,coin->blockspace,(int32_t)(coin->blockspacesize - sizeof(struct iguana_msghdr)),0,msg->hash2,0)) > 0 )
{
//char str[65]; printf("msg Sendlen.%d block %s to %s\n",len,bits256_str(str,msg->hash2),addr->ipaddr);
iguana_queue_send(addr,0,coin->blockspace,"block",len);
@ -288,11 +291,11 @@ int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits2
return(len - sizeof(struct iguana_msghdr));
}
int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block)
int32_t iguana_headerget(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block)
{
bits256 checkhash2; struct iguana_msgblock msgB; int32_t len = 0;
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&msgB,block,1);
if ( (len= iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr)],&msgB,(int32_t)(maxsize-sizeof(struct iguana_msghdr)))) < 0 )
bits256 checkhash2; struct iguana_msgzblock zmsgB; int32_t len = 0;
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&zmsgB,(void *)block,1);
if ( (len= iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr)],&zmsgB,(int32_t)(maxsize-sizeof(struct iguana_msghdr)))) < 0 )
return(-1);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{
@ -305,8 +308,8 @@ int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t ma
int32_t iguana_peerhdrrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2)
{
int32_t len=0,i,flag=0,height,n,hdrsi,bundlei,bundlesize,firstvout,retval=-1; struct iguana_block *block; struct iguana_bundle *bp;
if ( coin->RTheight > 0 && (firstvout= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,hash2,0,coin->bundlescount-1,0)) != 0 )
int32_t len=0,i,flag=0,height,n,hdrsi,bundlei,bundlesize,retval=-1; struct iguana_block *block; struct iguana_bundle *bp; struct iguana_outpoint outpt;
if ( coin->RTheight > 0 && iguana_RTunspentindfind(myinfo,coin,&outpt,0,0,0,0,&height,hash2,0,coin->bundlescount-1,0) == 0 )
{
bundlesize = coin->chain->bundlesize;
hdrsi = (height / bundlesize);
@ -317,7 +320,7 @@ int32_t iguana_peerhdrrequest(struct supernet_info *myinfo,struct iguana_info *c
{
if ( (block= bp->blocks[i]) != 0 )
{
if ( (n= iguana_headerget(coin,&serialized[len],maxsize-len,block)) < 0 )
if ( (n= iguana_headerget(myinfo,coin,&serialized[len],maxsize-len,block)) < 0 )
{
printf("%s error getting header ht.%d\n",coin->symbol,block->height);
continue;
@ -350,7 +353,7 @@ int32_t iguana_peergetrequest(struct supernet_info *myinfo,struct iguana_info *c
break;
if ( flag == 0 )
{
if ( getblock != 0 && iguana_peerblockrequest(coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2,0) > 0 )
if ( getblock != 0 && iguana_peerblockrequest(myinfo,coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2,0) > 0 )
flag = 1;
else if ( getblock == 0 && iguana_peerhdrrequest(myinfo,coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2) > 0 )
flag = 1;

2
iguana/iguana_bitmap.c

@ -126,7 +126,7 @@ void gen_jpegfile(char *fname,int32_t quality,uint8_t *bitmap,int32_t width,int3
if ( (outfile= fopen(fname,"wb")) == NULL)
{
fprintf(stderr, "can't open %s\n", fname);
exit(1);
iguana_exit(0,0);
}
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = width; /* image width and height, in pixels */

156
iguana/iguana_blocks.c

@ -17,49 +17,74 @@
#define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0)
void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height) //uint32_t numtxids,uint32_t numunspents,uint32_t numspends,double PoW)
int32_t iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,struct iguana_msgzblock *zmsg,bits256 hash2,int32_t height) //uint32_t numtxids,uint32_t numunspents,uint32_t numspends,double PoW)
{
int32_t i;
memset(dest,0,sizeof(*dest));
dest->RO.version = msg->H.version;
dest->RO.prev_block = msg->H.prev_block;
dest->RO.merkle_root = msg->H.merkle_root;
dest->RO.timestamp = msg->H.timestamp;
dest->RO.bits = msg->H.bits;
dest->RO.txn_count = msg->txn_count;
dest->height = height;
dest->RO.hash2 = hash2;
int32_t i; struct iguana_block *dest = (void *)zdest; struct iguana_msgblock *msg = (void *)zmsg;
if ( zcash == 0 )
{
memset(dest,0,sizeof(*dest));
dest->RO.version = msg->H.version;
dest->RO.prev_block = msg->H.prev_block;
dest->RO.merkle_root = msg->H.merkle_root;
dest->RO.timestamp = msg->H.timestamp;
dest->RO.bits = msg->H.bits;
dest->RO.txn_count = msg->txn_count;
dest->height = height;
dest->RO.hash2 = hash2;
dest->RO.nonce = msg->H.nonce;
return(msg->txn_count);
}
else
{
dest->RO.allocsize = (int32_t)(sizeof(*dest) + sizeof(*dest->zRO));
dest->zRO[0].bignonce = msg->zH.bignonce;
zdest->RO.allocsize = (int32_t)sizeof(struct iguana_zblock);
zdest->RO.txn_count = zmsg->txn_count;
zdest->RO.hash2 = hash2;
zdest->height = height;
zdest->RO.version = zmsg->zH.version;
zdest->RO.prev_block = zmsg->zH.prev_block;
zdest->RO.merkle_root = zmsg->zH.merkle_root;
zdest->RO.timestamp = zmsg->zH.timestamp;
zdest->RO.bits = zmsg->zH.bits;
zdest->zRO.bignonce = zmsg->zH.bignonce;
if ( iguana_rwvarint32(0,zmsg->zH.var_numelements,&zdest->zRO.numelements) != sizeof(zmsg->zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d\n",zdest->zRO.numelements);
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
dest->zRO[0].solution[i] = msg->zH.solution[i];
zdest->zRO.solution[i] = zmsg->zH.solution[i];
return(zmsg->txn_count);
}
}
void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count)
void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgzblock *zmsg,struct iguana_zblock *zsrc,int32_t cleartxn_count)
{
int32_t i;
memset(msg,0,sizeof(*msg));
msg->H.version = src->RO.version;
msg->H.prev_block = src->RO.prev_block;
msg->H.merkle_root = src->RO.merkle_root;
msg->H.timestamp = src->RO.timestamp;
msg->H.bits = src->RO.bits;
if ( zcash == 0 )
msg->H.nonce = src->RO.nonce;
int32_t i; struct iguana_msgblock *msg = (void *)zmsg; struct iguana_block *src = (void *)zsrc;
if ( zcash != 0 )
{
memset(zmsg,0,sizeof(*zmsg));
zmsg->zH.version = zsrc->RO.version;
zmsg->zH.prev_block = zsrc->RO.prev_block;
zmsg->zH.merkle_root = zsrc->RO.merkle_root;
zmsg->zH.timestamp = zsrc->RO.timestamp;
zmsg->zH.bits = zsrc->RO.bits;
zmsg->zH.bignonce = zsrc->zRO.bignonce;
if ( iguana_rwvarint32(1,zmsg->zH.var_numelements,&zsrc->zRO.numelements) != sizeof(zmsg->zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d\n",zsrc->zRO.numelements);
for (i=0; i<zsrc->zRO.numelements; i++)
zmsg->zH.solution[i] = zsrc->zRO.solution[i];
if ( cleartxn_count == 0 )
zmsg->txn_count = zsrc->RO.txn_count;
}
else
{
msg->zH.bignonce = src->zRO[0].bignonce;
msg->zH.numelements = ZCASH_SOLUTION_ELEMENTS;
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
msg->zH.solution[i] = src->zRO[0].solution[i];
memset(msg,0,sizeof(*msg));
msg->H.version = src->RO.version;
msg->H.prev_block = src->RO.prev_block;
msg->H.merkle_root = src->RO.merkle_root;
msg->H.timestamp = src->RO.timestamp;
msg->H.bits = src->RO.bits;
msg->H.nonce = src->RO.nonce;
if ( cleartxn_count == 0 )
msg->txn_count = src->RO.txn_count;
}
if ( cleartxn_count == 0 )
msg->txn_count = src->RO.txn_count;
}
void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,struct iguana_block *block,struct iguana_block *origblock)
@ -102,9 +127,12 @@ void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,stru
printf("missing space for zcash block.%d origblock.%d\n",block->RO.allocsize,origblock->RO.allocsize);
else
{
block->zRO[0].bignonce = origblock->zRO[0].bignonce;
struct iguana_zblock *zblock = (void *)block;
struct iguana_zblock *origzblock = (void *)origblock;
zblock->zRO.bignonce = origzblock->zRO.bignonce;
zblock->zRO.numelements = origzblock->zRO.numelements;
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
block->zRO[0].solution[i] = origblock->zRO[0].solution[i];
zblock->zRO.solution[i] = origzblock->zRO.solution[i];
}
}
}
@ -150,7 +178,7 @@ void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct
if ( memcmp(block->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 )
{
printf("illegal blocklink mismatched hashes\n");
exit(-1);
iguana_exit(0,0);
return;
}
block->hh.prev = prev;
@ -298,7 +326,7 @@ int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *
int32_t iguana_blockROsize(uint8_t zcash)
{
return((int32_t)(sizeof(struct iguana_blockRO) + zcash*sizeof(struct iguana_msgblockhdr_zcash)));
return((int32_t)(sizeof(struct iguana_blockRO) + zcash*sizeof(struct iguana_msgzblockhdr)));
}
void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci)
@ -325,11 +353,17 @@ void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_blo
}
}
int32_t iguana_blockvalidate(struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag)
int32_t iguana_blockvalidate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag)
{
bits256 hash2; uint8_t serialized[sizeof(struct iguana_msgblock) + 4096];
if ( coin->chain->debug != 0 )
{
*validp = 1;
return(0);
}
*validp = 0;
iguana_serialize_block(coin->chain,&hash2,serialized,block);
if ( iguana_serialize_block(myinfo,coin->chain,&hash2,serialized,block) < 0 )
return(-1);
*validp = (memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0);
block->valid = *validp;
iguana_blocksizecheck("blockvalidate",coin->chain->zcash,block);
@ -377,7 +411,7 @@ void iguana_blockmerge(struct iguana_block *dest,struct iguana_prevdep *destlp,s
double PoW_from_compact(uint32_t nBits,uint8_t unitval) // NOT consensus safe, but most of the time will be correct
{
uint32_t nbytes,nbits,i,n; double PoW; uint64_t mult;
uint32_t nbytes,nbits; int32_t i,n; double PoW; uint64_t mult;
nbytes = (nBits >> 24) & 0xFF;
nbits = (8 * (nbytes - 3));
PoW = (nBits & 0xFFFFFF);
@ -386,7 +420,7 @@ double PoW_from_compact(uint32_t nBits,uint8_t unitval) // NOT consensus safe, b
printf("illegal nBits.%x unitval.%02x\n",nBits,unitval);
return(0.);
}
if ( (n= ((8 * (unitval-3)) - nbits)) != 0 ) // 0x1d00ffff is genesis nBits so we map that to 1.
if ( (n= ((8 * (unitval-3)) - nbits)) > 0 ) // 0x1d00ffff is genesis nBits so we map that to 1.
{
//printf("nbits.%d -> n.%d\n",nbits,n);
if ( n < 64 )
@ -396,7 +430,7 @@ double PoW_from_compact(uint32_t nBits,uint8_t unitval) // NOT consensus safe, b
for (i=0; i<n; i++)
PoW /= 2.;
}
}
} else PoW = 1.;
mult = 1;
while ( nbytes++ < unitval )
mult <<= 8;
@ -423,7 +457,7 @@ int32_t iguana_blockunmain(struct iguana_info *coin,struct iguana_block *block)
int32_t iguana_walkchain(struct iguana_info *coin,int32_t skipflag)
{
char str[65]; int32_t height,hdrsi,bundlei,n = 0; struct iguana_bundle *bp; struct iguana_block *block;
char str[65]; int32_t height,hdrsi,bundlei,n = 0; struct iguana_bundle *bp; struct iguana_block *block=0;
height = coin->blocks.hwmchain.height;
while ( 1 ) //(block= iguana_blockfind("main",coin,iguana_blockhash(coin,height))) != 0 )
{
@ -431,25 +465,25 @@ int32_t iguana_walkchain(struct iguana_info *coin,int32_t skipflag)
bundlei = (height % coin->chain->bundlesize);
if ( (bp= coin->bundles[hdrsi]) == 0 || (block= bp->blocks[bundlei]) == 0 )
{
printf("walk error [%d:%d] %p vs %p\n",hdrsi,bundlei,block,bp->blocks[bundlei]);
printf("%s walk error [%d:%d] %p vs %p\n",coin->symbol,hdrsi,bundlei,block,bp->blocks[bundlei]);
break;
}
else if ( block->height >= 0 && block->height != height )
printf("walkchain height mismatch %d vs %d\n",block->height,height);
printf("%s walkchain height mismatch %d vs %d\n",coin->symbol,block->height,height);
iguana_blocksizecheck("walkchain",coin->chain->zcash,block);
if ( bits256_nonz(iguana_blockhash(coin,height)) != 0 && bits256_cmp(iguana_blockhash(coin,height),block->RO.hash2) != 0 )
{
printf("walk error blockhash error at %d %s\n",height,bits256_str(str,iguana_blockhash(coin,height)));
printf("%s walk error blockhash error at %d %s\n",coin->symbol,height,bits256_str(str,iguana_blockhash(coin,height)));
break;
}
else if ( bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 )
{
printf("walk error [%d:%d] %s vs %s\n",hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str,block->RO.hash2));
printf("%s walk error [%d:%d] %s vs %s\n",coin->symbol,hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str,block->RO.hash2));
break;
}
else if ( block->hdrsi != hdrsi || block->bundlei != bundlei )
{
printf("walk error [%d:%d] vs [%d:%d]\n",hdrsi,bundlei,block->hdrsi,block->bundlei);
printf("%s walk error [%d:%d] vs [%d:%d]\n",coin->symbol,hdrsi,bundlei,block->hdrsi,block->bundlei);
break;
}
if ( height == 0 )
@ -494,7 +528,7 @@ struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight)
if ( prev != 0 && bits256_nonz(block->RO.prev_block) == 0 )
{
block->RO.prev_block = prev->RO.hash2;
printf("PATCH.[%d:%d] prev is null\n",bp->hdrsi,bundlei);
printf("%s PATCH.[%d:%d] prev is null\n",coin->symbol,bp->hdrsi,bundlei);
break;
}
bp->blocks[bundlei] = block;
@ -555,7 +589,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
{
//if ( memcmp(prev->RO.hash2.bytes,coin->blocks.hwmchain.RO.hash2.bytes,sizeof(bits256)) == 0 )
// prev->mainchain = 1;
if ( bits256_nonz(prev->RO.hash2) == 0 || (prev->valid == 0 && iguana_blockvalidate(coin,&valid,prev,0) < 0) )
if ( bits256_nonz(prev->RO.hash2) == 0 || (prev->valid == 0 && iguana_blockvalidate(myinfo,coin,&valid,prev,0) < 0) )
{
char str[65];
if ( 0 && bits256_nonz(prev->RO.hash2) != 0 )
@ -588,7 +622,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
return(0);
}
//char str[65]; printf("extend? %s.h%d: %.15f vs %.15f ht.%d vs %d\n",bits256_str(str,block->RO.hash2),height,block->PoW,coin->blocks.hwmchain.PoW,height,coin->blocks.hwmchain.height);
if ( iguana_blockvalidate(coin,&valid,newblock,0) < 0 || valid == 0 )
if ( iguana_blockvalidate(myinfo,coin,&valid,newblock,0) < 0 || valid == 0 )
return(0);
block->height = height;
block->valid = 1;
@ -619,7 +653,8 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
//iguana_walkchain(coin);
}
struct iguana_bundle *bp; int32_t hdrsi;
if ( (block->height % coin->chain->bundlesize) == 0 )
bundlei = (block->height % coin->chain->bundlesize);
if ( bundlei == 0 )
{
if ( (hdrsi= block->height/coin->chain->bundlesize) < coin->bundlescount )
{
@ -640,16 +675,19 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
{
if ( (bp= coin->bundles[block->height / coin->chain->bundlesize]) != 0 )
{
if ( memcmp(bp->hashes[block->height % coin->chain->bundlesize].bytes,block->RO.hash2.bytes,sizeof(bits256)) != 0 || block != bp->blocks[block->height % coin->chain->bundlesize] )
if ( memcmp(bp->hashes[bundlei].bytes,block->RO.hash2.bytes,sizeof(bits256)) != 0 || block != bp->blocks[bundlei] )
{
if ( bits256_nonz(bp->hashes[block->height % coin->chain->bundlesize]) != 0 )
if ( bits256_nonz(bp->hashes[bundlei]) != 0 )
{
if ( bp->blocks[block->height % coin->chain->bundlesize] == 0 && block != 0 )
bp->blocks[block->height % coin->chain->bundlesize] = block;
if ( bp->blocks[bundlei] == 0 && block != 0 )
bp->blocks[bundlei] = block;
else
{
char str[65],str2[65];
printf("ERROR: need to fix up bundle for height.%d (%p %p) (%s %s)\n",block->height,block,bp->blocks[block->height % coin->chain->bundlesize],bits256_str(str,block->RO.hash2),bits256_str(str2,bp->hashes[block->height % coin->chain->bundlesize]));
//char str[65],str2[65];
//printf("ERROR: need to fix up bundle for height.%d (%p %p) (%s %s)\n",block->height,block,bp->blocks[bundlei],bits256_str(str,block->RO.hash2),bits256_str(str2,bp->hashes[bundlei]));
bp->blocks[bundlei] = block;
bp->hashes[bundlei] = block->RO.hash2;
//if ( bp == coin->current && coin->RTheight > 0 )
// coin->RTdatabad = 1;
//iguana_bundleremove(coin,bp->hdrsi,0);
@ -657,10 +695,10 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
//getchar();
}
}
iguana_blockunmark(coin,block,bp,block->height % coin->chain->bundlesize,0);
iguana_bundlehash2add(coin,0,bp,block->height % coin->chain->bundlesize,block->RO.hash2);
iguana_blockunmark(coin,block,bp,bundlei,0);
iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2);
}
if ( coin->started != 0 && (block->height % coin->chain->bundlesize) == coin->minconfirms && (block->height > coin->longestchain-coin->chain->bundlesize*2 || ((block->height / coin->chain->bundlesize) % 100) == 9) )
if ( coin->started != 0 && bundlei == coin->minconfirms && (block->height > coin->longestchain-coin->chain->bundlesize*2 || ((block->height / coin->chain->bundlesize) % 100) == 9) )
{
//printf("savehdrs.[%d] ht.%d\n",bp->hdrsi,block->height);
iguana_savehdrs(coin);
@ -706,7 +744,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
int32_t iguana_chainextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *newblock)
{
struct iguana_block *block,*prev; int32_t valid,oldhwm; char str[65];
if ( iguana_blockvalidate(coin,&valid,newblock,0) < 0 || valid == 0 )
if ( iguana_blockvalidate(myinfo,coin,&valid,newblock,0) < 0 || valid == 0 )
{
printf("chainextend: newblock.%s didnt validate\n",bits256_str(str,newblock->RO.hash2));
return(-1);

145
iguana/iguana_bundles.c

@ -141,13 +141,15 @@ int32_t iguana_hash2set(struct iguana_info *coin,char *debugstr,struct iguana_bu
}
if ( bits256_nonz(*orighash2p) > 0 && memcmp(newhash2.bytes,orighash2p,sizeof(bits256)) != 0 )
{
char str2[65],str3[65];
bits256_str(str2,*orighash2p), bits256_str(str3,newhash2);
printf("WARNING iguana_hash2set overwrite avoided [%s] %s with %s [%d:%d]\n",debugstr,str2,str3,bp->hdrsi,bundlei);
return(-1);
static uint32_t counter;
if ( counter++ < 3 )
{
char str2[65],str3[65];
bits256_str(str2,*orighash2p), bits256_str(str3,newhash2);
printf("WARNING iguana_hash2set overwrite %s [%s] %s with %s [%d:%d]\n",coin->symbol,debugstr,str2,str3,bp->hdrsi,bundlei);
}
//*orighash2p = newhash2;
// getchar();
// return(-1);
return(-1);
}
if ( isinside != 0 )
{
@ -323,7 +325,7 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo
if ( err != 0 )
{
static uint32_t counter;
if ( counter++ < 100 )
if ( counter++ < 10 )
printf("bundlehash2add err.%d\n",err);
//return(0);
}
@ -379,7 +381,7 @@ struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bund
if ( issueflag != 0 )
{
iguana_blockQ("bundlecreate",coin,bp,0,bundlehash2,1);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
//queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
}
if ( bp->hdrsi >= coin->bundlescount )
coin->bundlescount = (bp->hdrsi + 1);
@ -587,7 +589,7 @@ struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p
if ( len > (sizeof(int32_t) + sizeof(*hashes))*n + 1024 )
{
printf("FATAL ERROR iguana_sendhashes: len.%d size.%ld\n",len,(sizeof(int32_t) + sizeof(*hashes))*n + 1024);
exit(-1);
iguana_exit(myinfo);
}
iguana_send(coin,addr,serialized,len);
coin->numreqsent += n;
@ -638,6 +640,8 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
lag = 60;
else if ( lag < 30 )
lag = 30;
if ( strcmp(coin->symbol,"BTC") != 0 )
lag /= 10;
if ( (num= coin->peers->numranked) == 0 )
iguana_updatemetrics(myinfo,coin);
if ( (num= coin->peers->numranked) != 0 )
@ -653,7 +657,7 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
lasti = firsti = -1;
for (i=nonz=0; i<bp->n; i++)
{
if ( (block= bp->blocks[i]) != 0 && block->txvalid != 0 )
if ( (block= bp->blocks[i]) != 0 && block->txvalid != 0 && block->mainchain != 0 )
continue;
//if ( GETBIT(bp->haveblock,i) != 0 )
// continue;
@ -661,12 +665,12 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
if ( firsti < 0 )
firsti = i;
lasti = i;
if ( bp->issued[i] > 1 && now > bp->issued[i]+lag )
if ( 1 )
{
iguana_bundleblock(coin,&hash2,bp,i);
if ( bits256_nonz(hash2) != 0 )
{
if ( 0 && (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 )
if ( (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 ) //strcmp("BTC",coin->symbol) != 0 || (bp->issued[i] > 1 && now > bp->issued[i]+lag &&
{
if ( 0 && bp == coin->current )
printf("iguana_bundleissuemissing.[%d:%d]\n",bp->hdrsi,i);
@ -684,7 +688,7 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
} //else printf("[z%d] ",i);
} //else printf("%d ",now - (bp->issued[i]+lag));
}
if ( firsti >= 0 && bp == coin->current )
if ( firsti >= 0 )//&& bp == coin->current )
{
//printf("[%d] first missing.%d of %d\n",bp->hdrsi,firsti,nonz);
iguana_bundleblock(coin,&hash2,bp,firsti);
@ -752,7 +756,7 @@ int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr)
return(n);
}
int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag)
int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag)
{
static bits256 zero;
int32_t i,ready,valid; char fname[1024]; struct iguana_block *block; int32_t sum[0x100],counts[0x100]; struct iguana_blockRO *B; struct iguana_bundle *nextbp; void *ptr; long filesize; struct iguana_ramchain R; bits256 prevhash2;
@ -805,7 +809,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
counts[block->peerid]++;
}
//printf("(%x:%x) ",(uint32_t)block->RO.hash2.ulongs[3],(uint32_t)bp->hashes[i].ulongs[3]);
if ( block->txvalid == 0 || block->fpipbits == 0 || block->fpos < 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(coin,&valid,block,1) < 0 )
if ( block->txvalid == 0 || block->fpipbits == 0 || block->fpos < 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(myinfo,coin,&valid,block,1) < 0 )
{
char str[65];
if ( requiredflag != 0 )
@ -835,11 +839,11 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
{
iguana_blockunmark(coin,block,bp,i,1);
if ( 0 && requiredflag != 0 )
printf("not ready altpath.(%d %d %d %d %d) [%d:%d]\n",block->txvalid == 0,block->fpipbits == 0 ,block->fpos < 0,(bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0),iguana_blockvalidate(coin,&valid,block,1) < 0,bp->hdrsi,i);
printf("not ready altpath.(%d %d %d %d %d) [%d:%d]\n",block->txvalid == 0,block->fpipbits == 0 ,block->fpos < 0,(bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0),iguana_blockvalidate(myinfo,coin,&valid,block,1) < 0,bp->hdrsi,i);
}
else
{
iguana_blockunmark(coin,block,bp,i,0);
//iguana_blockunmark(coin,block,bp,i,0);
//printf("cant find (%s)\n",fname);
}
}
@ -861,7 +865,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
int32_t iguana_bundlehdr(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t starti)
{
int32_t i,dist,counter=0; char str[64];
int32_t i,dist,counter=0; char str[65];
if ( 0 && bp->isRT == 0 && (bp->hdrsi == coin->bundlescount-1 || bp == coin->current) )
printf("hdr ITERATE.%d bundle.%d vs %d: h.%d n.%d r.%d s.%d c.%d finished.%d spec.%p[%d]\n",bp->hdrsi,bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->numcached,bp->emitfinish,bp->speculative,bp->numspec);
dist = 30 + (coin->current != 0 ? bp->hdrsi - coin->current->hdrsi : 0);
@ -925,10 +929,10 @@ int32_t iguana_bundletweak(struct iguana_info *coin,struct iguana_bundle *bp)
return(coin->MAXBUNDLES);
}
int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag)
int64_t iguana_bundlecalcs(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag)
{
int32_t bundlei,numhashes,numsaved,numrecv,numcached,minrequests; int64_t datasize; struct iguana_block *block;
if ( bp->emitfinish > 0 && (bp->ramchain.H.data != 0 || iguana_bundleready(coin,bp,0) == bp->n) )
if ( bp->emitfinish > 0 && (bp->ramchain.H.data != 0 || iguana_bundleready(myinfo,coin,bp,0) == bp->n) )
{
memset(bp->haveblock,0xff,sizeof(bp->haveblock));
bp->numhashes = bp->numsaved = bp->numcached = bp->numrecv = bp->n;
@ -1023,10 +1027,16 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int
int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB)
{
int32_t i; struct iguana_bundle *tmpbp;
if ( coin->firstRTheight == 0 && iguana_bundleready(coin,bp,0) == bp->n )
int32_t i; struct iguana_bundle *tmpbp; struct iguana_blockreq *breq;
if ( coin->firstRTheight == 0 && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
{
printf(">>>>>>>>>>>>>> EMIT.[%3d] %s | 1st.%-3d h.%-3d c.%-3d s.[%3d] maxB.%d NET.(h%d b%d) %ld:%02ld\n",bp->hdrsi,coin->symbol,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numcached:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,netBLOCKS,(time(NULL)-coin->startutc)/60,(time(NULL)-coin->startutc)%60);
printf(">>>>>>>>>>>>>> EMIT.[%3d] %s | 1st.%-3d h.%-3d c.%-3d s.[%3d] maxB.%d NET.(h%d b%d) %u:%02u\n",bp->hdrsi,coin->symbol,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numcached:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,queue_size(&coin->priorityQ),(uint32_t)(time(NULL)-coin->startutc)/60,(uint32_t)(time(NULL)-coin->startutc)%60);
if ( queue_size(&coin->priorityQ) > 10000 )
{
while ( (breq= queue_dequeue(&coin->priorityQ,0)) != 0 )
myfree(breq,sizeof(*breq));
//printf("cleared priorityQ\n");
}
if ( bp->emitfinish != 0 )
{
printf("already EMIT for bundle.%d\n",bp->hdrsi);
@ -1034,7 +1044,7 @@ int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *c
}
bp->emitfinish = 1;
usleep(100000); // make sure new incoming packet didnt overwrite
if ( iguana_bundleready(coin,bp,1) == bp->n )
if ( iguana_bundleready(myinfo,coin,bp,1) == bp->n )
{
usleep(100000); // make sure new incoming packet didnt overwrite
coin->emitbusy++;
@ -1050,13 +1060,14 @@ int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *c
printf("GENESIS block validated\n");
else printf("GENESIS didnt validate bp.%p\n",bp);*/
//if ( strcmp("BTC",coin->symbol) != 0 )
coin->spendvectorsaved = 0;
for (i=bp->hdrsi; i<coin->bundlescount; i++)
coin->RTheight = coin->firstRTheight = 0;
//coin->spendvectorsaved = 0;
for (i=0; i<coin->bundlescount; i++)
if ( (tmpbp= coin->bundles[i]) != 0 )
tmpbp->converted = tmpbp->balancefinish = tmpbp->validated = 0;
#ifdef __PNACL__
iguana_bundlevalidate(coin,bp,1);
#endif
//#ifdef __PNACL__
iguana_bundlevalidate(myinfo,coin,bp,1);
//#endif
}
else
{
@ -1089,7 +1100,7 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin
{
printf("%s not ready yet\n",coin->symbol);
bp->nexttime = (uint32_t)time(NULL) + 1;
iguana_bundleQ(coin,bp,1000);
iguana_bundleQ(myinfo,coin,bp,1000);
return(retval);
}
if ( coin->current == 0 )
@ -1100,9 +1111,9 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin
starti = currentbp == 0 ? 0 : currentbp->hdrsi;
lasti = lastbp == 0 ? coin->bundlescount-1 : lastbp->hdrsi;
range = lasti - starti + 1;
iguana_bundlecalcs(coin,bp,lag);
iguana_bundlecalcs(myinfo,coin,bp,lag);
if ( coin->blockdepth == 0 && coin->blockdepth == 0 && bp->hdrsi == coin->bundlescount-1 )
iguana_autoextend(coin,bp);
iguana_autoextend(myinfo,coin,bp);
if ( 0 && bp->hdrsi == 0 )
printf("ITER utxo.%u now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->utxofinish,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount);
bp->nexttime = (uint32_t)time(NULL) + ((bp->hdrsi > starti) ? 0 : -2);
@ -1110,7 +1121,7 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin
iguana_bundlehdr(myinfo,coin,bp,starti);
else if ( bp->emitfinish == 0 && bp->numsaved >= bp->n )
{
if ( coin->virtualchain != 0 || iguana_bundlefinalize(myinfo,coin,bp,mem,memB) > 0 )
if ( coin->virtualchain != 0 )//|| iguana_bundlefinalize(myinfo,coin,bp,mem,memB) > 0 )
{
//printf("bundlefinalized done.[%d]\n",bp->hdrsi);
return(0);
@ -1120,12 +1131,12 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin
else if ( bp->hdrsi == starti || (bp->hdrsi >= starti && bp->hdrsi <= starti+range) )
{
max = bp->n;
counter = iguana_bundleissuemissing(myinfo,coin,bp,1,1.);
counter = iguana_bundleissuemissing(myinfo,coin,bp,1,3.);
if ( 0 && counter > 0 )
printf("starti.%d range.%d now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",starti,range,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount);
} else bp->nexttime++;
if ( bp->emitfinish <= 1 )
iguana_bundleQ(coin,bp,1000);
if ( 0 && bp->emitfinish <= 1 )
iguana_bundleQ(myinfo,coin,bp,1000);
else
{
//printf("[%d] not queued\n",bp->hdrsi);
@ -1153,7 +1164,7 @@ static int32_t revsortds(double *buf,uint32_t num,int32_t size)
return(0);
}*/
int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei)
int32_t iguana_cacheprocess(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei)
{
int32_t recvlen; struct iguana_msghdr H; uint8_t *data; struct iguana_block *block;
if ( (data= bp->speculativecache[bundlei]) != 0 && bp->speculative != 0 && (block= iguana_blockfind("cacheprocess",coin,bp->speculative[bundlei])) != 0 && block->processed == 0 )
@ -1166,13 +1177,8 @@ int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,in
memset(&H,0,sizeof(H));
if ( iguana_sethdr(&H,coin->chain->netmagic,"block",&data[sizeof(recvlen)],recvlen) > 0 )
{
if ( coin->internaladdr.RAWMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.RAWMEM,"cache",0,IGUANA_MAXPACKETSIZE + 65536*3,0);
if ( coin->TXMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE*1.5,0);
if ( coin->internaladdr.HASHMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.HASHMEM,"HASHPTRS",0,256,0);
if ( iguana_msgparser(coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen,1) < 0 )
iguana_peer_meminit(coin,&coin->internaladdr);
if ( iguana_msgparser(myinfo,coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen,1) < 0 )
printf("error parsing speculativecache.[%d:%d]\n",bp->hdrsi,bundlei);
}
free(data);
@ -1203,7 +1209,7 @@ void iguana_unstickhdr(struct iguana_info *coin,struct iguana_bundle *bp,int32_t
void iguana_bundlemissings(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,uint32_t now)
{
int32_t mult = 7,n=0,priority = 1;
if ( now > bp->missingstime+30 )
if ( now > bp->missingstime+13 )
{
if ( coin->current != 0 )
{
@ -1288,7 +1294,7 @@ int32_t iguana_bundlehash2_check(struct iguana_info *coin,bits256 hash2)
void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,char *str,int32_t lag)
{
int32_t i,n,m,j,numv,numconverted,count,starti,lasti,pending,capacity,displag,numutxo,numbalances,numrecv,done,numhashes,numcached,numsaved,numemit; struct iguana_block *block; bits256 hash2;
int32_t i,n,m,j,numv,numconverted,count,starti,lasti,pending,capacity,displag,numutxo,numbalances,numrecv,done,numhashes,numcached,numsaved,numemit,numbQ=0; struct iguana_block *block; bits256 hash2; struct iguana_blockreq *breq;
int64_t spaceused=0,estsize = 0; struct iguana_bundle *currentbp,*lastbp,*bp,*lastpending = 0,*firstgap = 0; uint32_t now;
if ( coin->bundlescount <= 0 )
return;
@ -1308,6 +1314,8 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
{
if ( bp->converted != 0 )
numconverted++;
if ( bp->queued != 0 )
numbQ++;
if ( bp == coin->current && coin->blocks.hwmchain.height >= bp->bundleheight && coin->blocks.hwmchain.height < bp->bundleheight+bp->n )
{
for (j=coin->blocks.hwmchain.height-bp->bundleheight+1; j<=bp->n; j++)
@ -1335,7 +1343,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
if ( ((block= bp->blocks[j]) == 0 || bp == coin->current) && bp->speculativecache[j] != 0 )
{
if ( (block != 0 || (block= iguana_blockhashset("bundlestats3",coin,-1,bp->speculative[j],1)) != 0) && block->processed == 0 )
iguana_cacheprocess(coin,bp,j);
iguana_cacheprocess(myinfo,coin,bp,j);
numcached++;
}
if ( block != 0 && block->issued > 1 )
@ -1348,7 +1356,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
bp->metric = coin->bundlescount - bp->hdrsi;
if ( done > coin->bundlescount*IGUANA_HEADPERCENTAGE && bp->hdrsi > coin->bundlescount*IGUANA_TAILPERCENTAGE )
bp->metric *= 1000;
iguana_bundlecalcs(coin,bp,lag);
iguana_bundlecalcs(myinfo,coin,bp,lag);
estsize += bp->estsize;
numhashes += bp->numhashes;
numcached += bp->numcached;
@ -1373,19 +1381,19 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
}
else
{
if ( firstgap == 0 && bp->numsaved < bp->n && bp->numcached < bp->n && (bp->ramchain.H.data == 0 || bp->hdrsi == coin->longestchain/coin->chain->bundlesize || iguana_bundleready(coin,bp,bp->numsaved == bp->n) != bp->n) )
if ( firstgap == 0 && bp->queued == 0 && bp->numsaved < bp->n )
iguana_bundleQ(myinfo,coin,bp,1000);
if ( firstgap == 0 && bp->numsaved < bp->n && bp->numcached < bp->n && (bp->ramchain.H.data == 0 || bp->hdrsi == coin->longestchain/coin->chain->bundlesize || iguana_bundleready(myinfo,coin,bp,bp->numsaved == bp->n) != bp->n) )
{
//printf("firstgap <- [%d] emit.%u bp->n.%d numsaved.%d numcached.%d numhashes.%d\n",bp->hdrsi,bp->emitfinish,bp->n,bp->numsaved,bp->numcached,bp->numhashes);
firstgap = bp;
if ( bp->queued == 0 )
iguana_bundleQ(coin,bp,1000);
}
//else printf("[%d] emit.%u bp->n.%d numsaved.%d numcached.%d numhashes.%d\n",bp->hdrsi,bp->emitfinish,bp->n,bp->numsaved,bp->numcached,bp->numhashes);
if ( bp->emitfinish == 0 )
{
if ( lastpending == 0 && bp->queued == 0 )
iguana_bundleQ(coin,bp,1000);
iguana_bundleQ(myinfo,coin,bp,1000);
if ( firstgap != 0 && bp->numsaved < bp->n && ++pending == coin->MAXBUNDLES )
{
lastpending = bp;
@ -1433,12 +1441,17 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
if ( (bp= firstgap) != 0 )//&& coin->PREFETCHLAG < 0 )
{
if ( bp != coin->current )
printf("new 1st.%d\n",bp->hdrsi);
{
printf("%s new 1st.%d\n",coin->symbol,bp->hdrsi);
iguana_bundleissuemissing(myinfo,coin,bp,1 + (rand() % 3),1.);
if ( bp->queued == 0 )
iguana_bundleQ(myinfo,coin,bp,0);
}
//else printf("issue 1st.%d\n",bp->hdrsi);
for (i=0; i<bp->n; i++)
if ( GETBIT(bp->haveblock,i) == 0 )
bp->issued[i] = 0;
iguana_bundleissuemissing(myinfo,coin,bp,1 + (rand() % 3),1.);
//for (i=0; i<bp->n; i++)
// if ( GETBIT(bp->haveblock,i) == 0 )
// bp->issued[i] = 0;
//iguana_bundleissuemissing(myinfo,coin,bp,1 + (rand() % 3),1.);
}
if ( (coin->current= firstgap) == 0 )
{
@ -1468,7 +1481,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
}
else if ( coin->stucktime != 0 )
{
struct iguana_blockreq *breq; int32_t n,lag; //priority=3,
int32_t n,lag; //priority=3,
lag = (int32_t)time(NULL) - coin->stucktime;
//printf("NONZ stucktime.%u lag.%d iters.%d vs %d metric.%d\n",coin->stucktime,lag,coin->stuckiters,lag/coin->MAXSTUCKTIME,smetric);
if ( (lag/coin->MAXSTUCKTIME) > coin->stuckiters )
@ -1492,7 +1505,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
if ( GETBIT(bp->haveblock,i) == 0 )
bp->issued[i] = 0;
if ( (n= iguana_bundleissuemissing(myinfo,coin,bp,3,1.)) > 0 )
printf("issued %d priority requests [%d] to unstick stuckiters.%d lag.%d\n",n,bp->hdrsi,coin->stuckiters,lag);
printf("%s issued %d priority requests [%d] to unstick stuckiters.%d lag.%d\n",coin->symbol,n,bp->hdrsi,coin->stuckiters,lag);
//else printf("no bundlerequests issued\n");
}
} //else printf("stuck metric.%d\n",smetric);
@ -1501,7 +1514,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
coin->stucktime = coin->stuckiters = 0;
if ( coin->stucktime != 0 && time(NULL)-coin->stucktime > coin->maxstuck )
coin->maxstuck = (uint32_t)time(NULL) - coin->stucktime;
sprintf(str,"%s.RT%d u.%d+c.%d b.%d v.%d (%d+%d/%d 1st.%d).s%d to %d N[%d] h.%d r.%d c.%d s.%d d.%d E.%d maxB.%d peers.%d/%d Q.(%d %d) (L.%d %d:%d) M.%d %s ledger.%08llx supply %.8f",coin->symbol,coin->RTheight,numutxo,numconverted,numbalances,iguana_validated(coin),firstgap!=0?firstgap->numcached:-1,firstgap!=0?firstgap->numsaved:-1,firstgap!=0?firstgap->numhashes:-1,firstgap!=0?firstgap->hdrsi:-1,firstgap!=0?firstgap->numspec:-1,coin->lastpending!=0?coin->lastpending->hdrsi:0,count,numhashes,coin->blocksrecv,numcached,numsaved,done,numemit,coin->MAXBUNDLES,p,coin->MAXPEERS,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ),coin->longestchain,coin->longestchain/coin->chain->bundlesize,coin->longestchain%coin->chain->bundlesize,coin->blocks.hwmchain.height,bits256_str(str5,coin->blocks.hwmchain.RO.hash2),(long long)coin->utxoaddrhash.txid,dstr(coin->histbalance)+dstr(coin->RTcredits)-dstr(coin->RTdebits));
sprintf(str,"%s.RT%d u.%d+c.%d b.%d v.%d (%d+%d/%d 1st.%d).s%d to %d N[%d] h.%d r.%d c.%d s.%d d.%d E.%d maxB.%d peers.%d/%d Q.(%d %d) (L.%d %d:%d) M.%d %s ledger.%08llx supply %.8f sigs %u:%u",coin->symbol,coin->RTheight,numutxo,numconverted,numbalances,iguana_validated(coin),firstgap!=0?firstgap->numcached:-1,firstgap!=0?firstgap->numsaved:-1,firstgap!=0?firstgap->numhashes:-1,firstgap!=0?firstgap->hdrsi:-1,firstgap!=0?firstgap->numspec:-1,coin->lastpending!=0?coin->lastpending->hdrsi:0,count,numhashes,coin->blocksrecv,numcached,numsaved,done,numemit,coin->MAXBUNDLES,p,coin->MAXPEERS,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ),coin->longestchain,coin->longestchain/coin->chain->bundlesize,coin->longestchain%coin->chain->bundlesize,coin->blocks.hwmchain.height,bits256_str(str5,coin->blocks.hwmchain.RO.hash2),(long long)coin->utxoaddrhash.txid,dstr(coin->histbalance)+dstr(coin->RTcredits)-dstr(coin->RTdebits),coin->sigserrs,coin->sigsvalidated);
//if( strcmp("BTC",coin->symbol) == 0 )
// printf("%s\n",str);
if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize && numemit == coin->current->hdrsi && numutxo == coin->bundlescount-1 )
@ -1518,7 +1531,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
//printf("bundleQ.[%d]\n",j);
bp->balancefinish = bp->startutxo = 0;
bp->utxofinish = 1;
iguana_bundleQ(coin,bp,1000);
iguana_bundleQ(myinfo,coin,bp,1000);
}
}
}
@ -1530,10 +1543,10 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
logfp = fopen("debug.log","wb");
if ( logfp != 0 )
{
fprintf(logfp,"%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
fprintf(logfp,"%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,numbQ,(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
fflush(logfp);
}
//printf("%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
//printf("%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,numbQ,(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
strcpy(coin->lastdispstr,str);
if ( (rand() % 100) == 0 )
myallocated(0,0);
@ -1551,5 +1564,11 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
iguana_setmaxbundles(coin);
strcpy(coin->statusstr,str);
coin->estsize = estsize;
if ( queue_size(&coin->priorityQ) > 10000 )
{
while ( (breq= queue_dequeue(&coin->priorityQ,0)) != 0 )
myfree(breq,sizeof(*breq));
//printf("cleared priorityQ\n");
}
}

52
iguana/iguana_chains.c

@ -161,21 +161,21 @@ bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhash
return(hash2);
}
bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root)
bits256 iguana_chaingenesis(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root)
{
struct iguana_msgblock msg; int32_t len; bits256 hash2; char blockhashstr[256]; uint8_t serialized[8192];
memset(&msg,0,sizeof(msg));
msg.H.version = version;
msg.H.merkle_root = merkle_root;
msg.H.timestamp = timestamp;
msg.H.bits = nBits;
msg.H.nonce = nonce;
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; int32_t len; bits256 hash2; char blockhashstr[256]; uint8_t serialized[8192];
memset(&zmsg,0,sizeof(zmsg));
msg->H.version = version;
msg->H.merkle_root = merkle_root;
msg->H.timestamp = timestamp;
msg->H.bits = nBits;
msg->H.nonce = nonce;
if ( zcash != 0 )
printf("need to handle zcash genesis\n");
if ( hashalgostr != 0 && strcmp(hashalgostr,"sha256") != 0 )
hashalgo = iguana_hashalgo(hashalgostr);
else hashalgo = blockhash_sha256;
len = iguana_rwblock(symbol,zcash,auxpow,hashalgo,1,&hash2,serialized,&msg,sizeof(1024));
len = iguana_rwblock(myinfo,symbol,zcash,auxpow,hashalgo,1,&hash2,serialized,&zmsg,sizeof(1024));
blockhashstr[0] = 0;
init_hexbytes_noT(blockhashstr,hash2.bytes,sizeof(hash2));
char str[65],str2[65];
@ -284,7 +284,7 @@ uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *us
return(port);
}
void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,cJSON *argjson)
{
extern char Userhome[];
char *path,conf[512],*hexstr,genesisblock[1024]; uint16_t port; cJSON *rpair,*genesis,*rewards,*item; int32_t i,n,m; uint32_t nBits; uint8_t tmp[4];
@ -341,6 +341,8 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
chain->rpcport = 14632;
}
chain->zcash = juint(argjson,"zcash");
chain->debug = juint(argjson,"debug");
chain->fixit = juint(argjson,"fixit");
if ( (chain->normal_txversion= juint(argjson,"normal_txversion")) == 0 )
chain->normal_txversion = IGUANA_NORMAL_TXVERSION;
if ( (chain->locktime_txversion= juint(argjson,"locktime_txversion")) == 0 )
@ -384,7 +386,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
decode_hex((uint8_t *)&chain->wiftype,1,hexstr);
}
}
printf("addrtypes.(%02x %02x %02x) (%d %d %d)\n",chain->pubtype,chain->p2shtype,chain->wiftype,chain->pubtype,chain->p2shtype,chain->wiftype);
printf("MINCONFIRMS.%d addrtypes.(%02x %02x %02x) (%d %d %d)\n",chain->minconfirms,chain->pubtype,chain->p2shtype,chain->wiftype,chain->pubtype,chain->p2shtype,chain->wiftype);
if ( (hexstr= jstr(argjson,"netmagic")) != 0 && strlen(hexstr) == 8 )
decode_hex((uint8_t *)chain->netmagic,4,hexstr);
if ( (hexstr= jstr(argjson,"unitval")) != 0 && strlen(hexstr) == 2 )
@ -411,7 +413,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
chain->nBits = nBits;
chain->unitval = (nBits >> 24);
printf("NETMAGIC %08x unitval.%02x nBits.%08x\n",*(uint32_t *)chain->netmagic,chain->unitval,chain->nBits);
chain->genesishash2 = iguana_chaingenesis(chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,chain->genesishash2,genesisblock,jstr(genesis,"hashalgo"),juint(genesis,"version"),juint(genesis,"timestamp"),nBits,juint(genesis,"nonce"),jbits256(genesis,"merkle_root"));
chain->genesishash2 = iguana_chaingenesis(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,chain->genesishash2,genesisblock,jstr(genesis,"hashalgo"),juint(genesis,"version"),juint(genesis,"timestamp"),nBits,juint(genesis,"nonce"),jbits256(genesis,"merkle_root"));
memcpy(chain->genesis_hashdata,chain->genesishash2.bytes,32);
char str[65]; init_hexbytes_noT(str,chain->genesis_hashdata,32);
chain->genesis_hash = clonestr(str);
@ -433,7 +435,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
if ( (hexstr= jstr(argjson,"genesisblock")) != 0 )
{
uint8_t hexbuf[1024],*ptr,*data; int32_t datalen,hdrsize;
hdrsize = chain->zcash != 0 ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr);
hdrsize = chain->zcash != 0 ? sizeof(struct iguana_msgzblockhdr) : sizeof(struct iguana_msgblockhdr);
chain->genesis_hex = clonestr(hexstr);
data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr);
chain->genesishash2 = iguana_calcblockhash(chain->symbol,chain->hashalgo,data,hdrsize);
@ -460,7 +462,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
}
}
void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson)
void iguana_chaininit(struct supernet_info *myinfo,struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson)
{
int32_t i;
if ( chain->hashalgo != 0 )
@ -482,11 +484,11 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs
chain->txfee = 10000;
chain->havecltv = 1;
}
else chain->txfee = 1000000;
else chain->txfee = 10000;
if ( chain->unitval == 0 )
chain->unitval = 0x1e;
if ( argjson != 0 )
iguana_chainparms(chain,argjson);
iguana_chainparms(myinfo,chain,argjson);
if ( hasheaders != 0 )
{
strcpy(chain->gethdrsmsg,"getheaders");
@ -497,6 +499,8 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs
strcpy(chain->gethdrsmsg,"getblocks");
chain->bundlesize = _IGUANA_BLOCKHASHES;
}
if ( chain->zcash != 0 )
chain->bundlesize = 500;
if ( strcmp(chain->symbol,"BTC") == 0 )
chain->bundlesize = 100;
decode_hex((uint8_t *)chain->genesis_hashdata,32,(char *)chain->genesis_hash);
@ -504,7 +508,7 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs
chain->rpcport = chain->portp2p + 1;
}
struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createflag)
struct iguana_chain *iguana_chainfind(struct supernet_info *myinfo,char *name,cJSON *argjson,int32_t createflag)
{
struct iguana_chain *chain; uint32_t i;
for (i=0; i<sizeof(Chains)/sizeof(*Chains); i++)
@ -515,23 +519,23 @@ struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createfl
{
if ( createflag != 0 && argjson != 0 )
{
iguana_chaininit(chain,strcmp(chain->symbol,"BTCD") != 0,argjson);
iguana_chaininit(myinfo,chain,strcmp(chain->symbol,"BTCD") != 0,argjson);
return(chain);
}
continue;
}
if ( strcmp(name,chain->symbol) == 0 )
{
iguana_chaininit(chain,strcmp(chain->symbol,"BTCD") != 0,argjson);
iguana_chaininit(myinfo,chain,strcmp(chain->symbol,"BTCD") != 0,argjson);
return(chain);
}
}
chain = calloc(1,sizeof(*chain));
iguana_chaininit(chain,1,argjson);
iguana_chaininit(myinfo,chain,1,argjson);
return(chain);
}
struct iguana_chain *iguana_findmagic(uint8_t netmagic[4])
struct iguana_chain *iguana_findmagic(struct supernet_info *myinfo,uint8_t netmagic[4])
{
struct iguana_chain *chain; uint8_t i;
for (i=0; i<sizeof(Chains)/sizeof(*Chains); i++)
@ -540,7 +544,7 @@ struct iguana_chain *iguana_findmagic(uint8_t netmagic[4])
if ( chain->name[0] == 0 || chain->genesis_hash == 0 )
continue;
if ( memcmp(netmagic,chain->netmagic,4) == 0 )
return(iguana_chainfind((char *)chain->symbol,0,0));
return(iguana_chainfind(myinfo,(char *)chain->symbol,0,0));
}
return NULL;
}
@ -558,7 +562,7 @@ uint64_t iguana_miningreward(struct iguana_info *coin,uint32_t blocknum)
return(reward);
}
struct iguana_chain *iguana_createchain(cJSON *json)
struct iguana_chain *iguana_createchain(struct supernet_info *myinfo,cJSON *json)
{
char *symbol,*name; struct iguana_chain *chain = 0;
if ( ((symbol= jstr(json,"newcoin")) != 0 || (symbol= jstr(json,"name")) != 0) && strlen(symbol) < 8 )
@ -567,7 +571,7 @@ struct iguana_chain *iguana_createchain(cJSON *json)
strcpy(chain->symbol,symbol);
if ( (name= jstr(json,"description")) != 0 && strlen(name) < 32 )
strcpy(chain->name,name);
iguana_chaininit(chain,juint(json,"hasheaders"),json);
iguana_chaininit(myinfo,chain,juint(json,"hasheaders"),json);
}
return(chain);
}

31
iguana/iguana_exchanges.c

@ -1035,7 +1035,7 @@ struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson)
if ( stringbits((char *)Exchange_funcs[i]->name) == stringbits((char *)Exchange_funcs[j]->name) )
{
printf("FIRST 8 chars of Exchange_func[].name must be unique: %d.(%s) vs %d.(%s)\n",i,Exchange_funcs[i]->name,j,Exchange_funcs[j]->name);
exit(-1);
iguana_exit(0,0);
}
}
didinit = 1;
@ -1072,18 +1072,21 @@ struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson)
exchange->exchangeid = exchangeid;
safecopy(exchange->name,exchangestr,sizeof(exchange->name));
exchange->exchangebits = stringbits(exchange->name);
if ( (exchange->pollgap= juint(argjson,"pollgap")) < EXCHANGES777_MINPOLLGAP )
exchange->pollgap = EXCHANGES777_MINPOLLGAP;
if ( (key= jstr(argjson,"apikey")) != 0 || (key= jstr(argjson,"key")) != 0 )
safecopy(exchange->apikey,key,sizeof(exchange->apikey));
if ( (secret= jstr(argjson,"apisecret")) != 0 || (secret= jstr(argjson,"secret")) != 0 )
safecopy(exchange->apisecret,secret,sizeof(exchange->apisecret));
if ( (userid= jstr(argjson,"userid")) != 0 )
safecopy(exchange->userid,userid,sizeof(exchange->userid));
if ( (tradepassword= jstr(argjson,"tradepassword")) != 0 )
safecopy(exchange->tradepassword,tradepassword,sizeof(exchange->tradepassword));
if ( (exchange->commission= jdouble(argjson,"commission")) > 0. )
exchange->commission *= .01;
if ( argjson != 0 )
{
if ( (exchange->pollgap= juint(argjson,"pollgap")) < EXCHANGES777_MINPOLLGAP )
exchange->pollgap = EXCHANGES777_MINPOLLGAP;
if ( (key= jstr(argjson,"apikey")) != 0 || (key= jstr(argjson,"key")) != 0 )
safecopy(exchange->apikey,key,sizeof(exchange->apikey));
if ( (secret= jstr(argjson,"apisecret")) != 0 || (secret= jstr(argjson,"secret")) != 0 )
safecopy(exchange->apisecret,secret,sizeof(exchange->apisecret));
if ( (userid= jstr(argjson,"userid")) != 0 )
safecopy(exchange->userid,userid,sizeof(exchange->userid));
if ( (tradepassword= jstr(argjson,"tradepassword")) != 0 )
safecopy(exchange->tradepassword,tradepassword,sizeof(exchange->tradepassword));
if ( (exchange->commission= jdouble(argjson,"commission")) > 0. )
exchange->commission *= .01;
}
printf("ADDEXCHANGE.(%s) [%s, %s, %s] commission %.3f%% -> exchangeid.%d\n",exchangestr,exchange->apikey,exchange->userid,exchange->apisecret,exchange->commission * 100.,exchangeid);
Exchanges[exchangeid] = exchange;
//instantdex_FSMinit();
@ -1132,7 +1135,7 @@ void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sle
{
if ( strcmp(Exchange_funcs[i]->name,"PAX") == 0 || strcmp(Exchange_funcs[i]->name,"truefx") == 0 || strcmp(Exchange_funcs[i]->name,"fxcm") == 0 || strcmp(Exchange_funcs[i]->name,"instaforx") == 0 )
continue;
if ( ((exchange= exchanges777_find(Exchange_funcs[i]->name)) == 0 && (exchange= exchange_create(Exchange_funcs[i]->name,item)) != 0) || (exchange= exchanges777_info(Exchange_funcs[i]->name,sleepflag,argjson,0)) != 0 )
if ( ((exchange= exchanges777_find(Exchange_funcs[i]->name)) == 0 && (exchange= exchange_create(Exchange_funcs[i]->name,0)) != 0) || (exchange= exchanges777_info(Exchange_funcs[i]->name,sleepflag,argjson,0)) != 0 )
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange;
}
free_json(argjson);

56
iguana/iguana_init.c

@ -92,7 +92,7 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
bits256 iguana_genesis(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_chain *chain)
{
struct iguana_block *block,*ptr; struct iguana_msgblock msg; bits256 hash2; char str[65],str2[65]; uint8_t buf[8192],blockspace[sizeof(*block)+sizeof(*block->zRO)]; int32_t height,auxback;
struct iguana_block *block,*ptr; struct iguana_msgzblock zmsg; bits256 hash2; char str[65],str2[65]; uint8_t buf[8192],blockspace[sizeof(*block)+sizeof(struct iguana_zblock)]; int32_t height,auxback;
if ( coin == 0 || chain == 0 )
return(GENESIS_PUBKEY);
block = (void *)blockspace;
@ -106,37 +106,42 @@ bits256 iguana_genesis(struct supernet_info *myinfo,struct iguana_info *coin,str
return(hash2);
}
decode_hex(buf,(int32_t)strlen(chain->genesis_hex)/2,(char *)chain->genesis_hex);
hash2 = iguana_calcblockhash(coin->symbol,coin->chain->hashalgo,buf,sizeof(struct iguana_msgblockhdr));
auxback = coin->chain->auxpow, coin->chain->auxpow = 0;
iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,buf,&msg,sizeof(buf));
coin->chain->auxpow = auxback;
hash2 = iguana_calcblockhash(coin->symbol,coin->chain->hashalgo,buf,chain->zcash == 0 ? sizeof(struct iguana_msgblockhdr) : sizeof(struct iguana_msgzblockhdr));
auxback = chain->auxpow, chain->auxpow = 0;
iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,chain->auxpow,chain->hashalgo,0,&hash2,buf,(void *)&zmsg,sizeof(buf));
chain->auxpow = auxback;
if ( coin->virtualchain == 0 && coin->MAXPEERS > 1 )
{
if ( memcmp(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)) != 0 )
if ( chain->debug == 0 && memcmp(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)) != 0 )
{
bits256_str(str,hash2);
printf("genesis mismatch? zcash.%d calculated %s vs %s\n",coin->chain->zcash,str,bits256_str(str2,*(bits256 *)chain->genesis_hashdata));
printf("genesis mismatch? zcash.%d calculated %s vs %s\n",chain->zcash,str,bits256_str(str2,*(bits256 *)chain->genesis_hashdata));
memcpy(hash2.bytes,chain->genesis_hashdata,sizeof(hash2));
}
if ( coin->chain->debug != 0 )
memcpy(hash2.bytes,chain->genesis_hashdata,sizeof(hash2));
} else memcpy(hash2.bytes,chain->genesis_hashdata,sizeof(hash2));
bits256_str(str,hash2);
printf("genesis.(%s) zcash.%d len.%d hash.%s\n",chain->genesis_hex,coin->chain->zcash,(int32_t)sizeof(msg.H),str);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,block,&msg,hash2,0);
if ( chain->debug != 0 )
printf("genesis.(%s) zcash.%d len.%d hash.%s\n",chain->genesis_hex,chain->zcash,(int32_t)sizeof(zmsg.zH),str);
iguana_blockconv(chain->zcash,chain->auxpow,(void *)block,&zmsg,hash2,0);
block->RO.txn_count = 1;
block->RO.numvouts = 1;
block->RO.allocsize = (int32_t)(sizeof(*block) + coin->chain->zcash*sizeof(*block->zRO));
if ( chain->zcash != 0 )
block->RO.allocsize = sizeof(struct iguana_zblock);
else block->RO.allocsize = (int32_t)sizeof(*block);
iguana_gotdata(coin,0,0);
if ( (ptr= iguana_blockhashset("genesis0",coin,0,hash2,1)) != 0 )
{
iguana_blockcopy(coin->chain->zcash,coin->chain->auxpow,coin,ptr,block);
iguana_blocksizecheck("genesis ptr",coin->chain->zcash,ptr);
iguana_blockcopy(chain->zcash,chain->auxpow,coin,ptr,block);
iguana_blocksizecheck("genesis ptr",chain->zcash,ptr);
ptr->mainchain = 1;
ptr->height = 0;
//coin->blocks.RO[0] = block.RO;
if ( coin->virtualchain != 0 || (height= iguana_chainextend(myinfo,coin,ptr)) == 0 )
{
iguana_blockzcopy(coin->chain->zcash,block,ptr);
iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,ptr);
iguana_blockzcopy(chain->zcash,block,ptr);
iguana_blockzcopy(chain->zcash,(void *)&coin->blocks.hwmchain,ptr);
printf("size.%d genesis block PoW %f ptr %f\n",block->RO.allocsize,block->PoW,ptr->PoW);
coin->blocks.recvblocks = coin->blocks.issuedblocks = 1;
} else printf("genesis block doesnt validate for %s ht.%d\n",coin->symbol,height);
@ -194,7 +199,8 @@ int32_t iguana_savehdrs(struct iguana_info *coin)
printf("new hdrs.txt %ld vs (%s) %ld\n",ftell(fp),fname,(long)OS_filesize(fname));
fclose(fp);
OS_renamefile(fname,oldfname);
OS_copyfile(tmpfname,fname,1);
OS_renamefile(tmpfname,fname);
//OS_copyfile(tmpfname,fname,1);
} else fclose(fp);
if ( fp2 != 0 )
{
@ -210,7 +216,7 @@ int32_t iguana_savehdrs(struct iguana_info *coin)
return(retval);
}
int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1)
int32_t iguana_bundleinitmap(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1)
{
char str[65]; struct iguana_block *block;
bp->bundleheight = height;
@ -226,7 +232,7 @@ int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,i
coin->current = coin->bundles[0] = bp;
if ( (block= iguana_blockfind("parse",coin,hash2)) != 0 )
block->mainchain = 1, block->height = height;
if ( iguana_bundleload(coin,&bp->ramchain,bp,2) != 0 )
if ( iguana_bundleload(myinfo,coin,&bp->ramchain,bp,2) != 0 )
{
if ( coin->current != 0 && coin->current->hdrsi+1 == bp->hdrsi )
coin->current = bp;
@ -240,7 +246,7 @@ int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,i
bp->emitfinish = 0;
iguana_blockQ("init",coin,bp,0,hash2,1);
//printf("init reqhdrs.%d\n",bp->bundleheight);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
//queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
memset(&hash2,0,sizeof(hash2));
bp->emitfinish = 0;
return(-1);
@ -253,6 +259,10 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,hash1,zero,lastbundle;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 && iter > 0 )
return;
OS_randombytes((uint8_t *)&j,sizeof(j));
if ( j < 0 )
j = -j;
srand(j);
memset(&zero,0,sizeof(zero));
lastbundle = zero;
if ( coin->MAXPEERS > IGUANA_MAXPEERS )
@ -292,7 +302,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
//printf("parse line.(%s) maxpeers.%d\n",line,coin->MAXPEERS);
if ( iter == 0 )
{
if ( m < 32 || (m < coin->MAXPEERS/2 && strcmp("BTCD",coin->symbol) != 0) )//&& m < 77.7 )
if ( (m < 8 || (rand() % 2) == 0) && (m < 32 || m < coin->MAXPEERS/2) )//&& m < 77.7 )
{
if ( 0 && m == 0 )
{
@ -333,7 +343,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
{
//printf("created bundle.%d\n",bp->hdrsi);
memset(hash1.bytes,0,sizeof(hash1));
iguana_bundleinitmap(coin,bp,height,hash2,hash1);
iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1);
lastbundle = hash2;
}
}
@ -362,7 +372,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
}
if ( height >= lastheight )
{
if ( iguana_bundleinitmap(coin,bp,height,hash2,hash1) == 0 )
if ( iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1) == 0 )
lastbundle = hash2, lastheight = height;
}
}
@ -459,7 +469,7 @@ void iguana_coinpurge(struct iguana_info *coin)
coin->started = 0;
while ( coin->idletime == 0 && coin->emitbusy > 0 )
{
printf("coinpurge.%s waiting for idle %lu emitbusy.%d\n",coin->symbol,time(NULL),coin->emitbusy);
printf("coinpurge.%s waiting for idle %u emitbusy.%d\n",coin->symbol,(uint32_t)time(NULL),coin->emitbusy);
sleep(1);
}
coin->RTgenesis = 0;
@ -534,7 +544,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
}
}
}
if ( coin->FULLNODE != 0 && coin->rpcloop == 0 )
if ( coin->rpcloop == 0 )
{
myinfo->argport = coin->chain->rpcport;
coin->rpcloop = malloc(sizeof(pthread_t));

52
iguana/iguana_interpreter.c

@ -498,7 +498,7 @@ static int32_t iguana_pushdata(struct iguana_interpreter *stacks,int64_t num64,u
struct iguana_stackdata Snum; cJSON *item = 0; char tmpstr[2048]; int32_t num = (int32_t)num64;
if ( stacks->lastpath[stacks->ifdepth] < 0 )
return(0);
printf("PUSH.(%lld %p %d)\n",(long long)num64,numbuf,numlen);
//printf("PUSH.(%lld %p %d)\n",(long long)num64,numbuf,numlen);
if ( stacks->maxstackdepth > 0 )
{
/*if ( numbuf != 0 )
@ -726,17 +726,26 @@ void iguana_stack(struct iguana_interpreter *stacks,struct iguana_stackdata *arg
int32_t iguana_checksig(struct iguana_info *coin,struct iguana_stackdata pubkeyarg,struct iguana_stackdata sigarg,bits256 sigtxid)
{
uint8_t pubkey[MAX_SCRIPT_ELEMENT_SIZE],sig[MAX_SCRIPT_ELEMENT_SIZE]; int32_t plen,siglen;
uint8_t pubkey[MAX_SCRIPT_ELEMENT_SIZE],sig[MAX_SCRIPT_ELEMENT_SIZE]; int32_t retval,plen,siglen;
plen = iguana_databuf(pubkey,pubkeyarg);
siglen = iguana_databuf(sig,sigarg);
int32_t i; for (i=0; i<siglen; i++)
printf("%02x",sig[i]);
printf(" sig, ");
for (i=0; i<plen; i++)
printf("%02x",pubkey[i]);
char str[65]; printf(" checksig sigtxid.%s\n",bits256_str(str,sigtxid));
if ( bitcoin_pubkeylen(pubkey) == plen && plen > 0 && siglen > 0 && siglen < 74 )
return(bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,pubkey,plen) == 0);
{
if ( (retval= (bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,pubkey,plen) == 0)) == 0 )
{
if ( 1 )
{
int32_t i; char str[65];
for (i=0; i<siglen; i++)
printf("%02x",sig[i]);
printf(" sig, ");
for (i=0; i<plen; i++)
printf("%02x",pubkey[i]);
printf(" checksig sigtxid.%s\n",bits256_str(str,sigtxid));
}
}
return(retval);
}
return(0);
}
@ -949,9 +958,12 @@ int32_t iguana_expandscript(struct iguana_info *coin,char *asmstr,int32_t maxlen
n = (n << 8) | script[i++];
n = (n << 8) | script[i++];
n = (n << 8) | script[i++];
for (j=0; j<n; j++)
sprintf(&asmstr[len],"%02x",script[i++]), len += 2;
extraflag = 1;
if ( n < IGUANA_MAXSCRIPTSIZE )
{
for (j=0; j<n; j++)
sprintf(&asmstr[len],"%02x",script[i++]), len += 2;
extraflag = 1;
} else return(-1);
}
if ( extraflag != 0 && i < scriptlen )
asmstr[len++] = ' ';
@ -978,8 +990,8 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
uint8_t databuf[MAX_SCRIPT_ELEMENT_SIZE]; char *asmstr,*str,*hexstr; cJSON *item;
int32_t c,numops,dlen,plen,numvars,numused,numargs=0,i,j,k,n,len,datalen,errs=0; int64_t val;
iguana_optableinit(coin);
if ( (asmstr= jstr(interpreter,"interpreter")) == 0 )
return(-1);
if ( (asmstr= jstr(interpreter,"interpreter")) == 0 || asmstr[0] == 0 )
return(0);
if ( (numvars= juint(interpreter,"numvars")) > 0 )
{
if ( (array= jarray(&n,interpreter,"args")) == 0 || (interpret != 0 && n != numvars) )
@ -1017,8 +1029,8 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
if ( V->suppress_pubkeys == 0 && (V->spendscript[0] != plen || V->spendscript[V->spendlen - 1] != IGUANA_OP_CHECKSIG || bitcoin_pubkeylen(&V->spendscript[1]) <= 0) )
{
iguana_pushdata(stacks,0,V->signers[i].pubkey,plen);
printf(">>>>>>>>> suppress.%d pushdata plen.%d depth.%d\n",V->suppress_pubkeys,plen,stacks->stackdepth);
} else printf("<<<<<<<<<< skip pubkey push %d script[0].%d spendlen.%d depth.%d\n",plen,V->spendscript[0],V->spendlen,stacks->stackdepth);
//printf(">>>>>>>>> suppress.%d pushdata plen.%d depth.%d\n",V->suppress_pubkeys,plen,stacks->stackdepth);
} // else printf("<<<<<<<<<< skip pubkey push %d script[0].%d spendlen.%d depth.%d\n",plen,V->spendscript[0],V->spendlen,stacks->stackdepth);
}
}
if ( V->userdatalen != 0 )
@ -1143,7 +1155,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
break;
}
HASH_FIND(hh,OPTABLE,str,j,op);
printf("{%s}\n",str);
//printf("{%s}\n",str);
str += j;
if ( op != 0 )
{
@ -1545,7 +1557,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
else if ( iguana_isnonz(stacks->stack[--stacks->stackdepth]) != 0 )
{
printf("Evaluate true, depth.%d errs.%d k.%d\n",stacks->stackdepth,errs,k);
//printf("Evaluate true, depth.%d errs.%d k.%d\n",stacks->stackdepth,errs,k);
if ( errs == 0 )
jadd(interpreter,"result",jtrue());
else jadd(interpreter,"result",jfalse());
@ -1554,9 +1566,9 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
{
jadd(interpreter,"result",jfalse());
printf("Evaluate FALSE, depth.%d errs.%d [0] size.%d num.%d\n",stacks->stackdepth,errs,stacks->stack[0].size,stacks->stack[0].U.val);
if ( stacks->logarray != 0 )
printf("LOG.(%s)\n\n",jprint(stacks->logarray,0));
}
//if ( stacks->logarray != 0 )
// printf("LOG.(%s)\n",jprint(stacks->logarray,0));
if ( numargs > 0 )
{
for (i=0; i<numargs; i++)

2
iguana/iguana_json.c

@ -908,7 +908,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
if ( coinstr != 0 && coinstr[0] != 0 )
coin = iguana_coinfind(coinstr);
if ( strcmp(agentstr,"bitcoinrpc") == 0 && coin == 0 )
return(clonestr("{\"error\":\"bitcoinrpc needs coin\"}"));
return(clonestr("{\"error\":\"bitcoinrpc needs coin that is active\"}"));
#define IGUANA_ARGS myinfo,coin,json,remoteaddr
#define IGUANA_DISPATCH0(agent,name) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS))
#define IGUANA_DISPATCH_S(agent,name,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str)))

2
iguana/iguana_mofn.c

@ -656,7 +656,7 @@ bits256 iguana_schnorr_noncepair(void *ctx,bits256 *pubkey,uint8_t odd_even,bits
if ( j == maxj )
{
printf("couldnt generate even noncepair\n");
exit(-1);
iguana_exit(0,0);
}
return(privnonce);
}

339
iguana/iguana_msg.c

@ -91,46 +91,56 @@ int32_t iguana_rwmerklebranch(int32_t rwflag,uint8_t *serialized,struct iguana_m
return(len);
}
int32_t iguana_rwzsolution(int32_t rwflag,uint8_t *serialized,uint32_t *solution,int32_t n)
int32_t iguana_rwzsolution(int32_t rwflag,uint8_t *serialized,uint8_t *solution,int32_t n)
{
int32_t i,len = 0;
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
for (i=0; i<n; i++)
len += iguana_rwnum(rwflag,&serialized[len],sizeof(solution[i]),&solution[i]);
return(len);
}
int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgblock *msg)
int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgzblock *zmsg)
{
uint32_t tmp; int32_t len = 0;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.version),&msg->H.version);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.prev_block),msg->H.prev_block.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.merkle_root),msg->H.merkle_root.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.timestamp),&msg->H.timestamp);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.bits),&msg->H.bits);
uint32_t tmp; struct iguana_msgblock *msg = (void *)zmsg; int32_t len = 0;
if ( zcash == 0 )
{
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.version),&msg->H.version);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.prev_block),msg->H.prev_block.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.merkle_root),msg->H.merkle_root.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.timestamp),&msg->H.timestamp);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.bits),&msg->H.bits);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.nonce),&msg->H.nonce);
}
else
{
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->zH.bignonce),msg->zH.bignonce.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(zmsg->zH.version),&zmsg->zH.version);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.prev_block),zmsg->zH.prev_block.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.merkle_root),zmsg->zH.merkle_root.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.reserved),zmsg->zH.reserved.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(zmsg->zH.timestamp),&zmsg->zH.timestamp);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(zmsg->zH.bits),&zmsg->zH.bits);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.bignonce),zmsg->zH.bignonce.bytes);
//char str[65]; printf("prev.(%s) len.%d [%d %d %d]\n",bits256_str(str,msg->H.prev_block),len,serialized[len],serialized[len+1],serialized[len+2]);
if ( rwflag != 0 )
tmp = msg->zH.numelements;
len += iguana_rwvarint32(rwflag,&serialized[len],(uint32_t *)&tmp);
if ( rwflag == 0 )
msg->zH.numelements = tmp;
if ( msg->zH.numelements != ZCASH_SOLUTION_ELEMENTS )
memcpy(&serialized[len],zmsg->zH.var_numelements,sizeof(zmsg->zH.var_numelements));
else memcpy(zmsg->zH.var_numelements,&serialized[len],sizeof(zmsg->zH.var_numelements));
//printf("numelements: (%02x %02x %02x)\n",serialized[len],serialized[len+1],serialized[len+2]);
len += sizeof(zmsg->zH.var_numelements);
if ( iguana_rwvarint32(0,zmsg->zH.var_numelements,(uint32_t *)&tmp) != sizeof(zmsg->zH.var_numelements) )
printf("rw.%d unexpected varint size for zmsg.zH.numelements <- %d %d %d\n",rwflag,zmsg->zH.var_numelements[0],zmsg->zH.var_numelements[1],zmsg->zH.var_numelements[2]);
if ( tmp != ZCASH_SOLUTION_ELEMENTS )
{
int32_t i; for (i=0; i<157; i++)
printf("%02x",serialized[i]);
printf(" unexpected ZCASH_SOLUTION_ELEMENTS, got %d vs %d len.%d\n",msg->zH.numelements,ZCASH_SOLUTION_ELEMENTS,len);
printf(" rw.%d unexpected ZCASH_SOLUTION_ELEMENTS, (%02x %02x %02x) expected %d tmp.%d len.%d\n",rwflag,zmsg->zH.var_numelements[0],zmsg->zH.var_numelements[1],zmsg->zH.var_numelements[2],ZCASH_SOLUTION_ELEMENTS,tmp,len);
return(-1);
}
len += iguana_rwzsolution(rwflag,&serialized[len],msg->zH.solution,ZCASH_SOLUTION_ELEMENTS);
len += iguana_rwzsolution(rwflag,&serialized[len],zmsg->zH.solution,tmp);
}
return(len);
}
int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *serialized,int32_t maxlen)
int32_t iguana_eatauxpow(struct supernet_info *myinfo,int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *serialized,int32_t maxlen)
{
int32_t len = 0; void *ptr; struct iguana_msgtx msg; struct OS_memspace MEM; bits256 auxhash2,coinbasetxid; struct iguana_msgmerkle *coinbase_branch,*blockchain_branch; struct iguana_msgblock parentblock; struct iguana_info *coin;
if ( rwflag == 0 && (coin= iguana_coinfind(symbol)) != 0 && coin->chain->auxpow != 0 )
@ -142,7 +152,7 @@ int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *seri
memset(&MEM,0,sizeof(MEM));
ptr = calloc(1,1000000);
iguana_meminit(&MEM,"auxpow",ptr,1000000,0);
len += iguana_rwtx(coin->chain->zcash,rwflag,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->isPoS,0);
len += iguana_rwtx(myinfo,coin->chain->zcash,rwflag,coin,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->isPoS,0);
if ( len > maxlen )
return(-1);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(auxhash2),auxhash2.bytes);
@ -154,7 +164,7 @@ int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *seri
len += iguana_rwmerklebranch(rwflag,&serialized[len],blockchain_branch);
if ( len > maxlen )
return(-1);
len += iguana_rwblockhdr(rwflag,zcash,&serialized[len],&parentblock);
len += iguana_rwblockhdr(rwflag,zcash,&serialized[len],(void *)&parentblock);
if ( len > maxlen )
return(-1);
free(ptr);
@ -164,7 +174,7 @@ int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *seri
return(len);
}
int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)//,uint8_t *serialized,int32_t maxlen)
int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)
{
int32_t len = 0;
if ( zcash == 0 )
@ -175,59 +185,83 @@ int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)//,uint8_t
return(sizeof(struct iguana_msgblockhdr) + len);
//else
return(-1);
} else return((int32_t)(sizeof(struct iguana_msgblockhdr) - sizeof(uint32_t) + sizeof(struct iguana_msgblockhdr_zcash) + auxpow*sizeof(bits256)));
} else return((int32_t)(sizeof(struct iguana_msgzblockhdr) + auxpow*sizeof(bits256)));
}
int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg,int32_t maxlen)
int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgzblock *zmsg,int32_t maxlen)
{
int32_t len = 0; uint64_t x;
if ( (len= iguana_rwblockhdr(rwflag,zcash,serialized,msg)) < 0 )
int32_t len = 0; uint64_t x; struct iguana_msgblock *msg = (void *)zmsg;
if ( (len= iguana_rwblockhdr(rwflag,zcash,serialized,zmsg)) < 0 )
{
printf("error rw.%d blockhdr zcash.%d\n",rwflag,zcash);
int32_t i;
for (i=0; i<maxlen&&i<sizeof(struct iguana_zblock); i++)
printf("%02x",serialized[i]);
printf(" error rw.%d blockhdr zcash.%d\n",rwflag,zcash);
return(-1);
}
*hash2p = iguana_calcblockhash(symbol,hashalgo,serialized,len);
//char str[65],str2[65]; printf("zcash.%d len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx hash2.%s\n",zcash,len,msg->H.version,msg->H.timestamp,msg->H.bits,msg->H.nonce,bits256_str(str,msg->H.prev_block),(long long)msg->H.merkle_root.txid,bits256_str(str2,*hash2p));
if ( auxpow != 0 && (msg->H.version & 0x100) != 0 )
len += iguana_eatauxpow(rwflag,symbol,zcash,&serialized[len],maxlen-len);
len += iguana_eatauxpow(myinfo,rwflag,symbol,zcash,&serialized[len],maxlen-len);
if ( rwflag == 1 )
x = msg->txn_count;
{
if ( zcash == 0 )
x = zmsg->txn_count;
else x = msg->txn_count;
}
//char str[65],str2[65]; printf("zcash.%d len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx hash2.%s zlen.%d\n",zcash,len,msg->H.version,msg->H.timestamp,msg->H.bits,msg->H.nonce,bits256_str(str,msg->H.prev_block),(long long)msg->H.merkle_root.txid,bits256_str(str2,*hash2p),(int32_t)sizeof(struct iguana_msgzblockhdr));
len += iguana_rwvarint(rwflag,&serialized[len],&x);
if ( rwflag == 0 )
{
char str[65];
bits256_str(str,*hash2p);
if ( x < 65536 )
msg->txn_count = (uint16_t)x;
else printf("txn_count overflow.%lld for %s\n",(long long)x,str);
{
if ( zcash != 0 )
zmsg->txn_count = (uint16_t)x;
else msg->txn_count = (uint16_t)x;
} else printf("txn_count overflow.%lld for %s\n",(long long)x,str);
}
// ? txns tx[] Block transactions, in format of "tx" command
return(len);
}
int32_t iguana_serialize_block(struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block)
int32_t iguana_serialize_block(struct supernet_info *myinfo,struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgzblock)],struct iguana_block *block)
{
struct iguana_msgblock msg; int32_t i,len;
memset(&msg,0,sizeof(msg));
msg.H.version = block->RO.version;
msg.H.prev_block = block->RO.prev_block;
msg.H.merkle_root = block->RO.merkle_root;
msg.H.timestamp = block->RO.timestamp;
msg.H.bits = block->RO.bits;
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; struct iguana_zblock *zblock; int32_t i,len;
if ( chain->zcash == 0 )
msg.H.nonce = block->RO.nonce;
{
memset(msg,0,sizeof(*msg));
msg->H.version = block->RO.version;
msg->H.prev_block = block->RO.prev_block;
msg->H.merkle_root = block->RO.merkle_root;
msg->H.timestamp = block->RO.timestamp;
msg->H.bits = block->RO.bits;
msg->H.nonce = block->RO.nonce;
msg->txn_count = block->RO.txn_count;
len = iguana_rwblock(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,&zmsg,IGUANA_MAXPACKETSIZE);
}
else
{
if ( block->RO.allocsize == sizeof(struct iguana_zblock) )
memset(&zmsg,0,sizeof(zmsg));
zblock = (void *)block;
zmsg.zH.version = zblock->RO.version;
zmsg.zH.prev_block = zblock->RO.prev_block;
zmsg.zH.merkle_root = zblock->RO.merkle_root;
zmsg.zH.timestamp = zblock->RO.timestamp;
zmsg.zH.bits = zblock->RO.bits;
zmsg.zH.bignonce = zblock->zRO.bignonce;
if ( iguana_rwvarint32(1,zmsg.zH.var_numelements,(uint32_t *)&zblock->zRO.numelements) != sizeof(zmsg.zH.var_numelements) )
{
// printf("unexpected varint size for zmsg.zH.numelements <- %d %d %d\n",zmsg.zH.var_numelements[0],zmsg.zH.var_numelements[1],zmsg.zH.var_numelements[2]);
}
if ( zblock->zRO.numelements == ZCASH_SOLUTION_ELEMENTS )
{
msg.zH.bignonce = block->zRO[0].bignonce;
msg.zH.numelements = ZCASH_SOLUTION_ELEMENTS;
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
msg.zH.solution[i] = block->zRO[0].solution[i];
} else printf("iguana_serialize_block has missing zRO\n");
zmsg.zH.solution[i] = zblock->zRO.solution[i];
zmsg.txn_count = block->RO.txn_count;
len = iguana_rwblock(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,(void *)&zmsg,IGUANA_MAXPACKETSIZE);
} else return(-1);
}
msg.txn_count = block->RO.txn_count;
len = iguana_rwblock(chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,&msg,IGUANA_MAXPACKETSIZE);
return(len);
}
@ -310,17 +344,15 @@ int32_t iguana_rwmsgalert(struct iguana_info *coin,int32_t rwflag,uint8_t *seria
void iguana_gotversion(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgversion *vers)
{
uint8_t serialized[sizeof(struct iguana_msghdr)]; char *retstr;
uint8_t serialized[sizeof(struct iguana_msghdr)];
//printf("gotversion from %s: starting height.%d services.%llx proto.%d (%s)\n",addr->ipaddr,vers->nStartingHeight,(long long)vers->nServices,vers->nVersion,vers->strSubVer);
if ( 0 && strncmp(vers->strSubVer,"/iguana",strlen("/iguana")) == 0 )
{
if ( strncmp(vers->strSubVer,"/iguana",strlen("/iguana")) == 0 )
addr->supernet = 1, addr->basilisk = 0;
if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)addr->ipbits,GENESIS_PUBKEY)) != 0 )
free(retstr);
}
else if ( strncmp(vers->strSubVer,"/basilisk",strlen("/basilisk")) == 0 )
{
addr->basilisk = 1, addr->supernet = 0;
if ( (vers->nServices & NODE_NETWORK) != 0 )
}
//if ( (vers->nServices & NODE_NETWORK) != 0 )
{
addr->protover = (vers->nVersion < PROTOCOL_VERSION) ? vers->nVersion : PROTOCOL_VERSION;
//printf("(%s) proto.%d -> %d\n",addr->ipaddr,vers->nVersion,addr->protover);
@ -328,11 +360,8 @@ void iguana_gotversion(struct supernet_info *myinfo,struct iguana_info *coin,str
addr->height = vers->nStartingHeight;
addr->relayflag = 1;
iguana_gotdata(coin,addr,addr->height);
iguana_queue_send(addr,0,serialized,"verack",0);
//iguana_send_ping(coin,addr);
}
else if ( 0 && addr->supernet == 0 && addr->basilisk == 0 )//|| (addr->basilisk != 0 && myinfo->IAMRELAY == 0) )
addr->dead = (uint32_t)time(NULL);
iguana_queue_send(addr,0,serialized,"verack",0);
if ( addr->supernet != 0 || addr->basilisk != 0 )
printf("height.%d nServices.%lld nonce.%llu %srelay node.(%s) supernet.%d basilisk.%d longest.%u\n",vers->nStartingHeight,(long long)vers->nServices,(long long)vers->nonce,addr->relayflag==0?"non-":"",addr->ipaddr,addr->supernet,addr->basilisk,vers->nStartingHeight);
if ( (int32_t)vers->nStartingHeight > coin->longestchain )
@ -343,6 +372,8 @@ void iguana_gotversion(struct supernet_info *myinfo,struct iguana_info *coin,str
addr->dead = 1;
} //else coin->longestchain = vers->nStartingHeight;
}
if ( addr->msgcounts.verack == 0 && time(NULL) > addr->ready+600 )
iguana_send_version(coin,addr,coin->myservices);
iguana_queue_send(addr,0,serialized,"getaddr",0);
}
@ -398,7 +429,8 @@ void iguana_gotverack(struct supernet_info *myinfo,struct iguana_info *coin,stru
uint8_t serialized[sizeof(struct iguana_msghdr)];
if ( addr != 0 )
{
//printf("gotverack from %s\n",addr->ipaddr);
if ( addr->supernet != 0 || addr->basilisk != 0 )
printf(">>>>>>>>>> supernet.%d basilisk.%d gotverack from %s\n",addr->supernet,addr->basilisk,addr->ipaddr);
addr->A.nTime = (uint32_t)time(NULL);
iguana_queue_send(addr,0,serialized,"getaddr",0);
iguana_supernet_ping(myinfo,coin,addr);
@ -423,8 +455,8 @@ void iguana_gotaddr(struct iguana_info *coin,struct iguana_peer *addr,struct igu
}
if ( strcmp(coin->symbol,"BTC") != 0 || (rand() % 10) == 0 )
iguana_possible_peer(coin,ipport);
if ( 0 && strncmp("BTC",coin->symbol,3) != 0 )
printf("%s\n",ipaddr);
if ( 0 && strcmp("TAZ",coin->symbol) == 0 )
printf("iguana_gotaddr: %s from %s\n",ipaddr,addr->ipaddr);
}
void iguana_gotping(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,uint64_t nonce,uint8_t *data)
@ -440,6 +472,11 @@ void iguana_gotping(struct supernet_info *myinfo,struct iguana_info *coin,struct
int32_t iguana_send_ping(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr)
{
int32_t len; uint64_t nonce; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(nonce)];
if ( addr->msgcounts.verack == 0 )
{
printf("%s send version instead of ping to %s\n",coin->symbol,addr->ipaddr);
return(iguana_send_version(coin,addr,coin->myservices));
}
if ( (nonce= addr->pingnonce) == 0 )
{
OS_randombytes((uint8_t *)&nonce,sizeof(nonce));
@ -507,7 +544,7 @@ int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type
}
int32_t debugtest;
int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg)
int32_t iguana_rwvin(int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg,int32_t vini)
{
int32_t len = 0; uint32_t tmp;
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->prev_hash),msg->prev_hash.bytes);
@ -518,7 +555,9 @@ int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,
if ( rwflag == 0 )
{
msg->scriptlen = tmp;
msg->vinscript = iguana_memalloc(mem,msg->scriptlen,1);
if ( msg->scriptlen < IGUANA_MAXSCRIPTSIZE )
msg->vinscript = iguana_memalloc(mem,msg->scriptlen,1);
else return(0);
}
len += iguana_rwmem(rwflag,&serialized[len],msg->scriptlen,msg->vinscript);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->sequence),&msg->sequence);
@ -538,7 +577,7 @@ int32_t iguana_rwvout(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->value),&msg->value);
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->pk_scriptlen);
if ( msg->pk_scriptlen > IGUANA_MAXSCRIPTSIZE )
return(-1);
return(0);
if ( rwflag == 0 )
msg->pk_script = iguana_memalloc(mem,msg->pk_scriptlen,1);
len += iguana_rwmem(rwflag,&serialized[len],msg->pk_scriptlen,msg->pk_script);
@ -577,7 +616,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj
return(len);
}
int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin)
int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin)
{
int32_t i,n,len = 0; uint8_t *txstart = serialized; char txidstr[65];
if ( maxsize < sizeof(msg->version) )
@ -604,7 +643,7 @@ int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t
return(-1);
}
}
if ( (n= iguana_rwvin(rwflag,mem,&serialized[len],&msg->vins[i])) >= 0 )
if ( (n= iguana_rwvin(rwflag,coin,mem,&serialized[len],&msg->vins[i],i)) >= 0 )
len += n;
if ( n < 0 || len+sizeof(int32_t) > maxsize )
{
@ -623,9 +662,9 @@ int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t
msg->vouts = iguana_memalloc(mem,msg->tx_out * sizeof(*msg->vouts),1);
for (i=0; i<msg->tx_out; i++)
{
if ( (n= iguana_rwvout(rwflag,mem,&serialized[len],&msg->vouts[i])) >= 0 )
if ( (n= iguana_rwvout(rwflag,mem,&serialized[len],&msg->vouts[i])) > 0 )
len += n;
if ( n < 0 || len > maxsize )
if ( n <= 0 || len > maxsize )
{
printf("invalid tx_out.%d len.%d vs maxsize.%d\n",msg->tx_out,len,maxsize);
return(-1);
@ -639,48 +678,96 @@ int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t
for (; serialized[len]!=0&&len<maxsize; len++) // eat null terminated string
;
}
if ( zcash != 0 && msg->version == 2 )
if ( zcash != 0 && msg->version > 1 )
{
uint32_t numjoinsplits; struct iguana_msgjoinsplit joinsplit; uint8_t joinsplitpubkey[33],joinsplitsig[64];
len += iguana_rwvarint32(rwflag,&serialized[len],&numjoinsplits);
char str[65];
printf("numjoinsplits.%d version.%d numvins.%d numvouts.%d locktime.%u %s\n",numjoinsplits,msg->version,msg->tx_in,msg->tx_out,msg->lock_time,bits256_str(str,*txidp));
if ( numjoinsplits > 0 )
{
for (i=0; i<numjoinsplits; i++)
len += iguana_rwjoinsplit(rwflag,&serialized[len],&joinsplit);
if ( rwflag != 0 )
{
memset(joinsplitpubkey,0,sizeof(joinsplitpubkey)); // for now
memset(joinsplitsig,0,sizeof(joinsplitsig)); // set to actuals
memcpy(&serialized[len],joinsplitpubkey+1,32), len += 32;
memcpy(&serialized[len],joinsplitsig,64), len += 64;
}
else
{
joinsplitpubkey[0] = 0x02; // need to verify its not 0x03
memcpy(joinsplitpubkey+1,&serialized[len],32), len += 32;
memcpy(joinsplitsig,&serialized[len],64), len += 64;
}
}
if ( rwflag != 0 )
if ( 0 )
{
memcpy(&serialized[len],joinsplitpubkey,33), len += 33;
memcpy(&serialized[len],joinsplitsig,64), len += 64;
*txidp = bits256_doublesha256(txidstr,txstart,len);
char str[65];
printf("[%ld] numjoinsplits.%d version.%d numvins.%d numvouts.%d locktime.%u %s\n",sizeof(joinsplit),numjoinsplits,msg->version,msg->tx_in,msg->tx_out,msg->lock_time,bits256_str(str,*txidp));
}
}
*txidp = bits256_doublesha256(txidstr,txstart,len);
msg->allocsize = len;
if ( coin->VALIDATENODE > 1 && rwflag == 0 && coin->RTheight > 0 )
{
int32_t sigsvalid; struct iguana_block *block;
if ( (block= iguana_blockfind("sig",coin,msg->txid)) != 0 && block->sigsvalid != 0 )
sigsvalid = 1;
else if ( iguana_validatesigs(myinfo,coin,txstart,len) == 0 )
sigsvalid = 1;
else
{
memcpy(joinsplitpubkey,&serialized[len],33), len += 33;
memcpy(joinsplitsig,&serialized[len],64), len += 64;
static FILE *fp;
if ( block != 0 )
block->sigsvalid = 1;
if ( fp == 0 )
fp = fopen("validates","wb");
if ( fp != 0 )
{
char str[65];
printf("error %s validating\n",bits256_str(str,*txidp));
for (i=0; i<len; i++)
{
printf("%02x",txstart[i]);
fprintf(fp,"%02x",txstart[i]);
}
printf(" len.%d\n\n",len);
fprintf(fp,"\n");
fflush(fp);
}
}
//return(0);
}
*txidp = bits256_doublesha256(txidstr,txstart,len);
msg->allocsize = len;
return(len);
}
char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid)
char *iguana_txscan(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid)
{
struct iguana_msgtx tx; bits256 hash2; struct iguana_block *block; struct iguana_msgblock msg;
int32_t i,n,len,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace,blockspace[sizeof(*block)+sizeof(*block->zRO)];
struct iguana_msgtx tx; bits256 hash2; struct iguana_zblock *zblock; struct iguana_block *block; struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg;
int32_t i,n,len,txn_count,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace,blockspace[sizeof(*block)+sizeof(struct iguana_zblock)];
zblock = (void *)blockspace;
block = (void *)blockspace;
memset(&msg,0,sizeof(msg));
memset(&zmsg,0,sizeof(zmsg));
vpnstr[0] = 0;
extraspace = calloc(1,extralen);
len = iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,block,&msg,hash2,-1);
for (i=0; i<msg.txn_count; i++)
if ( coin->chain->zcash == 0 )
{
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,(void *)msg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)block,(void *)msg,hash2,-1);
txn_count = msg->txn_count;
}
else
{
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,(void *)&zmsg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,zblock,&zmsg,hash2,-1);
txn_count = zmsg.txn_count;
}
for (i=0; i<txn_count; i++)
{
if ( (n= iguana_rwmsgtx(coin,coin->blocks.hwmchain.height,0,0,&data[len],recvlen - len,&tx,&tx.txid,vpnstr,extraspace,extralen,0,0)) < 0 )
break;
char str[65]; printf("%d of %d: %s len.%d\n",i,msg.txn_count,bits256_str(str,tx.txid),len);
char str[65]; printf("%d of %d: %s len.%d\n",i,txn_count,bits256_str(str,tx.txid),len);
if ( bits256_cmp(txid,tx.txid) == 0 )
{
if ( (n= iguana_rwmsgtx(coin,coin->blocks.hwmchain.height,0,json,&data[len],recvlen - len,&tx,&tx.txid,vpnstr,extraspace,extralen,0,0)) > 0 )
@ -696,30 +783,30 @@ char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t r
return(0);
}
int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txdata,int32_t *lenp,uint8_t *data,int32_t recvlen)
int32_t iguana_gentxarray(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txdata,int32_t *lenp,uint8_t *data,int32_t recvlen)
{
struct iguana_msgtx *tx; bits256 hash2; struct iguana_msgblock msg; int32_t i,n,hdrlen,len,numvouts,numvins; char str[65];
memset(&msg,0,sizeof(msg));
len = iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen);
struct iguana_msgtx *tx; bits256 hash2; struct iguana_msgzblock zmsg; int32_t txn_count,i,n,hdrlen,len,numvouts,numvins; char str[65];
memset(&zmsg,0,sizeof(zmsg));
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,(void *)&zmsg,recvlen);
hdrlen = len;
if ( len > recvlen )
{
printf("gentxarray error len.%d > recvlen.%d\n",len,recvlen);
return(-1);
}
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(struct iguana_block *)&txdata->zblock,&msg,hash2,-1);
txn_count = iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)&txdata->zblock,&zmsg,hash2,-1);
numvins = numvouts = 0;
if ( msg.txn_count > 0 )
if ( txn_count > 0 )
{
tx = iguana_memalloc(mem,msg.txn_count*sizeof(*tx),1);
for (i=0; i<msg.txn_count; i++)
tx = iguana_memalloc(mem,txn_count*sizeof(*tx),1);
for (i=0; i<txn_count; i++)
{
if ( len+32 > recvlen )
{
printf("gentxarrayB error len.%d > recvlen.%d\n",len,recvlen);
return(-1);
}
if ( (n= iguana_rwtx(coin->chain->zcash,0,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 )
if ( (n= iguana_rwtx(myinfo,coin->chain->zcash,0,coin,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 )
{
//for (i=0; i<recvlen-hdrlen; i++)
// printf("%02x",data[hdrlen+i]);
@ -739,9 +826,9 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc
} else txdata->extralen = 0;
}
if ( coin->chain->auxpow != 0 && len != recvlen )
printf("numtx.%d %s hdrlen.%d len.%d vs recvlen.%d v.%08x\n",msg.txn_count,bits256_str(str,hash2),hdrlen,len,recvlen,txdata->zblock.RO.version);
printf("numtx.%d %s hdrlen.%d len.%d vs recvlen.%d v.%08x\n",txn_count,bits256_str(str,hash2),hdrlen,len,recvlen,txdata->zblock.RO.version);
txdata->recvlen = len;
txdata->numtxids = msg.txn_count;
txdata->numtxids = txn_count;
txdata->numunspents = numvouts;
txdata->numspends = numvins;
return(len);
@ -834,10 +921,9 @@ int32_t iguana_intvectors(struct iguana_info *coin,struct iguana_peer *addr,int3
//printf("intvectors.%c recvlen.%d\n",intvectors,recvlen);
}
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache)
int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache)
{
uint8_t serialized[16384]; char *ipaddr; struct supernet_info *myinfo = SuperNET_MYINFO(0);
int32_t i,n=0,retval=-1,ishost,srvmsg,bloom,sendlen=0,intvectors,len= -100; uint64_t nonce,x; bits256 hash2;
uint8_t serialized[16384]; char *ipaddr; int32_t i,n=0,retval=-1,ishost,srvmsg,bloom,sendlen=0,intvectors,len= -100; uint64_t nonce,x; bits256 hash2;
bloom = intvectors = srvmsg = -1;
if ( strncmp(H->command+1,"uperNET",strlen("uperNET")) == 0 || strncmp(H->command,"uperNet",strlen("uperNet")) == 0 )
{
@ -856,8 +942,8 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
}
if ( addr != 0 )
{
if ( 0 && strcmp("DOGE",coin->symbol) == 0 )
printf("iguana_msgparser from (%s) parse.(%s) len.%d\n",addr->ipaddr,H->command,recvlen);
if ( 0 && addr->msgcounts.verack == 0 )
printf("iguana_msgparser verack.%d from (%s) parse.(%s) len.%d\n",addr->msgcounts.verack,addr->ipaddr,H->command,recvlen);
//iguana_peerblockrequest(coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,iguana_blockhash(coin,100),0);
addr->lastcontact = (uint32_t)time(NULL);
strcpy(addr->lastcommand,H->command);
@ -871,17 +957,19 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
memset(&txdata,0,sizeof(txdata));
if ( ishost == 0 )
{
if ( 0 && coin->chain->auxpow != 0 )
if ( coin->chain->debug != 0 )
{
int32_t i; for (i=0; i<recvlen; i++)
int32_t i,max;
max = coin->chain->zcash == 0 ? 80 : sizeof(struct iguana_msgzblockhdr);
for (i=0; i<max; i++)
printf("%02x",data[i]);
printf(" auxblock\n");
printf(" block.[%d]\n",max);
}
addr->msgcounts.block++;
if ( (n= iguana_gentxarray(coin,rawmem,&txdata,&len,data,recvlen)) == recvlen || n == recvlen-1 )
if ( (n= iguana_gentxarray(myinfo,coin,rawmem,&txdata,&len,data,recvlen)) == recvlen || n == recvlen-1 )
{
len = n;
iguana_gotblockM(coin,addr,&txdata,rawmem->ptr,H,data,recvlen,fromcache);
iguana_gotblockM(myinfo,coin,addr,&txdata,rawmem->ptr,H,data,recvlen,fromcache);
}
else
{
@ -917,7 +1005,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
}
else if ( (ishost= (strcmp(H->command,"getheaders") == 0)) || strcmp(H->command,"headers") == 0 )
{
struct iguana_msgblock msg; struct iguana_zblock *zblocks; uint32_t tmp,n=0;
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; struct iguana_zblock *zblocks; uint32_t tmp,n=0;
len = 0;
if ( addr != 0 && recvlen >= sizeof(bits256) && strcmp("BTCD",coin->symbol) != 0 )
{
@ -926,9 +1014,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
len = iguana_rwvarint32(0,data,&n);
if ( n <= IGUANA_MAXINV )
{
bits256 auxhash2,prevhash2; struct iguana_msgtx *tx; struct iguana_msgmerkle *coinbase_branch,*blockchain_branch; struct iguana_msgblock parentblock;
coinbase_branch = calloc(1,sizeof(*coinbase_branch));
blockchain_branch = calloc(1,sizeof(*blockchain_branch));
bits256 auxhash2,prevhash2; struct iguana_msgtx *tx; struct iguana_msgmerkle *coinbase_branch=0,*blockchain_branch=0; struct iguana_msgblock parentblock;
if ( rawmem->totalsize == 0 )
iguana_meminit(rawmem,"bighdrs",0,IGUANA_MAXPACKETSIZE * 2,0);
memset(prevhash2.bytes,0,sizeof(prevhash2));
@ -938,29 +1024,36 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
{
if ( coin->chain->auxpow != 0 )
{
tmp = iguana_rwblockhdr(0,coin->chain->zcash,&data[len],&msg);
if ( coinbase_branch == 0 )
coinbase_branch = calloc(1,sizeof(*coinbase_branch));
if ( blockchain_branch == 0 )
blockchain_branch = calloc(1,sizeof(*blockchain_branch));
tmp = iguana_rwblockhdr(0,coin->chain->zcash,&data[len],(void *)msg);
hash2 = iguana_calcblockhash(coin->symbol,coin->chain->hashalgo,&data[len],tmp);
len += tmp;
if ( (msg.H.version & 0x100) != 0 )
if ( (msg->H.version & 0x100) != 0 )
{
iguana_memreset(rawmem);
tx = iguana_memalloc(rawmem,sizeof(*tx),1);
len += iguana_rwtx(coin->chain->zcash,0,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0);
len += iguana_rwtx(myinfo,coin->chain->zcash,0,coin,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0);
len += iguana_rwbignum(0,&data[len],sizeof(auxhash2),auxhash2.bytes);
len += iguana_rwmerklebranch(0,&data[len],coinbase_branch);
len += iguana_rwmerklebranch(0,&data[len],blockchain_branch);
len += iguana_rwblockhdr(0,coin->chain->zcash,&data[len],&parentblock);
len += iguana_rwblockhdr(0,coin->chain->zcash,&data[len],(void *)&parentblock);
}
len += iguana_rwvarint32(0,&data[len],&tmp);
char str[65],str2[65];
if ( 0 && coin->chain->auxpow != 0 )
printf("%d %d of %d: %s %s v.%08x numtx.%d cmp.%d\n",len,i,n,bits256_str(str,hash2),bits256_str(str2,msg.H.prev_block),msg.H.version,tmp,bits256_cmp(prevhash2,msg.H.prev_block));
} else len += iguana_rwblock(coin->chain->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,&data[len],&msg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(struct iguana_block *)&zblocks[i],&msg,hash2,-1);
printf("%d %d of %d: %s %s v.%08x numtx.%d cmp.%d\n",len,i,n,bits256_str(str,hash2),bits256_str(str2,zmsg.zH.prev_block),zmsg.zH.version,tmp,bits256_cmp(prevhash2,zmsg.zH.prev_block));
}
else len += iguana_rwblock(myinfo,coin->chain->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,&data[len],(void *)&zmsg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)&zblocks[i],&zmsg,hash2,-1);
prevhash2 = hash2;
}
free(coinbase_branch);
free(blockchain_branch);
if ( coinbase_branch != 0 )
free(coinbase_branch);
if ( blockchain_branch != 0 )
free(blockchain_branch);
if ( iguana_gotheadersM(coin,addr,zblocks,n) < 0 )
myfree(zblocks,(int32_t)(sizeof(struct iguana_zblock) * n));
//myfree(blocks,sizeof(*blocks) * n);
@ -1093,7 +1186,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
struct iguana_msgtx *tx;
iguana_memreset(rawmem);
tx = iguana_memalloc(rawmem,sizeof(*tx),1);//mycalloc('u',1,sizeof(*tx));
len = iguana_rwtx(coin->chain->zcash,0,rawmem,data,tx,recvlen,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0);
len = iguana_rwtx(myinfo,coin->chain->zcash,0,coin,rawmem,data,tx,recvlen,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0);
if ( addr != 0 )
{
iguana_gotunconfirmedM(coin,addr,tx,data,recvlen);
@ -1114,9 +1207,9 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
addr->headerserror++;
else
{
for (i=0; i<recvlen; i++)
for (i=0; i<recvlen&&i<100; i++)
printf("%02x ",data[i]);
printf("reject.(%s) recvlen.%d %s proto.%d\n",data+1,recvlen,addr->ipaddr,addr->protover);
printf("%s reject.(%s) recvlen.%d %s proto.%d\n",coin->symbol,data+1,recvlen,addr->ipaddr,addr->protover);
addr->msgcounts.reject++;
}
}

170
iguana/iguana_payments.c

@ -218,7 +218,7 @@ cJSON *iguana_inputjson(bits256 txid,int32_t vout,uint8_t *spendscript,int32_t s
cJSON *iguana_RTinputsjson(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,uint64_t amount,struct iguana_outpoint *unspents,int32_t num)
{
cJSON *vins; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE]; struct iguana_txid *T; struct iguana_unspent *U,*u; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; char coinaddr[64]; int32_t vout,height,abovei,belowi,i,spendlen,ind; uint32_t txidind; struct iguana_ramchaindata *rdata; bits256 txid; int64_t above,below,total = 0; struct iguana_outpoint outpt; int64_t remains = amount;
struct iguana_outpoint outpt; cJSON *vins; int32_t abovei,belowi,i,ind; int64_t above,below,total = 0,remains = amount;
*totalp = 0;
vins = cJSON_CreateArray();
for (i=0; i<num; i++)
@ -235,6 +235,13 @@ cJSON *iguana_RTinputsjson(struct supernet_info *myinfo,struct iguana_info *coin
else ind = belowi;
outpt = unspents[ind];
memset(&unspents[ind],0,sizeof(unspents[ind]));
jaddi(vins,iguana_inputjson(outpt.txid,outpt.vout,outpt.spendscript,outpt.spendlen));
total += outpt.value;
remains -= outpt.value;
//printf("%s value %.8f -> remains %.8f\n",coinaddr,dstr(value),dstr(remains));
if ( remains <= 0 )
break;
/*continue;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 )
{
if ( (spendlen= basilisk_unspentfind(myinfo,coin,&txid,&vout,spendscript,outpt,outpt.value)) > 0 )
@ -274,7 +281,7 @@ cJSON *iguana_RTinputsjson(struct supernet_info *myinfo,struct iguana_info *coin
u = &U[outpt.unspentind];
if ( (txidind= u->txidind) > 0 && txidind < rdata->numtxids )
{
if ( iguana_unspentindfind(myinfo,coin,coinaddr,spendscript,&spendlen,&amount,&height,T[txidind].txid,u->vout,coin->bundlescount-1,0) == outpt.unspentind && spendlen > 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt2,coinaddr,spendscript,&spendlen,&amount,&height,T[txidind].txid,u->vout,coin->bundlescount-1,0) == 0 && spendlen > 0 )
{
jaddi(vins,iguana_inputjson(T[txidind].txid,u->vout,spendscript,spendlen));
total += outpt.value;
@ -302,7 +309,7 @@ cJSON *iguana_RTinputsjson(struct supernet_info *myinfo,struct iguana_info *coin
printf("%s illegal unspentind.u%d [%d]\n",coin->symbol,outpt.unspentind,outpt.hdrsi);
free_json(vins);
return(0);
}
}*/
}
*totalp = total;
return(vins);
@ -374,6 +381,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
free(unspents);
return(0);
}
printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount));
if ( txobj != 0 && avail >= satoshis+txfee )
{
if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num)) != 0 )
@ -442,25 +450,25 @@ void iguana_RTunspentslock(struct supernet_info *myinfo,struct iguana_info *coin
}
}
char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *coinaddr,uint64_t satoshis,uint64_t txfee,char *comment,char *comment2,int32_t minconf,char *account)
char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *destaddr,uint64_t satoshis,uint64_t txfee,char *comment,char *comment2,int32_t minconf,char *account)
{
uint8_t addrtype,spendscript[1024],rmd160[20]; int32_t completed; char *retstr,spendscriptstr[4096],*rawtx=0,*signedtx = 0; bits256 signedtxid,senttxid; cJSON *retjson,*vins,*addresses,*valsobj; uint32_t spendlen,locktime = 0; uint32_t basilisktag;
//sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] <amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful. Y
if ( coin->RTheight == 0 )
return(clonestr("{\"error\":\"need to get to realtime blocks to send transaction\"}"));
if ( account == 0 || account[0] == 0 )
account = "*";
addresses = iguana_getaddressesbyaccount(myinfo,coin,account);
if ( coin->changeaddr[0] == 0 )
{
//if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 )
// return(clonestr("{\"error\":\"no change address specified\"}"));
bitcoin_address(coin->changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
printf("%s change %s\n",coin->symbol,coin->changeaddr);
}
if ( coinaddr != 0 && coinaddr[0] != 0 && satoshis != 0 )
if ( destaddr != 0 && destaddr[0] != 0 && satoshis != 0 )
{
if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 )
if ( iguana_addressvalidate(coin,&addrtype,destaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
init_hexbytes_noT(spendscriptstr,spendscript,spendlen);
basilisktag = (uint32_t)rand();
@ -678,12 +686,12 @@ INT_ARRAY_STRING(bitcoinrpc,addmultisigaddress,M,pubkeys,account) //
HASH_AND_TWOINTS(bitcoinrpc,gettxout,txid,vout,mempool)
{
uint8_t script[IGUANA_MAXSCRIPTSIZE],rmd160[20],pubkey33[33]; char coinaddr[128],asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; struct iguana_bundle *bp; int32_t minconf,scriptlen,unspentind,height,spentheight; int64_t RTspend; int64_t value; struct iguana_ramchaindata *rdata; struct iguana_pkhash *P; struct iguana_txid *T; struct iguana_unspent *U; struct iguana_outpoint outpt; struct iguana_ramchain *ramchain; cJSON *scriptobj,*retjson = cJSON_CreateObject();
uint8_t script[IGUANA_MAXSCRIPTSIZE],rmd160[20],pubkey33[33]; char coinaddr[128],asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; struct iguana_bundle *bp; int32_t minconf,scriptlen,unspentind,height,spentheight; struct iguana_RTtxid *ptr; int64_t RTspend; int64_t value; struct iguana_ramchaindata *rdata; struct iguana_pkhash *P; struct iguana_txid *T; struct iguana_unspent *U; struct iguana_outpoint outpt; struct iguana_ramchain *ramchain; cJSON *scriptobj,*retjson = cJSON_CreateObject();
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( coin != 0 )
{
if ( (value= _RTgettxout(coin,&height,&scriptlen,script,rmd160,coinaddr,txid,vout,mempool)) > 0 )
if ( (value= _RTgettxout(coin,&ptr,&height,&scriptlen,script,rmd160,coinaddr,txid,vout,mempool)) > 0 )
{
jaddbits256(retjson,"bestblock",coin->blocks.hwmchain.RO.hash2);
jaddnum(retjson,"bestheight",coin->blocks.hwmchain.height);
@ -699,8 +707,9 @@ HASH_AND_TWOINTS(bitcoinrpc,gettxout,txid,vout,mempool)
return(jprint(retjson,1));
}
minconf = (mempool != 0) ? 0 : 1;
if ( (unspentind= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,txid,vout,coin->bundlescount-1,0)) != 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,0,0,0,0,&height,txid,vout,coin->bundlescount-1,0) == 0 && outpt.isptr == 0 )
{
unspentind = outpt.unspentind;
if ( height >= 0 && height < coin->longestchain && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 )
{
ramchain = &bp->ramchain;
@ -847,12 +856,16 @@ int64_t iguana_txdetails(struct supernet_info *myinfo,struct iguana_info *coin,c
if ( vout >= 0 )
{
jaddnum(item,"vout",vout);
if ( (amount= iguana_txidamount(myinfo,coin,txid,vout)) != 0 )
if ( (amount= iguana_txidamount(myinfo,coin,coinaddr,txid,vout)) != 0 )
jaddnum(item,"amount",dstr(amount));
jaddstr(item,"category",iguana_txidcategory(myinfo,coin,account,coinaddr,txid,vout));
}
else
{
if ( vout == -1 )
jadd(item,"coinbase",jtrue());
vout = 0;
}
else if ( vout == -1 )
jadd(item,"coinbase",jtrue());
jaddstr(item,"category",iguana_txidcategory(myinfo,coin,account,coinaddr,txid,vout));
if ( account[0] != 0 && jobj(item,"account") == 0 )
jaddstr(item,"account",account);
if ( coinaddr[0] != 0 )
@ -896,7 +909,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose)
free(txbytes);
if ( txobj != 0 )
{
iguana_txdetails(myinfo,coin,txobj,tx->txid,-2,height);
iguana_txdetails(myinfo,coin,txobj,checktxid,-2,height);
return(jprint(txobj,1));
}
}
@ -918,7 +931,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose)
datalen = (int32_t)(strlen(blockstr) >> 1);
data = malloc(datalen);
decode_hex(data,datalen,blockstr);
if ( (txbytes= iguana_txscan(coin,verbose != 0 ? retjson : 0,data,datalen,txid)) != 0 )
if ( (txbytes= iguana_txscan(myinfo,coin,verbose != 0 ? retjson : 0,data,datalen,txid)) != 0 )
{
jaddstr(retjson,"result",txbytes);
jaddbits256(retjson,"blockhash",blockhash);
@ -949,7 +962,7 @@ int64_t iguana_lockval(int32_t finalized,int64_t locktime)
char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,char *rawtx,int32_t mempool,int32_t suppress_pubkeys)
{
bits256 signedtxid,txid; struct iguana_msgvin vin; cJSON *log,*vins,*vouts,*txobj,*retjson; char *checkstr,*signedtx; int32_t finalized = 1,i,len,maxsize,numinputs,numoutputs,complete; struct vin_info *V; uint8_t *serialized,*serialized2; uint32_t sigsize,pubkeysize,p2shsize,suffixlen; int64_t inputsum,outputsum,lockval;
bits256 signedtxid,txid; struct iguana_outpoint outpt; struct iguana_msgvin vin; cJSON *log,*vins,*vouts,*txobj,*retjson; char *checkstr,*signedtx; int32_t plen,finalized = 1,i,len,maxsize,numinputs,numoutputs,complete; struct vin_info *V; uint8_t *serialized,*serialized2; uint32_t sigsize,pubkeysize,p2shsize,suffixlen; int64_t inputsum,outputsum,lockval;
retjson = cJSON_CreateObject();
inputsum = outputsum = numinputs = numoutputs = 0;
if ( rawtx != 0 && rawtx[0] != 0 && coin != 0 )
@ -960,8 +973,9 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin
if ( (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&msgtx->txid,msgtx,rawtx,extraspace,extralen,0,0,suppress_pubkeys)) != 0 )
{
//printf("txobj.(%s)\n",jprint(txobj,0));
if ( (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 )
if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 )
{
// no guarantee byte for byte identical tx is recreated
if ( strcmp(rawtx,checkstr) != 0 )
{
jaddstr(retjson,"error","converting from hex2json and json2hex mismatch");
@ -972,7 +986,7 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin
break;
jaddnum(retjson,"mismatch position",i);
jadd(retjson,"origtx",txobj);
if ( (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,msgtx,checkstr,extraspace,extralen,0,0,suppress_pubkeys)) != 0 )
if ( 0 && (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,msgtx,checkstr,extraspace,extralen,0,0,suppress_pubkeys)) != 0 )
jadd(retjson,"checktx",txobj);
free(checkstr);
return(jprint(retjson,1));
@ -998,34 +1012,48 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin
for (i=0; i<numinputs; i++)
{
len += iguana_parsevinobj(myinfo,coin,&serialized[len],maxsize-len,&vin,jitem(vins,i),&V[i]);
if ( (V[i].unspentind= iguana_RTunspentindfind(myinfo,coin,V[i].coinaddr,V[i].spendscript,&V[i].spendlen,&V[i].amount,&V[i].height,msgtx->vins[i].prev_hash,msgtx->vins[i].prev_vout,coin->bundlescount-1,mempool)) > 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,V[i].coinaddr,V[i].spendscript,&V[i].spendlen,&V[i].amount,&V[i].height,msgtx->vins[i].prev_hash,msgtx->vins[i].prev_vout,coin->bundlescount-1,mempool) == 0 )
{
V[i].suppress_pubkeys = suppress_pubkeys;
V[i].unspentind = outpt.unspentind;
inputsum += V[i].amount;
msgtx->vins[i].spendscript = V[i].spendscript;
msgtx->vins[i].spendlen = V[i].spendlen;
if ( (msgtx->vins[i].spendlen= V[i].spendlen) == 35 )
{
if ( (plen= bitcoin_pubkeylen(msgtx->vins[i].spendscript+1)) > 0 )
{
memcpy(V[i].signers[0].pubkey,msgtx->vins[i].spendscript+1,plen);
V[i].suppress_pubkeys = 1;
}
}
V[i].hashtype = iguana_vinscriptparse(coin,&V[i],&sigsize,&pubkeysize,&p2shsize,&suffixlen,msgtx->vins[i].vinscript,msgtx->vins[i].scriptlen);
//if ( (V[i].signers[0].siglen= sigsize) > 0 )
// memcpy(V[i].signers[0].sig,msgtx->vins[i].vinscript+1,sigsize);
V[i].userdatalen = suffixlen;
memcpy(V[i].spendscript,msgtx->vins[i].spendscript,msgtx->vins[i].spendlen);
V[i].spendlen = msgtx->vins[i].spendlen;
if ( msgtx->vins[i].sequence < IGUANA_SEQUENCEID_FINAL )
finalized = 0;
//printf("V %.8f (%s) spendscript.[%d] scriptlen.%d\n",dstr(V[i].amount),V[i].coinaddr,V[i].spendlen,V[i].spendlen);
}
}
V[0].suppress_pubkeys = suppress_pubkeys;
if ( (complete= bitcoin_verifyvins(coin,height,&signedtxid,&signedtx,msgtx,serialized2,maxsize,V,1,0,suppress_pubkeys)) > 0 && signedtx != 0 )
{
msgtx->txid = signedtxid;
log = cJSON_CreateArray();
lockval = iguana_lockval(finalized,jint(txobj,"locktime"));
if ( iguana_interpreter(coin,log,lockval,V,numinputs) < 0 )
{
jaddstr(retjson,"error","interpreter rejects tx");
}
jadd(retjson,"interpreter",log);
if ( V[i].M == 0 )
V[i].M = 1;
if ( V[i].N < V[i].M )
V[i].N = V[i].M;
//printf("V %dof%d %.8f (%s) spendscript.[%d] scriptlen.%d\n",V[i].M,V[i].N,dstr(V[i].amount),V[i].coinaddr,V[i].spendlen,V[i].spendlen);
} else printf("couldnt find spendscript\n");
}
complete = 0;
bitcoin_verifyvins(coin,height,&signedtxid,&signedtx,msgtx,serialized2,maxsize,V,1,0,suppress_pubkeys);
msgtx->txid = signedtxid;
log = cJSON_CreateArray();
lockval = iguana_lockval(finalized,jint(txobj,"locktime"));
if ( iguana_interpreter(coin,log,lockval,V,numinputs) < 0 )
jaddstr(retjson,"error","interpreter rejects tx");
else complete = 1;
jadd(retjson,"interpreter",log);
jaddnum(retjson,"complete",complete);
free(serialized), free(serialized2);
if ( signedtx != 0 )
free(signedtx);
}
}
//char str[65]; printf("got txid.(%s)\n",bits256_str(str,txid));
@ -1043,26 +1071,46 @@ STRING_AND_INT(bitcoinrpc,validaterawtransaction,rawtx,suppress)
uint8_t *extraspace; int32_t extralen=65536; char *retstr; struct iguana_msgtx msgtx;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
//cJSON *txobj; char *teststr= "{\"version\":1,\"locktime\":0,\"vin\":[{\"userdata\":\"20fe936da3707c8c4cc7eb0352160ec3f50b9454d46425df6347b2fbc5b2ec87ea00\",\"txid\":\"ee12e50b629d5d45438570fff841d1a2ba7d27f356de4aa06900c9a5e38cf141\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a9145cc47cc123e3f9b7dce0230009b9d3013a9e0c9687\"},\"suppress\":1,\"redeemScript\":\"6304165daa57b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a9143805600256ed8498ca1ec426759212e5835e8dc2882103a7b696908f77d69ec89887f8c4a0423b9e80b5974dc43301bd7d8abad07e1211ac68\"}],\"vout\":[{\"satoshis\":\"21821\",\"scriptPubkey\":{\"hex\":\"76a9143ef4734c1141725c095342095f6e0e7748b6c16588ac\"}}]}";
//cJSON *txobj; char *teststr= "{\"version\":1,\"locktime\":0,\"vin\":[{\"userdata\":\"206efad760ee54b9b2e2a038a821ef9f950eb0e248545ac202c3e2074cd14f92cb00\",\"txid\":\"3f4759381a62154f2f0eefed1e4433342548ad7b269f912820383b715a39273c\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a91446dcccef39c1d8c6da2ccc35dce2bfa7ec0d168887\"},\"suppress\":1,\"redeemScript\":\"63041c60aa57b1752103175cf93574c31637b8c2d8acd5319e3cd23761b5e418d32c6bcb194972ba9273ac67a9142d75daf71325feaa593b8f30989e462892189914882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68\"}],\"vout\":[{\"satoshis\":\"18625\",\"scriptPubkey\":{\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\"}}]}";
// 01000000013c27395a713b382028919f267bad48253433441eedef0e2f4f15621a3859473f00000000d147304402207ecd423b55c1aa45a994c4eb4337ff0891692fbb69954a9ba024745a99c5272d02207cea696425feb5388153ab7f2608d66a66e4c95cfda2d44e98bc56e25994d3f701206efad760ee54b9b2e2a038a821ef9f950eb0e248545ac202c3e2074cd14f92cb004c6763041c60aa57b1752103175cf93574c31637b8c2d8acd5319e3cd23761b5e418d32c6bcb194972ba9273ac67a9142d75daf71325feaa593b8f30989e462892189914882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68ffffffff01c1480000000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000
// 01000000013c27395a713b382028919f267bad48253433441eedef0e2f4f15621a3859473f00000000fd8b00206efad760ee54b9b2e2a038a821ef9f950eb0e248545ac202c3e2074cd14f92cb004c6763041c60aa57b1752103175cf93574c31637b8c2d8acd5319e3cd23761b5e418d32c6bcb194972ba9273ac67a9142d75daf71325feaa593b8f30989e462892189914882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68ffffffff01c1480000000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000
//cJSON *txobj; char *teststr= "{\"version\":1,\"locktime\":0,\"vin\":[{\"userdata\":\"20ae439d344513eab8e718d8214fe6ae8133b8b5b594afd64da21d0e40b9c37cdd00\",\"txid\":\"2c1320315f4fb519cbf2b4d7b67855013b9a09a85e515df43b41d407a0083b09\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a9142e7674400d04217f770f2222126dc7fee44b06b487\"},\"suppress\":1,\"redeemScript\":\"63041686a657b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a914ed74c61c27656abc6c20687c3a9212ffdc6f34cd88210398a4cb9f6ea7c52a4e27455028a95e2e4e397a110fb75f072c2c58a8bdcbf4baac68\"}],\"vout\":[{\"satoshis\":\"16733\",\"scriptPubkey\":{\"hex\":\"76a91454a752f0d71b89d7c014ed0be29ca231c9546f9f88ac\"}}]}";
extraspace = calloc(1,extralen);
/*if ( (txobj= cJSON_Parse(teststr)) != 0 )
{
bits256 txid;
rawtx = bitcoin_json2hex(myinfo,coin,&txid,txobj,0);
txobj = bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,0,rawtx,extraspace,extralen,0,0,suppress);
printf("RAWTX.(%s) -> (%s)\n",rawtx,jprint(txobj,0));
}*/
retstr = iguana_validaterawtx(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,extraspace,extralen,rawtx,0,suppress);
free(extraspace);
return(rawtx);
}
int32_t iguana_validatesigs(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t datalen)
{
uint8_t *extraspace; cJSON *retjson; int32_t extralen=65536; char *retstr,*rawtx; struct iguana_msgtx msgtx; int32_t suppress=0,retval = -1;
rawtx = calloc(1,datalen*2 + 1);
init_hexbytes_noT(rawtx,serialized,datalen);
extraspace = calloc(1,extralen);
for (suppress=0; suppress<1; suppress++)
{
if ( (retstr= iguana_validaterawtx(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,extraspace,extralen,rawtx,0,suppress)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(retjson,"error") == 0 )
{
retval = 0;
//char str[65]; printf("%s %s sigs validated\n",coin->symbol,bits256_str(str,msgtx.txid));
coin->sigsvalidated++;
break;
}
else
{
printf("ERROR.(%s)\n",retstr);
coin->sigserrs++;
}
free_json(retjson);
}
free(retstr);
}
}
free(rawtx);
free(extraspace);
return(retval);
}
STRING_AND_INT(bitcoinrpc,decoderawtransaction,rawtx,suppress)
{
cJSON *txobj = 0; bits256 txid; uint8_t *extraspace; int32_t extralen = 65536;
@ -1091,7 +1139,7 @@ HASH_ARG(bitcoinrpc,gettransaction,txid)
cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *txobj,cJSON *vins)
{
int32_t i,n,vout,p2shlen=0,spendlen=0,unspentind,height; uint64_t satoshis; char coinaddr[128],pubkeystr[256],scriptstr[IGUANA_MAXSCRIPTSIZE*2],*str,*hexstr; cJSON *pubkeys,*item,*obj,*newvin,*newvins; uint32_t sequenceid; bits256 txid; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE],redeemscript[IGUANA_MAXSCRIPTSIZE]; struct iguana_waccount *wacct; struct iguana_waddress *waddr;
int32_t i,n,vout,p2shlen=0,spendlen=0,height; uint64_t satoshis; char coinaddr[128],pubkeystr[256],scriptstr[IGUANA_MAXSCRIPTSIZE*2],*str,*hexstr; cJSON *pubkeys,*item,*obj,*newvin,*newvins; uint32_t sequenceid; bits256 txid; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE],redeemscript[IGUANA_MAXSCRIPTSIZE]; struct iguana_waccount *wacct; struct iguana_waddress *waddr; struct iguana_outpoint outpt;
newvins = cJSON_CreateArray();
if ( (n= cJSON_GetArraySize(vins)) > 0 )
{
@ -1115,7 +1163,7 @@ cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,c
spendlen = (int32_t)strlen(hexstr) >> 1;
decode_hex(spendscript,spendlen,hexstr);
}
if ( (unspentind= iguana_RTunspentindfind(myinfo,coin,coinaddr,spendscript,&spendlen,&satoshis,&height,txid,vout,coin->bundlescount-1,0)) > 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,coinaddr,spendscript,&spendlen,&satoshis,&height,txid,vout,coin->bundlescount-1,0) == 0 )
{
//printf("[%d] unspentind.%d (%s) spendlen.%d %.8f\n",height/coin->chain->bundlesize,unspentind,coinaddr,spendlen,dstr(satoshis));
if ( coinaddr[0] != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
@ -1248,7 +1296,7 @@ TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array)
maxconf = (1 << 30);
if ( (argarray= array) == 0 || cJSON_GetArraySize(array) == 0 )
argarray = iguana_getaddressesbyaccount(myinfo,coin,"*");
retjson = iguana_RTlistunspent(myinfo,coin,argarray,minconf,maxconf,remoteaddr);
retjson = iguana_RTlistunspent(myinfo,coin,argarray,minconf,maxconf,remoteaddr,0);
if ( argarray != array )
free_json(argarray);
return(jprint(retjson,1));
@ -1265,7 +1313,7 @@ ZERO_ARGS(bitcoinrpc,getrawchangeaddress)
INT_AND_ARRAY(bitcoinrpc,lockunspent,flag,array)
{
struct iguana_outpoint outpt; int32_t RTspendflag,vout,i,n,height,spentheight,lockedflag; cJSON *item,*retjson; bits256 txid; uint32_t unspentind;
struct iguana_outpoint outpt; int32_t RTspendflag,vout,i,n,height,spentheight,lockedflag; cJSON *item,*retjson; bits256 txid;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
retjson = cJSON_CreateObject();
@ -1278,11 +1326,10 @@ INT_AND_ARRAY(bitcoinrpc,lockunspent,flag,array)
{
txid = jbits256(item,"txid");
vout = jint(item,"vout");
if ( (unspentind= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,txid,vout,coin->bundlescount-1,0)) != 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,0,0,0,0,&height,txid,vout,coin->bundlescount-1,0) == 0 )
{
memset(&outpt,0,sizeof(outpt));
outpt.hdrsi = height / coin->chain->bundlesize;
outpt.unspentind = unspentind;
//outpt.hdrsi = height / coin->chain->bundlesize;
//outpt.unspentind = unspentind;
iguana_RTutxofunc(coin,&spentheight,&lockedflag,outpt,&RTspendflag,!flag,0);
}
}
@ -1333,13 +1380,16 @@ DOUBLE_ARG(bitcoinrpc,settxfee,amount)
S_D_SS(bitcoinrpc,sendtoaddress,address,amount,comment,comment2)
{
char *retstr;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
myinfo->expiration++;
//iguana_unspentset(myinfo,coin);
return(sendtoaddress(myinfo,coin,remoteaddr,address,amount * SATOSHIDEN,coin->txfee,comment,comment2,coin->minconfirms,0));
if ( (retstr= sendtoaddress(myinfo,coin,remoteaddr,address,amount * SATOSHIDEN,coin->txfee,comment,comment2,coin->minconfirms,0)) != 0 )
printf("SEND.(%s)\n",retstr);
return(retstr);
}
SS_D_I_SS(bitcoinrpc,sendfrom,fromaccount,toaddress,amount,minconf,comment,comment2)

113
iguana/iguana_peers.c

@ -88,7 +88,10 @@ struct iguana_iAddr *_iguana_hashset(struct iguana_info *coin,uint32_t ipbits,in
ptr = iguana_memalloc(mem,allocsize,1);
else ptr = mycalloc('t',1,allocsize);
if ( ptr == 0 )
printf("fatal alloc errorA in hashset\n"), exit(-1);
{
printf("fatal alloc errorA in hashset\n");
iguana_exit(0,0);
}
//printf("ptr.%p allocsize.%d key.%p keylen.%d itemind.%d\n",ptr,allocsize,key,keylen,itemind);
ptr->hh.itemind = itemind;
ptr->ipbits = ipbits;
@ -114,7 +117,7 @@ struct iguana_iAddr *iguana_iAddrhashset(struct iguana_info *coin,struct iguana_
if ( iA == 0 || iA->ipbits == 0 )
{
printf("null iA.%p or ipbits.%llx ind.%d status.%d\n",iA,iA!=0?(long long)iA->ipbits:0,iA!=0?iA->hh.itemind:0,iA!=0?iA->status:0);
exit(-1);
iguana_exit(0,0);
return(0);
}
portable_mutex_lock(&coin->peers_mutex);
@ -189,7 +192,10 @@ uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana
{
ptr = mycalloc('t',1,sizeof(*ptr));
if ( ptr == 0 )
printf("fatal alloc errorB in hashset\n"), exit(-1);
{
printf("fatal alloc errorB in hashset\n");
iguana_exit(0,0);
}
ptr->hh.itemind = m;
ptr->ipbits = tmp.ipbits;
HASH_ADD(hh,coin->iAddrs,ipbits,sizeof(ipbits),ptr);
@ -361,10 +367,14 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
}
saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
//#ifdef WIN32
// saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1");
//#else
memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length);
expand_ipbits(checkipaddr,saddr.sin_addr.s_addr);
if ( strcmp(ipaddr,checkipaddr) != 0 )
printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr);
//#endif
if ( (sock= socket(AF_INET,SOCK_STREAM,0)) < 0 )
{
if ( errno != ETIMEDOUT )
@ -374,6 +384,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
opt = 1;
slen = sizeof(opt);
//printf("set keepalive.%d\n",setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,(void *)&opt,slen));
#ifndef WIN32
if ( 1 )//&& bindflag != 0 )
{
if ( 1 )
@ -389,6 +400,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
} else setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(void *)&opt,sizeof(opt));
#ifdef __APPLE__
setsockopt(sock,SOL_SOCKET,SO_NOSIGPIPE,&opt,sizeof(opt));
#endif
#endif
if ( bindflag == 0 )
{
@ -472,6 +484,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
//printf("skip.(%s) since no verack yet\n",cmdstr);
return(-1);
}
//printf("%s -> %s\n",cmdstr,addr->ipaddr);
if ( strcmp(cmdstr,"ping") == 0 )
addr->sendmillis = OS_milliseconds();
if ( len > IGUANA_MAXPACKETSIZE )
@ -504,7 +517,8 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
}
}
addr->totalsent += len;
//printf(" (%s) sent.%d bytes to %s\n",cmdstr,len,addr->ipaddr);// getchar();
if ( 0 && addr->basilisk != 0 )
printf("verack.%d (%s) sent.%d bytes to %s\n",addr->msgcounts.verack,cmdstr,len,addr->ipaddr);
return(len);
}
@ -514,7 +528,7 @@ int32_t iguana_queue_send(struct iguana_peer *addr,int32_t delay,uint8_t *serial
if ( addr == 0 )
{
printf("iguana_queue_send null addr\n");
exit(-1);
iguana_exit(0,0);
return(-1);
}
if ( (datalen= iguana_sethdr((void *)serialized,addr->netmagic,cmd,&serialized[sizeof(struct iguana_msghdr)],len)) < 0 )
@ -532,7 +546,8 @@ int32_t iguana_queue_send(struct iguana_peer *addr,int32_t delay,uint8_t *serial
packet->embargo.millis += delay;
}
memcpy(packet->serialized,serialized,datalen);
//printf("%p queue send.(%s) %d to (%s)\n",packet,serialized+4,datalen,addr->ipaddr);
if ( 0 && addr->basilisk != 0 )
printf("%p queue send.(%s) %d to (%s)\n",packet,serialized+4,datalen,addr->ipaddr);
queue_enqueue("sendQ",&addr->sendQ,&packet->DL,0);
return(datalen);
}
@ -566,23 +581,29 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len)
return(len);
}
void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache)
void iguana_peer_meminit(struct iguana_info *coin,struct iguana_peer *addr)
{
if ( addr->RAWMEM.ptr == 0 )
iguana_meminit(&addr->RAWMEM,addr->ipaddr,0,IGUANA_MAXPACKETSIZE * 2,0);
if ( addr->TXDATA.ptr == 0 )
iguana_meminit(&addr->TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE * 2,0);
if ( addr->HASHMEM.ptr == 0 )
iguana_meminit(&addr->HASHMEM,"HASHPTRS",0,256,0);//IGUANA_MAXPACKETSIZE*16,0);
//printf("Init %s memory %p %p %p\n",addr->ipaddr,addr->RAWMEM.ptr,addr->TXDATA.ptr,addr->HASHMEM.ptr);
iguana_memreset(&addr->RAWMEM);
iguana_memreset(&addr->TXDATA);
iguana_memreset(&addr->HASHMEM);
}
void iguana_parsebuf(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache)
{
struct iguana_msghdr checkH;
memset(&checkH,0,sizeof(checkH));
if ( iguana_sethdr(&checkH,coin->chain->netmagic,H->command,buf,len) > 0 && memcmp(&checkH,H,sizeof(checkH)) == 0 )
{
if ( strcmp(H->command,"block") == 0 || strcmp(H->command,"getblocks") == 0 || strcmp(H->command,"tx") == 0 )
{
if ( addr->RAWMEM.ptr == 0 )
iguana_meminit(&addr->RAWMEM,addr->ipaddr,0,IGUANA_MAXPACKETSIZE * 2,0);
if ( addr->TXDATA.ptr == 0 )
iguana_meminit(&addr->TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE * 2,0);
if ( addr->HASHMEM.ptr == 0 )
iguana_meminit(&addr->HASHMEM,"HASHPTRS",0,256,0);//IGUANA_MAXPACKETSIZE*16,0);
//printf("Init %s memory %p %p %p\n",addr->ipaddr,addr->RAWMEM.ptr,addr->TXDATA.ptr,addr->HASHMEM.ptr);
}
if ( iguana_msgparser(coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len,fromcache) < 0 || addr->dead != 0 )
iguana_peer_meminit(coin,addr);
if ( iguana_msgparser(myinfo,coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len,fromcache) < 0 || addr->dead != 0 )
{
printf("%p addr->dead.%d or parser break at %u\n",&addr->dead,addr->dead,(uint32_t)time(NULL));
addr->dead = (uint32_t)time(NULL);
@ -604,7 +625,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
}
}
void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen)
void _iguana_processmsg(struct supernet_info *myinfo,struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen)
{
int32_t len,recvlen; void *buf = _buf; struct iguana_msghdr H;
if ( (coin->peers != 0 && coin->peers->shuttingdown != 0) || addr->dead != 0 )
@ -638,7 +659,7 @@ void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_pee
return;
}
}
iguana_parsebuf(coin,addr,&H,buf,len,0);
iguana_parsebuf(myinfo,coin,addr,&H,buf,len,0);
if ( buf != _buf )
myfree(buf,len);
return;
@ -695,7 +716,7 @@ void iguana_startconnection(void *arg)
addr->addrind = (int32_t)(((long)addr - (long)&coin->peers->active[0]) / sizeof(*addr));
if ( addr->usock >= 0 )
{
printf("%s usock.%d skip connection\n",addr->ipaddr,addr->usock);
//printf("%s usock.%d skip connection\n",addr->ipaddr,addr->usock);
return;
}
if ( strcmp(coin->name,addr->coinname) != 0 )
@ -703,12 +724,6 @@ void iguana_startconnection(void *arg)
printf("iguana_startconnection.%s:%04x mismatched coin.%p (%s) vs (%s)\n",addr->ipaddr,coin->chain->portp2p,coin,coin->symbol,addr->coinname);
return;
}
if ( strcmp("85.25.217.233",addr->ipaddr) == 0 )
{
printf("temp blacklist %s\n",addr->ipaddr);
iguana_iAkill(coin,addr,1);
return;
}
//printf("%s iguana_startconnection.%s:%04x\n",coin->symbol,addr->ipaddr,coin->chain->portp2p);
if ( strcmp("127.0.0.1",addr->ipaddr) == 0 )//&& (coin->myservices & NODE_NETWORK) != 0 )
{
@ -716,7 +731,7 @@ void iguana_startconnection(void *arg)
printf("avoid self-loopback\n");
return;
}
//printf("startconnection.(%s) pending.%u usock.%d addrind.%d\n",addr->ipaddr,addr->pending,addr->usock,addr->addrind);
//printf(">>>>>>>> %s startconnection.(%s) pending.%u usock.%d addrind.%d\n",coin->symbol,addr->ipaddr,addr->pending,addr->usock,addr->addrind);
addr->pending = (uint32_t)time(NULL);
if ( (port= (uint16_t)(addr->ipbits >> 32)) == 0 )
port = coin->chain->portp2p;
@ -824,16 +839,15 @@ void iguana_launchpeer(struct iguana_info *coin,char *ipaddr,int32_t forceflag)
else printf("iguana_launchpeer skip %s\n",ipaddr);
}
void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA)
void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA,struct iguana_peer *addr)
{
struct iguana_peer *addr = 0;
if ( coin->virtualchain != 0 )
return(0);
if ( iA != 0 && iA->ipbits != 0 && iguana_numthreads(coin,1 << IGUANA_CONNTHREAD) < IGUANA_MAXCONNTHREADS && iA->status == IGUANA_PEER_ELIGIBLE )
{
//printf("%x\n",iA->ipbits);
//portable_mutex_unlock(&coin->peers_mutex);
if ( (addr= iguana_peerslot(coin,iA->ipbits,0)) != 0 )
if ( addr != 0 || (addr= iguana_peerslot(coin,iA->ipbits,0)) != 0 )
{
addr->ipbits = iA->ipbits;
//printf("pend.%d status.%d possible peer.(%s).%x threads %d %d %d %d\n",addr->pending,iA->status,addr->ipaddr,(uint32_t)addr->ipbits,iguana_numthreads(coin,0),iguana_numthreads(coin,1),iguana_numthreads(coin,2),iguana_numthreads(coin,3));
@ -863,7 +877,7 @@ void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA)
uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
{
char checkaddr[64]; uint64_t ipbits; uint32_t now = (uint32_t)time(NULL); int32_t i,n; struct iguana_iAddr *iA;
char checkaddr[64],_ipaddr[64]; uint64_t ipbits; uint32_t now = (uint32_t)time(NULL); int32_t i,n; struct iguana_iAddr *iA; struct iguana_peer *addr;
if ( coin->virtualchain != 0 || coin->peers == 0 )
return(0);
if ( ipaddr != 0 && ipaddr[0] != 0 && coin->peers != 0 )
@ -884,28 +898,24 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
return((uint32_t)time(NULL));
else if ( (ipaddr= queue_dequeue(&coin->possibleQ,1)) == 0 )
return((uint32_t)time(NULL));
safecopy(_ipaddr,ipaddr,sizeof(_ipaddr));
free_queueitem(ipaddr);
ipaddr = _ipaddr;
#ifdef IGUANA_DISABLEPEERS
if ( strcmp(ipaddr,"127.0.0.1") != 0 )
{
free_queueitem(ipaddr);
return((uint32_t)time(NULL));
}
#endif
ipbits = (uint32_t)calc_ipbits(ipaddr);
//printf("%s check possible peer.(%s)\n",coin->symbol,ipaddr);
if ( iguana_peerslot(coin,(uint32_t)ipbits,0) != 0 )
if ( (addr= iguana_peerslot(coin,(uint32_t)ipbits,0)) == 0 )
return((uint32_t)time(NULL));
for (i=n=0; i<IGUANA_MAXPEERS; i++)
/*for (i=n=0; i<IGUANA_MAXPEERS; i++)
{
if ( strcmp(ipaddr,coin->peers->active[i].ipaddr) == 0 )
{
//printf("(%s) already active\n",ipaddr);
free_queueitem(ipaddr);
return((uint32_t)time(NULL));
}
else if ( coin->peers->active[i].ipaddr[0] != 0 )
n++;
}
}*/
n = coin->peers->numranked;
if ( n >= coin->MAXPEERS-(coin->MAXPEERS>>3)-1 || coin->peers->numranked >= coin->MAXPEERS )
return((uint32_t)time(NULL));
if ( strncmp("0.0.0",ipaddr,5) != 0 && strcmp("0.0.255.255",ipaddr) != 0 && strcmp("1.0.0.0",ipaddr) != 0 )
@ -916,6 +926,7 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
ipaddr[i] = 0;
break;
}
//printf("%s check possible peer.(%s)\n",coin->symbol,ipaddr);
if ( (ipbits= calc_ipbits(ipaddr)) != 0 )
{
expand_ipbits(checkaddr,ipbits);
@ -931,14 +942,13 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
iA->status = IGUANA_PEER_ELIGIBLE;
if ( iguana_rwiAddrind(coin,1,iA,iA->hh.itemind) == 0 )
printf("error updating status for (%s) ind.%d\n",ipaddr,iA->hh.itemind);
iguana_iAddriterator(coin,iA);
iguana_iAddriterator(coin,iA,addr);
} else printf("ignore.(%s) lastconnect.%u lastkilled.%u numconnects.%d\n",ipaddr,iA->lastconnect,iA->lastkilled,iA->numconnects);
} else printf("skip.(%s) ind.%d status.%d\n",ipaddr,iA->hh.itemind,iA->status);
} else printf("cant find (%s) which should have been created\n",ipaddr);
} else printf("%s reject ipaddr.(%s) vs checkaddr.(%s)\n",coin->symbol,ipaddr,checkaddr);
}
}
free_queueitem(ipaddr);
return((uint32_t)time(NULL));
}
@ -950,7 +960,7 @@ void iguana_processmsg(void *ptr)
printf("iguana_processmsg cant find addr.%p symbol.%s\n",addr,addr!=0?addr->symbol:0);
return;
}
_iguana_processmsg(coin,addr->usock,addr,buf,sizeof(buf));
_iguana_processmsg(SuperNET_MYINFO(0),coin,addr->usock,addr,buf,sizeof(buf));
addr->startrecv = 0;
}
@ -981,7 +991,7 @@ int32_t iguana_pollsendQ(struct iguana_info *coin,struct iguana_peer *addr)
return(0);
}
int32_t iguana_pollrecv(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *buf,int32_t bufsize)
int32_t iguana_pollrecv(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,uint8_t *buf,int32_t bufsize)
{
#ifndef IGUANA_DEDICATED_THREADS
strcpy(addr->symbol,coin->symbol);
@ -992,7 +1002,7 @@ int32_t iguana_pollrecv(struct iguana_info *coin,struct iguana_peer *addr,uint8_
}
else
#endif
_iguana_processmsg(coin,addr->usock,addr,buf,bufsize);
_iguana_processmsg(myinfo,coin,addr->usock,addr,buf,bufsize);
return(1);
}
@ -1076,7 +1086,7 @@ int64_t iguana_peerfree(struct iguana_info *coin,struct iguana_peer *addr,void *
if ( iguana_memfree(mem,ptr,datalen) < 0 || (avail= iguana_peerallocated(coin,addr)) < 0 )
{
printf("iguana_peerfree: corrupted mem avail.%lld ptr.%p %d\n",(long long)avail,ptr,datalen);
exit(-1);
iguana_exit(myinfo);
}
return(avail);
}
@ -1190,8 +1200,9 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
}
else
{
sleep(1 + (rand() % 3));
//printf("greeting send version myservices.%llu to (%s)\n",(long long)coin->myservices,addr->ipaddr);
iguana_send_version(coin,addr,coin->myservices);
//printf("send version myservices.%llu to (%s)\n",(long long)coin->myservices,addr->ipaddr);
}
//sleep(1+(rand()%5));
run = 0;
@ -1202,7 +1213,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
if ( req->datalen != 0 )
{
//char str[65]; printf("CACHE.%p parse[%d] %s %s\n",req,req->recvlen,req->H.command,bits256_str(str,req->zblock.RO.hash2));
iguana_parsebuf(coin,addr,&req->H,req->serializeddata,req->recvlen,1);
iguana_parsebuf(myinfo,coin,addr,&req->H,req->serializeddata,req->recvlen,1);
} else printf("CACHE error no datalen\n");
coin->cachefreed++;
myfree(req,req->allocsize);
@ -1225,7 +1236,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
{
if ( (fds.revents & POLLIN) != 0 )
{
flag += iguana_pollrecv(coin,addr,buf,bufsize);
flag += iguana_pollrecv(myinfo,coin,addr,buf,bufsize);
if ( addr->dead != 0 )
{
printf("%s is dead\n",addr->ipaddr);

337
iguana/iguana_ramchain.c

@ -52,7 +52,10 @@ struct iguana_kvitem *iguana_hashsetPT(struct iguana_ramchain *ramchain,int32_t
printf("alloc.%d\n",allocsize);
}
if ( ptr == 0 )
printf("fatal alloc errorC in hashset\n"), exit(-1);
{
printf("fatal alloc errorC in hashset\n");
iguana_exit(0,0);
}
if ( 0 && ramchain->expanded && selector == 'T' )
printf("hashmem.%p selector.%c added.(%s) itemind.%x ptr.%p\n",ramchain->hashmem,selector,str,itemind,ptr);
if ( selector == 'T' )
@ -64,7 +67,10 @@ struct iguana_kvitem *iguana_hashsetPT(struct iguana_ramchain *ramchain,int32_t
if ( 0 && ramchain->expanded && selector == 'T' )
printf("selector.%c added.(%s) itemind.%x ptr.%p tmp.%p\n",selector,str,itemind,ptr,tmp);
if ( itemind == 0 )
printf("negative itemind\n"), exit(-1);
{
printf("negative itemind\n");
iguana_exit(0,0);
}
if ( 0 )
{
if ( selector == 'T' )
@ -72,7 +78,8 @@ struct iguana_kvitem *iguana_hashsetPT(struct iguana_ramchain *ramchain,int32_t
else HASH_FIND(hh,ramchain->pkhashes,key,keylen,tmp);
if ( tmp != ptr )
{
printf("(%s) hashmem.%p selector.%c %s search error %p != %p itemind.%x\n",str,ramchain->hashmem,selector,str,ptr,tmp,itemind), exit(-1);
printf("(%s) hashmem.%p selector.%c %s search error %p != %p itemind.%x\n",str,ramchain->hashmem,selector,str,ptr,tmp,itemind);
iguana_exit(0,0);
}
}
}
@ -106,8 +113,7 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,
if ( 0 && dispflag != 0 )
printf("iguana_peerfname %s error finding.(%s) spec.%p bp.%p\n",coin->symbol,bits256_str(str,hash2),bp!=0?bp->speculative:0,bp);
return(-2);
}
else bundlei++;
} else bundlei++;
}
hash2 = bp->hashes[0], *hdrsip = bp->hdrsi;
subdir = bp->bundleheight / IGUANA_SUBDIRDIVISOR;
@ -163,6 +169,7 @@ int32_t iguana_peerfile_exists(struct iguana_info *coin,struct iguana_peer *addr
#define RAMCHAIN_DESTARG dest,destB,destT,destU,destS,destP,destA,destX,destUx,destSx,destTXbits,destPKbits,destKspace
#define RAMCHAIN_DESTPTRS dest,&destB,&destT,&destU,&destS,&destP,&destA,&destX,&destUx,&destSx,&destTXbits,&destPKbits,&destKspace
#define RAMCHAIN_DESTDECLARE struct iguana_blockRO *destB; struct iguana_txid *destT; struct iguana_unspent20 *destU; struct iguana_spend256 *destS; struct iguana_pkhash *destP; struct iguana_account *destA; bits256 *destX; struct iguana_unspent *destUx; struct iguana_spend *destSx; uint8_t *destTXbits,*destPKbits,*destKspace;
#define RAMCHAIN_DESTZEROES destB = 0, destUx = 0, destSx = 0, destP = 0, destA = 0, destX = 0, destKspace = destTXbits = destPKbits = 0, destU = 0, destS = 0, destT = 0
uint32_t iguana_ramchain_addtxid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256 txid,int32_t numvouts,int32_t numvins,uint32_t locktime,uint32_t version,uint32_t timestamp,int16_t bundlei)
{
@ -177,7 +184,7 @@ uint32_t iguana_ramchain_addtxid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
{
if ( t->txidind != txidind || memcmp(t->txid.bytes,txid.bytes,sizeof(bits256)) != 0 || t->numvouts != numvouts || t->numvins != numvins || t->firstvout != ramchain->H.unspentind || t->firstvin != ramchain->H.spendind || t->locktime != locktime || t->version != version || t->timestamp != timestamp )
{
printf("iguana_ramchain_addtxid.RO: addtxid mismatch (%d %d %d %d %d) vs. (%d %d %d %d %d)\n",t->txidind,t->numvouts,t->numvins,t->firstvout,t->firstvin,txidind,numvouts,numvins,ramchain->H.unspentind,ramchain->H.spendind);
printf("iguana_ramchain_addtxid.RO: addtxid mismatch (%u %d %d %u %u) vs. (%d %d %d %d %d)\n",(uint32_t)t->txidind,t->numvouts,t->numvins,(uint32_t)t->firstvout,(uint32_t)t->firstvin,txidind,numvouts,numvins,ramchain->H.unspentind,ramchain->H.spendind);
//getchar();
return(0);
}
@ -192,7 +199,7 @@ uint32_t iguana_ramchain_addtxid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
t->locktime = locktime, t->version = version, t->timestamp = timestamp;
if ( t->txidind != txidind || t->firstvout != ramchain->H.unspentind || t->firstvin != ramchain->H.spendind || t->bundlei != bundlei )
{
printf("addtxid error: t->txidind %u != %u txidind || t->firstvout %u != %u ramchain->H.unspentind || t->firstvin %u != %u ramchain->H.spendind || t->bundlei %u != %u bundlei\n",t->txidind,txidind,t->firstvout,ramchain->H.unspentind,t->firstvin,ramchain->H.spendind,t->bundlei,bundlei);
printf("addtxid error: t->txidind %u != %u txidind || t->firstvout %u != %u ramchain->H.unspentind || t->firstvin %u != %u ramchain->H.spendind || t->bundlei %u != %u bundlei\n",(uint32_t)t->txidind,txidind,(uint32_t)t->firstvout,ramchain->H.unspentind,(uint32_t)t->firstvin,ramchain->H.spendind,(uint32_t)t->bundlei,bundlei);
return(0);
}
if ( ramchain->expanded != 0 && (rdata= ramchain->H.data) != 0 )
@ -225,7 +232,7 @@ uint32_t iguana_ramchain_addpkhash(struct iguana_info *coin,RAMCHAIN_FUNC,uint8_
if ( P[pkind].pkind != pkind ) //unspentind != 0 && (P[pkind].firstunspentind != unspentind ||
{
printf("iguana_ramchain_addpkhash error mismatched pkind.(%x %x) unspentind.%d\n",pkind,P[pkind].pkind,unspentind);
exit(-1);
iguana_exit(0,0);
return(0);
}
if ( memcmp(P[pkind].rmd160,rmd160,sizeof(P[pkind].rmd160)) != 0 )
@ -332,7 +339,15 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
fputc(0,addr->voutsfp), u->scriptpos++, scriptpos++;
if ( u->scriptpos != scriptpos || fwrite(script,1,scriptlen,addr->voutsfp) != scriptlen )
printf("error writing vout scriptlen.%d errno.%d or scriptpos.%lld != %u\n",scriptlen,errno,(long long)scriptpos,u->scriptpos);
else addr->dirty[0]++;
else
{
if ( coin->chain->fixit != 0 )
{
fflush(addr->voutsfp);
usleep(1000);
}
addr->dirty[0]++;
}
#ifdef __PNACL__
//portable_mutex_unlock(&mutex);
#endif
@ -341,14 +356,14 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
}
}
u->txidind = ramchain->H.txidind;
if ( 0 && vout > 0 )
if ( coin->chain->fixit != 0 && vout > 0 )
{
int32_t i; for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" rmd160 ");
for (i=0; i<20; i++)
printf("%02x",u->rmd160[i]);
char str[65]; printf(" u->rmd160 type.%d scriptlen.%d:%d (%s).v%d ht.%d\n",u->type,scriptlen,u->scriptlen,bits256_str(str,txid),vout,bp->bundleheight);
char str[65]; printf(" u->rmd160 type.%d scriptpos.%d scriptlen.%d:%d (%s).v%d ht.%d\n",u->type,u->scriptpos,scriptlen,u->scriptlen,bits256_str(str,txid),vout,bp->bundleheight);
}
}
return(unspentind);
@ -388,7 +403,7 @@ uint32_t iguana_ramchain_addunspent(struct iguana_info *coin,RAMCHAIN_FUNC,uint6
if ( u->fileid != fileid || u->scriptpos != fpos || u->scriptlen != scriptlen || u->value != value || u->pkind != pkind || u->value != value || u->txidind != ramchain->H.txidind || (pkind != 0 && u->prevunspentind != A[pkind].lastunspentind) || u->vout != vout || u->hdrsi != hdrsi )
{
printf("iguana_ramchain_addunspent: (%d %d %d) vs (%d %d %d) mismatched values.(%d %.8f %d %d %d %d) vs (%d %.8f %d %d %d %d)\n",u->fileid,u->scriptpos,u->scriptlen,fileid,fpos,scriptlen,u->pkind,dstr(u->value),u->txidind,u->prevunspentind,u->vout,u->hdrsi,pkind,dstr(value),ramchain->H.txidind,A[pkind].lastunspentind,vout,hdrsi);
exit(-1);
iguana_exit(0,0);
return(0);
}
}
@ -483,7 +498,12 @@ uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
return(0);
}
} else printf("addspend illegal unspentind.%d vs %d\n",unspentind,rdata->numunspents);
} else printf("addspend illegal txidind.%d vs %d\n",txidind,rdata->numtxids), exit(-1);
}
else
{
printf("addspend illegal txidind.%d vs %d\n",txidind,rdata->numtxids);
iguana_exit(0,0);
}
}
if ( ramchain->H.ROflag != 0 )
{
@ -493,21 +513,6 @@ uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
char str[65],str2[65]; printf("ramchain_addspend RO value mismatch diffseq.%x v %x (%d) vs (%d) %s vs %s\n",s->sequenceid,sequence,s->prevout,prev_vout,bits256_str(str,txid),bits256_str(str2,prev_hash));
return(0);
}
/*if ( (checklen= iguana_vinscriptdecode(coin,ramchain,&metalen,_script,&Kspace[rdata->scriptspace],Kspace,s)) != vinscriptlen || (vinscript != 0 && memcmp(_script,vinscript,vinscriptlen) != 0) )
{
static uint64_t counter;
if ( counter++ < 100 )
{
for (i=0; i<checklen; i++)
printf("%02x",_script[i]);
printf(" decoded\n");
for (i=0; i<vinscriptlen; i++)
printf("%02x",vinscript[i]);
printf(" vinscript\n");
printf("A addspend: vinscript expand error (%d vs %d) %d\n",checklen,vinscriptlen,vinscript!=0?memcmp(_script,vinscript,vinscriptlen):0);
}
}*/
//ramchain->H.scriptoffset += metalen;
}
else
{
@ -517,36 +522,6 @@ uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
s->fileid = fileid;
s->scriptpos = scriptpos;
s->scriptlen = vinscriptlen;
/*static uint64_t good,bad;
if ( 0 && iguana_metascript(coin,RAMCHAIN_ARG,s,vinscript,vinscriptlen,0) < 0 )
{
static long errlen,err2len; char errbuf[1024];
errlen += vinscriptlen;
if ( iguana_metascript(coin,RAMCHAIN_ARG,s,vinscript,vinscriptlen,1) < 0 )
{
err2len += vinscriptlen;
errbuf[0] = 0;
for (i=0; i<vinscriptlen; i++)
sprintf(errbuf+strlen(errbuf),"%02x",vinscript[i]);
printf("%s <- second error with ",errbuf);
printf(" vinscript.%d errlens %ld %ld\n",vinscriptlen,errlen,err2len);
}
else if ( 0 && vinscriptlen > 138 )
{
errbuf[0] = 0;
for (i=0; i<vinscriptlen; i++)
sprintf(errbuf+strlen(errbuf),"%02x",vinscript[i]);
printf("%s bigscript ",errbuf);
}
bad += vinscriptlen;
} else good += vinscriptlen;
if ( 0 && (rand() % 100000) == 0 )
printf("good.%llu bad.%llu vinstats\n",(long long)good,(long long)bad);*/
//s->hdrsi = hdrsi;
//s->bundlei = bundlei;
//char str[65]; printf("%s set prevout.%d -> %d\n",bits256_str(str,prev_hash),prev_vout,s->prevout);
//if ( pkind != 0 )
// s->prevspendind = A[pkind].lastspendind;
}
if ( pkind != 0 )
{
@ -567,7 +542,7 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
{
if ( vinscriptlen != s->vinscriptlen || s->sequenceid != sequence || memcmp(s->prevhash2.bytes,prev_hash.bytes,sizeof(bits256)) != 0 || s->prevout != prev_vout ) //|| s->hdrsi != hdrsi
{
char str[65],str2[65]; printf("check offset %llu (%d %d) addspend.%d v %d RO value mismatch sequenceid.%x seq.%x prev_vout(%d vs %d) %s vs %s\n",(long long)s->scriptpos,vinscriptlen,s->vinscriptlen,spendind,s->spendind,s->sequenceid,sequence,s->prevout,prev_vout,bits256_str(str,s->prevhash2),bits256_str(str2,prev_hash));
char str[65],str2[65]; printf("check offset %llu (%d %d) addspend.%d v %d RO value mismatch sequenceid.%x seq.%x prev_vout(%d vs %d) %s vs %s\n",(long long)s->scriptpos,vinscriptlen,(int32_t)s->vinscriptlen,spendind,s->spendind,s->sequenceid,sequence,s->prevout,prev_vout,bits256_str(str,s->prevhash2),bits256_str(str2,prev_hash));
//printf("check addspend.%d vs %d RO value mismatch (%d %d:%d) vs (%d %d:%d)\n",spendind,s->spendind,s->prevout,s->hdrsi,s->bundlei,prev_vout,hdrsi,bundlei);
//exit(-1);
return(0);
@ -590,7 +565,15 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
fputc(0,addr->vinsfp), s->scriptpos++;
if ( (err= (int32_t)fwrite(vinscript,1,vinscriptlen,addr->vinsfp)) != vinscriptlen )
printf("error.%d writing vinscriptlen.%d errno.%d addrind.%d\n",err,vinscriptlen,errno,addr->addrind);
else addr->dirty[1]++;
else
{
addr->dirty[1]++;
if ( coin->chain->fixit != 0 )
{
fflush(addr->vinsfp);
usleep(1000);
}
}
#ifdef __PNACL__
//portable_mutex_unlock(&mutex);
#endif
@ -598,7 +581,7 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
//else printf("spend256 scriptfpos.%d\n",s->scriptfpos);
char str[65];
if ( 0 && coin->virtualchain != 0 )
printf("W.%p s.%d vout.%d/%d [%d] %s fpos.%u slen.%d\n",s,spendind,s->prevout,prev_vout,bp->hdrsi,bits256_str(str,prev_hash),(uint32_t)s->scriptpos,s->vinscriptlen);
printf("W.%p s.%d vout.%d/%d [%d] %s fpos.%u slen.%d\n",s,spendind,s->prevout,prev_vout,bp->hdrsi,bits256_str(str,prev_hash),(uint32_t)s->scriptpos,(int32_t)s->vinscriptlen);
}
return(spendind);
}
@ -689,6 +672,7 @@ void *iguana_ramchain_offset(char *fname,void *dest,uint8_t *lhash,FILE *fp,uint
#endif
startfpos = ftell(fp);
err = fwrite(srcptr,1,len,fp);
fflush(fp);
#ifdef __PNACL__
//portable_mutex_unlock(&mutex);
#endif
@ -985,7 +969,7 @@ int64_t iguana_ramchain_init(char *fname,struct iguana_ramchain *ramchain,struct
if ( rdata->allocsize != iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,scriptspace,zcash) )
{
printf("offset.%ld scriptspace.%d allocsize.%ld vs memsize.%ld\n",(long)offset,scriptspace,(long)rdata->allocsize,(long)iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,scriptspace,zcash));
exit(-1);
iguana_exit(0,0);
}
if ( offset <= mem->totalsize )
iguana_memreset(mem);
@ -1001,7 +985,7 @@ int64_t iguana_ramchain_init(char *fname,struct iguana_ramchain *ramchain,struct
if ( rdata->allocsize > mem->totalsize )
{
printf("init.(%d %d %d %d %d) rdata->allocsize.%ld mem->totalsize.%ld hashmemsize.%ld\n",numtxids,numunspents,numspends,numpkinds,numexternaltxids,(long)rdata->allocsize,mem->totalsize,hashmem!=0?hashmem->totalsize:0);
exit(-1);
iguana_exit(0,0);
}
return(offset);
}
@ -1023,7 +1007,7 @@ int32_t iguana_ramchain_alloc(char *fname,struct iguana_info *coin,struct iguana
char str[65],str2[65]; fprintf(stderr,"ht.%d wait for allocated %s < MAXMEM %s | elapsed %.2f minutes hashsize.%ld allocsize.%ld\n",height,mbstr(str,myallocated(0,-1)+hashsize+allocsize),mbstr(str2,coin->MAXMEM),(double)(time(NULL)-coin->startutc)/60.,(long)hashsize,(long)allocsize);
sleep(13);
}
iguana_meminit(hashmem,"ramhashmem",0,hashsize + 65536,0);
iguana_meminit(hashmem,"ramhashmem",0,2*hashsize + 65536,0);
iguana_meminit(mem,"ramchain",0,allocsize + 65536,0);
mem->alignflag = sizeof(uint32_t);
hashmem->alignflag = sizeof(uint32_t);
@ -1069,7 +1053,9 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
fpos = -1;
} else iguana_ramchain_saveaction(fname,RAMCHAIN_ARG,fp,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset,zcash);
*rdata = tmp;
fflush(fp);
fclose(fp);
//sleep(3);
}
#ifdef __PNACL__
//portable_mutex_unlock(&mutex);
@ -1092,18 +1078,18 @@ int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *
t = &T[ramchain->H.txidind];
if ( t->txidind != ramchain->H.txidind )
{
printf("firsti.%d t->txidind.%d != txidind.%d\n",rdata->firsti,t->txidind,ramchain->H.txidind);
printf("firsti.%d t->txidind.%u != txidind.%u\n",rdata->firsti,(uint32_t)t->txidind,(uint32_t)ramchain->H.txidind);
return(-1);
}
if ( t->firstvout != ramchain->H.unspentind )
{
printf("%p txidind.%d firstvout.%d != unspentind.%d\n",t,ramchain->H.txidind,t->firstvout,ramchain->H.unspentind);
printf("%p txidind.%u firstvout.%u != unspentind.%u\n",t,(uint32_t)ramchain->H.txidind,(uint32_t)t->firstvout,(uint32_t)ramchain->H.unspentind);
//exit(-1);
return(-4);
}
if ( t->firstvin != ramchain->H.spendind )
{
printf("t[%d] firstvin.%d vs spendind.%d\n",t->txidind,t->firstvin,ramchain->H.spendind);
printf("t[%u] firstvin.%u vs spendind.%d\n",(uint32_t)t->txidind,(uint32_t)t->firstvin,ramchain->H.spendind);
return(-5);
}
if ( ramchain->expanded != 0 )
@ -1227,7 +1213,7 @@ int32_t iguana_ramchain_free(struct iguana_info *coin,struct iguana_ramchain *ra
if ( ramchain->A != ramchain->creditsA )
{
//printf("hashmem.%p Free A %p %p, numpkinds.%d %ld\n",ramchain->hashmem,ramchain->A,ramchain->creditsA,rdata->numpkinds,sizeof(*ramchain->A) * rdata->numpkinds);
if ( deleteflag != 0 )
if ( deleteflag != 0 && ramchain->A != 0 )
myfree(ramchain->A,sizeof(*ramchain->A) * rdata->numpkinds), ramchain->A = 0;
}
//if ( ramchain->U2 != ramchain->roU2 )
@ -1294,7 +1280,7 @@ int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfi
struct iguana_bundle *bp; int32_t i; char fname[1024],str[65];
if ( hdrsi >= 0 && hdrsi < coin->bundlescount && (bp= coin->bundles[hdrsi]) != 0 )
{
printf("delete bundle.[%d]\n",hdrsi);
printf("%s delete bundle.[%d]\n",coin->symbol,hdrsi);
if ( tmpfiles != 0 )
{
for (i=0; i<bp->n; i++)
@ -1374,7 +1360,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
struct iguana_ramchain *_iguana_ramchain_map(struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded,uint8_t zcash)
{
RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi; long filesize; void *ptr; char str[65],str2[65],dirstr[64]; struct iguana_block *block; struct iguana_zblockRO zRO; struct iguana_ramchaindata *rdata;
RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi; long filesize; void *ptr; char str[65],str2[65],dirstr[65]; struct iguana_block *block; struct iguana_zblockRO zRO; struct iguana_ramchaindata *rdata;
/*if ( ramchain->expanded != 0 && (ramchain->sigsfileptr == 0 || ramchain->sigsfilesize == 0) )
{
sprintf(sigsfname,"sigs/%s/%s",coin->symbol,bits256_str(str,hash2));
@ -1630,7 +1616,7 @@ int32_t iguana_ramchain_cmp(struct iguana_ramchain *A,struct iguana_ramchain *B,
int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int16_t bundlei)
{
RAMCHAIN_DECLARE; RAMCHAIN_DESTDECLARE;
RAMCHAIN_DECLARE; RAMCHAIN_DESTDECLARE; RAMCHAIN_DESTZEROES;
int32_t j,hdrsi,prevout,scriptlen; uint32_t timestamp=0,unspentind,sequenceid,destspendind=0,desttxidind=0; uint16_t fileid; uint64_t scriptpos; int64_t crypto777_payment = 0;
bits256 prevhash; uint64_t value; uint8_t type; struct iguana_unspent *u;
struct iguana_txid *tx; struct iguana_ramchaindata *rdata; uint8_t rmd160[20];
@ -1830,88 +1816,22 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
return(0);
}
long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen)
long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,struct iguana_block *block)
{
static uint64_t totalrecv;
int32_t verifyflag = 0;
RAMCHAIN_DECLARE; uint32_t addr_ipbits; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,msize,sigsize,subdir,firsti=1,err,flag,bundlei = -2; bits256 merkle_root; struct iguana_bundle *bp = 0; struct iguana_block *block; uint32_t scriptspace,stackspace;
totalrecv += recvlen;
#ifdef __PNACL__
//verifyflag = 1;
#endif
if ( addr == 0 || (addr_ipbits= (uint32_t)addr->ipbits) == 0 )
addr_ipbits = 1;
if ( bits256_nonz(origtxdata->zblock.RO.merkle_root) == 0 )
RAMCHAIN_DECLARE; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,sigsize,subdir,firsti=1,err,flag,bundlei; uint32_t scriptspace,stackspace;
if ( block == 0 || bp == 0 || addr == 0 || (bundlei= block->bundlei) < 0 )
{
memset(&origtxdata->zblock.RO.prev_block,0,sizeof(bits256));
origtxdata->zblock.RO.recvlen = 0;
origtxdata->zblock.issued = 0;
printf("iguana_ramchain_data: null ptr %p %p %p\n",block,bp,addr);
return(-1);
}
if ( addr != 0 )
{
for (i=0; i<sizeof(addr->dirty)/sizeof(*addr->dirty); i++)
addr->dirty[i] = 0;
}
msize = (int32_t)sizeof(bits256) * (txn_count+1) * 2;
if ( msize <= addr->TXDATA.totalsize )
{
bits256 *tree = addr->TXDATA.ptr;
iguana_memreset(&addr->TXDATA);
for (i=0; i<txn_count; i++)
tree[i] = txarray[i].txid;
merkle_root = iguana_merkle(tree,txn_count);
if ( bits256_cmp(merkle_root,origtxdata->zblock.RO.merkle_root) != 0 )
{
char str[65],str2[65];
printf(">>>>>>>>>> %s %s merkle mismatch.[%d] calc.(%s) vs (%s)\n",addr->ipaddr,coin->symbol,txn_count,bits256_str(str,merkle_root),bits256_str(str2,origtxdata->zblock.RO.merkle_root));
origtxdata->zblock.RO.recvlen = 0;
origtxdata->zblock.issued = 0;
return(-1);
} //else printf("matched merkle.%d\n",txn_count);
} else printf("not enough memory for merkle verify %d vs %lu\n",(int32_t)(sizeof(bits256)*(txn_count+1)),(long)addr->TXDATA.totalsize);
bp = 0, bundlei = -2;
if ( iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.hash2) == 0 )
{
bp = 0, bundlei = -2;
if ( iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.prev_block) == 0 )
{
origtxdata->zblock.RO.recvlen = 0;
origtxdata->zblock.issued = 0;
return(-1);
}
else if ( bundlei < coin->chain->bundlesize-1 )
bundlei++;
else
{
origtxdata->zblock.issued = 0;
origtxdata->zblock.RO.recvlen = 0;
char str[65]; printf("ramchain data: error finding block %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
return(-1);
}
}
if ( (block= bp->blocks[bundlei]) == 0 || bits256_cmp(block->RO.hash2,origtxdata->zblock.RO.hash2) != 0 || bits256_cmp(bp->hashes[bundlei],origtxdata->zblock.RO.hash2) != 0 )
{
char str[65];
if ( 0 && block != 0 )
printf("%d:%d has no block ptr.%p %s or wrong hash\n",bp->hdrsi,bundlei,block,bits256_str(str,origtxdata->zblock.RO.hash2));
return(-1);
}
block->txvalid = 1;
if ( block->fpipbits != 0 && block->fpos >= 0 )
{
static int32_t numredundant; static double redundantsize; static uint32_t lastdisp;
char str[65],str2[65];
numredundant++, redundantsize += recvlen;
if ( time(NULL) > lastdisp+30 )
{
lastdisp = (uint32_t)time(NULL);
printf("ramchaindata have %d:%d at %d | %d blocks %s redundant xfers total %s %.2f%% wasted\n",bp->hdrsi,bundlei,block->fpos,numredundant,mbstr(str,redundantsize),mbstr(str2,totalrecv),100.*redundantsize/totalrecv);
}
return(block->fpos);
}
#ifdef __PNACL__
//verifyflag = 1;
#endif
sigsize = pubkeysize = 0;
scriptspace = 1;//iguana_scriptspaceraw(coin,&scriptsize,&sigsize,&pubkeysize,txarray,txn_count);
for (i=0; i<sizeof(addr->dirty)/sizeof(*addr->dirty); i++)
addr->dirty[i] = 0;
if ( iguana_ramchain_init(fname,ramchain,&addr->TXDATA,&addr->HASHMEM,1,txn_count,origtxdata->numunspents,origtxdata->numspends,0,0,(scriptspace+sigsize+pubkeysize)*1.1,0,1,coin->chain->zcash) == 0 )
{
if ( block->fpipbits == 0 )
@ -1976,18 +1896,18 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
iguana_blockzcopyRO(coin->chain->zcash,B,0,&block->RO,0);
rdata->scriptspace = ramchain->H.scriptoffset = scriptspace;
rdata->stackspace = ramchain->H.stacksize = stackspace;
if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,addr_ipbits,block->RO.hash2,block->RO.prev_block,bundlei,0,coin->chain->zcash)) >= 0 )
if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,(uint32_t)addr->ipbits,block->RO.hash2,block->RO.prev_block,bundlei,0,coin->chain->zcash)) >= 0 )
{
origtxdata->datalen = (int32_t)rdata->allocsize;
//char str[65]; printf("saved.%s [%d:%d] fpos.%d datalen.%d\n",bits256_str(str,block->RO.hash2),bp->hdrsi,bundlei,fpos,origtxdata->datalen);
ramchain->H.ROflag = 0;
flag = 1;
if ( addr->dirty[0] != 0 && addr->voutsfp != 0 )
if ( addr->dirty[0] != 0 && addr->voutsfp != 0 ) //
fflush(addr->voutsfp);
if ( addr->dirty[1] != 0 && addr->vinsfp != 0 )
if ( addr->dirty[1] != 0 && addr->vinsfp != 0 ) //addr->dirty[1] != 0 &&
fflush(addr->vinsfp);
memset(&R,0,sizeof(R));
if ( verifyflag != 0 && (mapchain= iguana_ramchain_map(coin,fname,0,1,&R,0,addr_ipbits,block->RO.hash2,block->RO.prev_block,bundlei,fpos,1,0)) == 0 )
if ( verifyflag != 0 && (mapchain= iguana_ramchain_map(coin,fname,0,1,&R,0,(uint32_t)addr->ipbits,block->RO.hash2,block->RO.prev_block,bundlei,fpos,1,0)) == 0 )
{
printf("delete unverified [%d:%d]\n",bp->hdrsi,bundlei);
iguana_ramchain_free(coin,&R,1);
@ -2001,7 +1921,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
//bp->rawscriptspace += rdata->scriptspace;
}
if ( fpos >= 0 )
block->fpos = fpos, block->fpipbits = addr_ipbits;
block->fpos = fpos, block->fpipbits = (uint32_t)addr->ipbits;
} else printf("save error\n");
}
else
@ -2038,7 +1958,7 @@ void iguana_ramchain_disp(struct iguana_ramchain *ramchain)
init_hexbytes_noT(str,U[unspentind].rmd160,20);
printf("(%.8f %s) ",dstr(U[unspentind].value),str);
}
printf("txid.[%d] %s (%d:%d %d:%d)\n",txidind,bits256_str(str,tx->txid),tx->firstvout,tx->numvouts,tx->firstvin,tx->numvins);
printf("txid.[%d] %s (%u:%d %u:%d)\n",txidind,bits256_str(str,tx->txid),(uint32_t)tx->firstvout,tx->numvouts,(uint32_t)tx->firstvin,tx->numvins);
}
}
}
@ -2055,8 +1975,10 @@ void iguana_blockdelete(struct iguana_info *coin,bits256 hash2,int32_t i)
if ( fname[0] != 0 )
{
OS_removefile(fname,0);
#ifndef WIN32
strcat(fname,".tmp");
OS_removefile(fname,0);
#endif
}
}
@ -2083,7 +2005,7 @@ void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,stru
bp->speculativecache[i] = 0;
}
}
if ( deletefile != 0 )
if ( deletefile != 0 && block != 0 )
iguana_blockdelete(coin,block->RO.hash2,i);
}
@ -2142,12 +2064,14 @@ void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,str
else
{
fclose(fp);
#ifndef WIN32
if ( renameflag != 0 )
{
sprintf(renamed,"%s.tmp",fname);
OS_renamefile(fname,renamed);
strcpy(fname,renamed);
}
#endif
if ( (ptr= OS_mapfile(fname,filesizep,0)) == 0 )
{
printf("error mapping.(%s) bundlei.%d\n",fname,bundlei);
@ -2296,11 +2220,13 @@ int32_t iguana_ramchain_expandedsave(struct supernet_info *myinfo,struct iguana_
return(retval);
}
struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag)
struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag)
{
static const bits256 zero;
struct iguana_blockRO *B; struct iguana_txid *T; int32_t i,firsti = 1; char fname[512];
struct iguana_block *block,*prev,*prev2; struct iguana_ramchain *mapchain; struct iguana_ramchaindata *rdata;
if ( bp->emitfinish > 1 )
return(ramchain);
memset(ramchain,0,sizeof(*ramchain));
if ( (mapchain= iguana_ramchain_map(coin,fname,bp,bp->n,ramchain,0,0,bp->hashes[0],zero,0,0,extraflag,1)) != 0 )
{
@ -2350,9 +2276,9 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
}
}
}
//printf("mapped bundle.%d\n",bp->bundleheight);
//printf("mapped bundle.[%d]\n",bp->hdrsi);
bp->emitfinish = (uint32_t)time(NULL) + 1;
iguana_bundlecalcs(coin,bp,60);
iguana_bundlecalcs(myinfo,coin,bp,60);
}
else
{
@ -2369,7 +2295,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
int64_t iguana_ramchainopen(char *fname,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2)
{
RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; int32_t i,numblocks = coin->chain->bundlesize; uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int64_t hashsize,allocsize;
RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; int32_t i,numblocks = coin->chain->bundlesize; uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t hashsize,allocsize;
//B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0;
mem->alignflag = sizeof(uint32_t);
hashmem->alignflag = sizeof(uint32_t);
@ -2567,7 +2493,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi
{
if ( bits256_nonz(block->RO.prev_block) == 0 && i > 0 )
block->RO.prev_block = bp->hashes[i-1];
if ( (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(coin,&valid,block,1) < 0 )
if ( (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(myinfo,coin,&valid,block,1) < 0 )
{
char str[65]; printf("null prevblock error at ht.%d patch.(%s)\n",bp->bundleheight+i,bits256_str(str,bp->hashes[i-1]));
iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi);
@ -2629,7 +2555,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi
{
//char dirname[1024];
//printf("delete %d files hdrs.[%d] retval.%d bp_n.%d\n",num,bp->hdrsi,retval,bp_n);
if ( iguana_bundleload(coin,&newchain,bp,0) == 0 )
if ( iguana_bundleload(myinfo,coin,&newchain,bp,0) == 0 )
retval = -1;
else //if ( bp_n == bp->n && bp->n == coin->chain->bundlesize && bp->hdrsi < coin->bundlescount-3 )
{
@ -2699,7 +2625,7 @@ int32_t iguana_bundlemergeHT(struct supernet_info *myinfo,char *fname,struct igu
{
if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,(A->H.data->numtxids+B->H.data->numtxids),(A->H.data->numunspents+B->H.data->numunspents),(A->H.data->numspends+B->H.data->numspends),(A->H.data->numpkinds+B->H.data->numpkinds),(A->H.data->numexternaltxids+B->H.data->numexternaltxids),A->H.data->scriptspace,A->height,A->numblocks + B->numblocks,coin->chain->zcash) < 0 )
{
printf("depth.%d ht.%d fsize.%s ERROR alloc lag.%d elapsed.%ld\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),now-starttime,time(NULL)-now);
printf("depth.%d ht.%d fsize.%s ERROR alloc lag.%d elapsed.%d\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),now-starttime,(int32_t)(time(NULL)-now));
iguana_mergefree(coin,mem,A,B,&HASHMEM,&HASHMEMA,&HASHMEMB);
return(-1);
}
@ -2716,7 +2642,7 @@ int32_t iguana_bundlemergeHT(struct supernet_info *myinfo,char *fname,struct igu
else if ( iguana_ramchain_expandedsave(myinfo,coin,RAMCHAIN_DESTARG,&newchain,&HASHMEM,0,0) == 0 )
{
printf("merging isnt setup to save the blockROs\n");
printf("depth.%d ht.%d fsize.%s MERGED %d[%d] and %d[%d] lag.%d elapsed.%ld bp.%d -> %d\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),A->height,A->numblocks,B->height,B->numblocks,now-starttime,time(NULL)-now,bp->bundleheight,nextbp->bundleheight);
printf("depth.%d ht.%d fsize.%s MERGED %d[%d] and %d[%d] lag.%d elapsed.%d bp.%d -> %d\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),A->height,A->numblocks,B->height,B->numblocks,now-starttime,(int32_t)(time(NULL)-now),bp->bundleheight,nextbp->bundleheight);
iguana_mergefree(coin,mem,A,B,&HASHMEM,&HASHMEMA,&HASHMEMB);
bp->mergefinish = 0;
nextbp->mergefinish = (uint32_t)time(NULL);
@ -2783,93 +2709,4 @@ void iguana_ramchainmerge(struct iguana_info *coin) // jl777: verify prev/next h
}
#endif
void iguana_RTvout(struct iguana_info *coin,int64_t polarity,struct iguana_RTtxid *RTptr,struct iguana_block *block,bits256 txid,int32_t j,struct iguana_msgvout *vout)
{
int32_t scriptlen,type,k; uint8_t *script; struct vin_info V; char coinaddr[64];
script = vout->pk_script;
scriptlen = vout->pk_scriptlen;
type = iguana_calcrmd160(coin,0,&V,script,scriptlen,txid,j,0xffffffff);
if ( (type == 12 && scriptlen == 0) || (type == 1 && bitcoin_pubkeylen(script+1) <= 0) )
{
for (k=0; k<scriptlen; k++)
printf("%02x",script[k]);
printf(" script type.%d scriptlen.%d\n",type,scriptlen);
}
bitcoin_address(coinaddr,coin->chain->pubtype,V.rmd160,sizeof(V.rmd160));
iguana_RTunspent(coin,RTptr,block,polarity,coinaddr,V.rmd160,type,script,scriptlen,txid,j,vout->value);
}
int32_t iguana_RTramchaindata(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *TXDATA,struct OS_memspace *HASHMEM,int64_t polarity,struct iguana_block *block,struct iguana_msgtx *txarray,int32_t txn_count)
{
RAMCHAIN_DECLARE; struct iguana_ramchain R,*ramchain = &R; struct iguana_msgtx *tx; char fname[1024]; struct iguana_ramchaindata *rdata; struct iguana_RTtxid *RTptr; int32_t iter,hdrsi,bundlei,i,j,firsti = 1;
if ( block->RO.txn_count != txn_count )
{
printf("txn_count mismatch ht.%d %d != %d\n",block->height,block->RO.txn_count,txn_count);
return(-1);
}
hdrsi = (block->height / coin->chain->bundlesize);
bundlei = (block->height % coin->chain->bundlesize);
if ( iguana_ramchain_init(fname,ramchain,TXDATA,HASHMEM,1,block->RO.txn_count,block->RO.numvouts,block->RO.numvins,0,0,1,0,1,coin->chain->zcash) == 0 )
{
printf("error iguana_ramchain_init\n");
return(-1);
}
iguana_ramchain_link(ramchain,block->RO.hash2,hdrsi,block->height,bundlei,1,firsti,0);
if ( (rdata= ramchain->H.data) != 0 )
{
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,rdata);
if ( T == 0 || U == 0 || S == 0 || B == 0 )
{
printf("fatal error getting txdataptrs %p %p %p %p\n",T,U,S,B);
return(-1);
}
for (iter=0; iter<2; iter++)
{
ramchain->H.txidind = ramchain->H.spendind = ramchain->H.unspentind = rdata->firsti;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
{
tx = &txarray[i];
RTptr = iguana_RTtxid_create(coin,block,polarity,i,txn_count,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,tx->serialized,tx->allocsize);
if ( polarity > 0 )
{
if ( iter == 0 )
{
for (j=0; j<tx->tx_out; j++)
iguana_RTvout(coin,polarity,RTptr,block,tx->txid,j,&tx->vouts[j]);
ramchain->H.spendind += tx->tx_in;
}
else
{
for (j=0; j<tx->tx_in; j++)
{
iguana_RTspend(myinfo,coin,RTptr,block,polarity,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->txid,j,tx->vins[j].prev_hash,tx->vins[j].prev_vout);
}
ramchain->H.unspentind += tx->tx_out;
}
}
else
{
if ( iter == 0 )
{
for (j=tx->tx_in-1; j>=0; j--)
{
iguana_RTspend(myinfo,coin,RTptr,block,polarity,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->txid,j,tx->vins[j].prev_hash,tx->vins[j].prev_vout);
}
ramchain->H.unspentind += tx->tx_out;
}
else
{
for (j=tx->tx_out-1; j>=0; j--)
iguana_RTvout(coin,polarity,RTptr,block,tx->txid,j,&tx->vouts[j]);
ramchain->H.spendind += tx->tx_in;
}
}
}
}
//printf("scriptoffset.%d after %d txids\n",ramchain->H.scriptoffset,txn_count);
iguana_ramchain_free(coin,ramchain,0);
return(0);
}
iguana_ramchain_free(coin,ramchain,0);
return(-1);
}

757
iguana/iguana_realtime.c

@ -16,457 +16,6 @@
// verify undo cases for hhutxo, and all 4 permutations of setting
#include "iguana777.h"
//#define ENABLE_RAMCHAIN
#ifdef oldway
void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp)
{
//return;
#ifdef ENABLE_RAMCHAIN
int32_t hdrsi;
//portable_mutex_lock(&coin->RTmutex);
if ( coin->utxotable != 0 )
{
printf("free RTramchain\n");
//iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables
coin->lastRTheight = coin->RTheight = 0;//(coin->bundlescount-1) * coin->chain->bundlesize;
coin->RTgenesis = 0;
iguana_utxoaddrs_purge(coin);
iguana_ramchain_free(coin,&coin->RTramchain,1);
if ( bp != 0 )
bp->ramchain = coin->RTramchain;
iguana_mempurge(&coin->RTmem);
iguana_mempurge(&coin->RThashmem);
for (hdrsi=coin->bundlescount-1; hdrsi>0; hdrsi--)
if ( (bp= coin->bundles[hdrsi]) == 0 && bp != coin->current )
{
iguana_volatilespurge(coin,&bp->ramchain);
if ( iguana_volatilesmap(coin,&bp->ramchain) != 0 )
printf("error mapping bundle.[%d]\n",hdrsi);
}
coin->RTdatabad = 0;
printf("done RTramchain\n");
}
//portable_mutex_unlock(&coin->RTmutex);
#endif
}
void *iguana_ramchainfile(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block)
{
//return(0);
#ifdef ENABLE_RAMCHAIN
char fname[1024]; long filesize; int32_t err; void *ptr=0;
if ( block == bp->blocks[bundlei] && (ptr= iguana_bundlefile(coin,fname,&filesize,bp,bundlei)) != 0 )
{
if ( iguana_mapchaininit(fname,coin,R,bp,bundlei,block,ptr,filesize) >= 0 )
{
if ( dest != 0 && dest->H.data != 0 )
err = iguana_ramchain_iterate(myinfo,coin,dest,R,bp,bundlei);
else err = 0;
if ( err != 0 || dest->H.data == 0 || bits256_cmp(R->H.data->firsthash2,block->RO.hash2) != 0 )
{
char str[65];
printf("ERROR [%d:%d] %s vs ",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2));
printf("mapped.%s\n",bits256_str(str,R->H.data->firsthash2));
} else return(ptr);
}
iguana_blockunmark(coin,block,bp,bundlei,1);
iguana_ramchain_free(coin,R,1);
} //else printf("ramchainfile ptr.%p block.%p\n",ptr,block);
#endif
return(0);
}
void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp)
{
//return;
#ifdef ENABLE_RAMCHAIN
uint32_t i,changed = 0; struct iguana_ramchaindata *rdata; struct iguana_ramchain *dest = &coin->RTramchain; struct iguana_blockRO *B; struct iguana_bundle *tmpbp;
//portable_mutex_lock(&coin->RTmutex);
if ( (rdata= dest->H.data) != 0 )
{
i = 0;
if ( coin->RTheight != coin->lastRTheight )
changed++;
else
{
B = RAMCHAIN_PTR(rdata,Boffset);
for (i=0; i<rdata->numblocks; i++)
if ( bits256_cmp(B[i].hash2,bp->hashes[i]) != 0 )
{
char str[65],str2[65]; printf("mismatched hash2 at %d %s vs %s\n",bp->bundleheight+i,bits256_str(str,B[i].hash2),bits256_str(str2,bp->hashes[i]));
changed++;
iguana_blockunmark(coin,bp->blocks[i],bp,i,1);
break;
}
}
if ( changed != 0 )
{
printf("RTramchain changed %d bundlei.%d | coin->RTheight %d != %d bp->bundleheight + %d coin->RTramchain.H.data->numblocks\n",coin->RTheight,i,coin->RTheight,bp->bundleheight,rdata->numblocks);
iguana_RTramchainfree(coin,bp);
}
}
if ( coin->RTramchain.H.data == 0 )
{
iguana_ramchainopen(fname,coin,dest,&coin->RTmem,&coin->RThashmem,bp->bundleheight,bp->hashes[0]);
printf("ALLOC RTramchain.(%s) RTrdata %p rdata.%p\n",fname,coin->RTramchain.H.data,bp->ramchain.H.data);
dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti;
dest->externalind = dest->H.stacksize = 0;
dest->H.scriptoffset = 1;
if ( 1 )
{
for (i=0; i<bp->hdrsi; i++)
if ( (tmpbp= coin->bundles[i]) != 0 )
{
iguana_volatilespurge(coin,&tmpbp->ramchain);
iguana_volatilesmap(coin,&tmpbp->ramchain);
}
sleep(1);
}
}
//portable_mutex_unlock(&coin->RTmutex);
#endif
}
void iguana_rdataset(struct iguana_ramchain *dest,struct iguana_ramchaindata *rdest,struct iguana_ramchain *src)
{
//return;
#ifdef ENABLE_RAMCHAIN
*dest = *src;
dest->H.data = rdest;
*rdest = *src->H.data;
rdest->numpkinds = src->pkind;
rdest->numexternaltxids = src->externalind;
rdest->numtxids = src->H.txidind;
rdest->numunspents = src->H.unspentind;
rdest->numspends = src->H.spendind;
//printf("RT set numtxids.%u numspends.%u\n",rdest->numtxids,rdest->numspends);
#endif
}
void iguana_rdatarestore(struct iguana_ramchain *dest,struct iguana_ramchaindata *rdest,struct iguana_ramchain *src)
{
//return;
#ifdef ENABLE_RAMCHAIN
*src = *dest;
*src->H.data = *rdest;
src->pkind = rdest->numpkinds;
src->externalind = rdest->numexternaltxids;
src->H.txidind = rdest->numtxids;
src->H.unspentind = rdest->numunspents;
src->H.spendind = rdest->numspends;
printf("RT restore numtxids.%u numspends.%u\n",rdest->numtxids,rdest->numspends);
#endif
}
void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t numaddrs)
{
//return;
#ifdef ENABLE_RAMCHAIN
int32_t datalen,i; uint8_t serialized[512]; char str[65]; struct iguana_peer *addr;
if ( coin->peers == 0 )
return;
datalen = iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0]));
for (i=0; i<numaddrs && i<coin->peers->numranked; i++)
{
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
if ( coin->chain->hasheaders == 0 )
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,coin->blocks.hwmchain.RO.hash2)),1);
if ( (addr= coin->peers->ranked[i]) != 0 && addr->usock >= 0 && addr->dead == 0 && datalen > 0 )
{
iguana_send(coin,addr,serialized,datalen);
//addr->pendhdrs++;
}
}
#endif
}
void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp)
{
//return;
#ifdef ENABLE_RAMCHAIN
int32_t iterate,lasti,num,hdrsi,orignumemit; struct iguana_ramchain R; struct iguana_ramchaindata RDATA;
if ( bp->hdrsi <= 0 )
return;
printf("RTspendvectors [%d]\n",bp->hdrsi);
bp->ramchain = coin->RTramchain;
iguana_rdataset(&R,&RDATA,&coin->RTramchain);
if ( (lasti= (coin->RTheight - ((coin->RTheight/bp->n)*bp->n))) >= bp->n-1 )
lasti = bp->n - 1;
orignumemit = bp->numtmpspends;
iterate = 0;
if ( iguana_spendvectors(myinfo,coin,bp,&coin->RTramchain,coin->RTstarti%coin->chain->bundlesize,lasti,0,iterate) < 0 )
{
printf("RTutxo error -> RTramchainfree\n");
coin->RTdatabad = 1;
return;
}
else
{
//printf("RTspendvectors calculated to %d [%d]\n",coin->RTheight,bp->hdrsi);
bp->converted = 1;
for (hdrsi=num=0; hdrsi<bp->hdrsi; hdrsi++)
{
#ifdef __APPLE__
if ( coin->bundles[hdrsi]->lastprefetch == 0 )
{
iguana_ramchain_prefetch(coin,&coin->bundles[hdrsi]->ramchain,2);
coin->bundles[hdrsi]->lastprefetch = (uint32_t)time(NULL);
}
#endif
num += iguana_convert(coin,IGUANA_NUMHELPERS,coin->bundles[hdrsi],1,orignumemit);
}
//printf("RTspendvectors converted.%d to %d\n",num,coin->RTheight);
//iguana_rdatarestore(&R,&RDATA,&bp->ramchain);
bp->converted = (uint32_t)time(NULL);
if ( iguana_balancegen(coin,1,bp,coin->RTstarti,coin->RTheight > 0 ? coin->RTheight-1 : bp->bundleheight+bp->n-1,orignumemit) < 0 )
{
printf("balancegen error\n");
coin->RTdatabad = 1;
}
else if ( coin->RTgenesis == 0 && coin->firstRTgenesis == 0 )
coin->firstRTgenesis++, printf(">>>>>> IGUANA %s READY FOR REALTIME RPC <<<<<<\n",coin->symbol);
//printf("iguana_balancegen [%d] (%d to %d)\n",bp->hdrsi,coin->RTstarti,(coin->RTheight-1)%bp->n);
coin->RTstarti = coin->RTheight;
}
#endif
}
int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info *coin)
{
int32_t flag = 0;
//return(0);
#ifdef ENABLE_RAMCHAIN
double startmillis0; static double totalmillis0; static int32_t num0;
struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t offset,bundlei,i,n; bits256 hash2,*ptr; struct iguana_peer *addr;
struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR;
if ( coin->peers == 0 && coin->virtualchain == 0 )
return(0);
offset = 0;//(strcmp("BTC",coin->symbol) != 0);
if ( coin->RTheight >= (coin->current->hdrsi+1)*coin->chain->bundlesize )
{
printf("inversion RT %d >= %d\n",coin->RTheight,(coin->current->hdrsi+1)*coin->chain->bundlesize);
coin->lastRTheight = coin->RTheight = coin->current->hdrsi*coin->chain->bundlesize;
iguana_utxoaddrs_purge(coin);
}
if ( coin->current != 0 && (coin->blocks.hwmchain.height % coin->chain->bundlesize) == coin->chain->bundlesize-1 && coin->blocks.hwmchain.height/coin->chain->bundlesize == coin->longestchain/coin->chain->bundlesize )
{
block = coin->current->blocks[coin->current->n - 1];
if ( _iguana_chainlink(coin,block) <= 0 )
{
printf("RT edge case couldnt link\n");
}
else
{
printf("RT edge case.%d\n",block->height);
if ( (bp= coin->bundles[coin->RTheight / coin->chain->bundlesize]) != 0 )
iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,0,0);
iguana_update_balances(coin);
}
}
if ( coin->spendvectorsaved <= 1 )
{
//printf("%s spendvectorsaved not yet\n",coin->symbol);
usleep(100000);
return(0);
}
//portable_mutex_lock(&coin->RTmutex);
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) != 0 && (i > 0 && bp->utxofinish == 0) && bp != coin->current )
{
if ( iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,0,0) < 0 )
{
//portable_mutex_unlock(&coin->RTmutex);
printf("error generating spendvectors.[%d], skipping\n",i);
return(0);
} // else printf("generated UTXO.[%d]\n",i);
coin->spendvectorsaved = 1;
}
}
//portable_mutex_unlock(&coin->RTmutex);
bp = coin->current;
if ( bp == 0 )//|| iguana_validated(coin) < bp->hdrsi )
{
//printf("bp.%p validated.%d vs hdrsi.%d\n",bp,iguana_validated(coin),bp->hdrsi);
return(0);
}
if ( 0 && coin->RTheight > 0 && coin->spendvectorsaved != 1 && coin->bundlescount-1 != coin->balanceswritten )
{
printf("RT mismatch %d != %d\n",coin->bundlescount-1,coin->balanceswritten);
iguana_RTramchainfree(coin,coin->current);
coin->spendvectorsaved = 0;
coin->lastRTheight = coin->RTheight = 0;
iguana_utxoaddrs_purge(coin);
/*while ( coin->spendvectorsaved <= 1 )
{
fprintf(stderr,"wait for spendvectorsaved\n");
sleep(3);
}*/
return(0);
}
if ( coin->RTdatabad == 0 && bp->hdrsi >= (coin->longestchain/coin->chain->bundlesize)-1 && bp->hdrsi >= coin->balanceswritten-2 && ((coin->RTheight < coin->blocks.hwmchain.height-offset && time(NULL) > bp->lastRT) || time(NULL) > bp->lastRT+1) ) //coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n &&
{
if ( coin->RTheight < bp->hdrsi*coin->chain->bundlesize )
{
coin->lastRTheight = coin->RTheight = bp->hdrsi*coin->chain->bundlesize;
iguana_utxoaddrs_purge(coin);
}
if ( (block= bp->blocks[0]) == 0 || block->txvalid == 0 || block->mainchain == 0 )
{
if ( block != 0 )
{
if ( _iguana_chainlink(coin,block) <= 0 )
{
iguana_blockunmark(coin,block,bp,0,0);
bp->issued[0] = 0;
hash2 = bp->hashes[0];
//char str[65]; printf("RT[0] [%d:%d] %s %p\n",bp->hdrsi,0,bits256_str(str,hash2),block);
if ( coin->peers != 0 )
{
addr = coin->peers->ranked[rand() % 8];
if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 )
iguana_sendblockreqPT(coin,addr,bp,0,hash2,0);
}
}
}
}
//char str[65]; printf("check longest.%d RTheight.%d hwm.%d %s %p\n",coin->longestchain,coin->RTheight,coin->blocks.hwmchain.height,bits256_str(str,bp->hashes[0]),block);
if ( bits256_cmp(coin->RThash1,bp->hashes[1]) != 0 )
coin->RThash1 = bp->hashes[1];
//bp->lastRT = (uint32_t)time(NULL);
if ( coin->peers != 0 && coin->RTheight <= coin->longestchain-offset && coin->peers->numranked > 0 && time(NULL) > coin->RThdrstime+16 )
{
iguana_RThdrs(coin,bp,coin->peers->numranked);
coin->RThdrstime = (uint32_t)time(NULL);
}
bp->lastRT = (uint32_t)time(NULL);
iguana_RTramchainalloc("RTbundle",coin,bp);
bp->isRT = 1;
//printf("%s rdata.%p RTheight.%d hwm.%d RTdatabad.%d\n",coin->symbol,coin->RTramchain.H.data,coin->RTheight,coin->blocks.hwmchain.height,coin->RTdatabad);
while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height-offset && coin->RTdatabad == 0 )
{
dest = &coin->RTramchain;
B = RAMCHAIN_PTR(rdata,Boffset);
bundlei = (coin->RTheight % coin->chain->bundlesize);
if ( (block= iguana_bundleblock(coin,&hash2,bp,bundlei)) != 0 )
{
iguana_bundlehashadd(coin,bp,bundlei,block);
//printf("RT.%d vs hwm.%d starti.%d bp->n %d block.%p/%p ramchain.%p databad.%d prevnonz.%d\n",coin->RTheight,coin->blocks.hwmchain.height,coin->RTstarti,bp->n,block,bp->blocks[bundlei],dest->H.data,coin->RTdatabad,bits256_nonz(block->RO.prev_block));
}
else
{
//printf("cant find bundleblock [%d:%d]\n",bp->hdrsi,bundlei);
iguana_blockQ("RTmissing",coin,bp,bundlei,hash2,1);
break;
}
if ( coin->RTdatabad == 0 && block != 0 && (block->height == 0 || bits256_nonz(block->RO.prev_block) != 0) )
{
//printf("bundlei.%d blockht.%d RTheight.%d\n",bundlei,block->height,coin->RTheight);
iguana_blocksetcounters(coin,block,dest);
startmillis0 = OS_milliseconds();
if ( iguana_ramchainfile(myinfo,coin,dest,&blockR,bp,bundlei,block) == 0 )
{
for (i=0; i<bp->n; i++)
if ( GETBIT(bp->haveblock,i) == 0 )
bp->issued[i] = 0;
if ( (n= iguana_bundleissuemissing(coin,bp,3,1.)) > 0 )
printf("RT issued %d priority requests [%d] to unstick stuckiters.%d\n",n,bp->hdrsi,coin->stuckiters);
for (i=bundlei; i<bp->n; i++)
{
block = iguana_bundleblock(coin,&hash2,bp,i);
if ( bits256_nonz(hash2) != 0 && (block == 0 || block->txvalid == 0) )
{
uint8_t serialized[512]; int32_t len; struct iguana_peer *addr;
//char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block);
if ( coin->peers != 0 )
{
addr = coin->peers->ranked[rand() % 8];
if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 )
iguana_send(coin,addr,serialized,len);
}
coin->RTgenesis = 0;
}
if ( bits256_nonz(hash2) != 0 )
iguana_blockQ("RTerr",coin,bp,i,hash2,1);
//break;
}
return(-1);
} else iguana_ramchain_free(coin,&blockR,1);
B[bundlei] = block->RO;
totalmillis0 += (OS_milliseconds() - startmillis0);
num0++;
flag++;
//coin->blocks.RO[bp->bundleheight+bundlei] = block->RO;
coin->RTheight++;
coin->lastRTheight = coin->RTheight;
//printf(">>>> RT.%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize);
if ( coin->RTramchain.H.data != 0 )
coin->RTramchain.H.data->numblocks = bundlei + 1;
else break;
} else break;
}
}
else
{
if ( coin->virtualchain == 0 )
{
//printf("%s skip RT.(%d %d %d %d %d %d %d %u)\n",coin->symbol,coin->RTdatabad,bp->hdrsi,coin->longestchain/coin->chain->bundlesize,coin->balanceswritten,coin->RTheight,bp->bundleheight,coin->blocks.hwmchain.height,bp->lastRT);
//sleep(1);
}
}
n = 0;
if ( coin->RTdatabad == 0 && dest != 0 && flag != 0 && coin->RTheight >= coin->blocks.hwmchain.height-offset )
{
printf("ramchainiterate.[%d] ave %.2f micros, total %.2f seconds starti.%d num.%d\n",num0,(totalmillis0*1000.)/num0,totalmillis0/1000.,coin->RTstarti,coin->RTheight%bp->n);
if ( (n= iguana_walkchain(coin,1)) == coin->RTheight-1+offset )
{
//printf("RTgenesis verified\n");
if ( (coin->RTheight % coin->chain->bundlesize) > 3 )
{
//portable_mutex_lock(&coin->RTmutex);
iguana_RTspendvectors(myinfo,coin,bp);
//portable_mutex_unlock(&coin->RTmutex);
coin->RTgenesis = (uint32_t)time(NULL);
}
}
else
{
printf("walkchain error n.%d != %d\n",n,coin->RTheight-1+offset);
coin->RTdatabad = 1;
}
}
if ( dest != 0 && flag != 0 )
printf("<<<< flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld balance %.8f + %.8f - %.8f = supply %.8f\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,dest->H.data!=0?(long)dest->H.data->allocsize:-1,dstr(coin->histbalance),dstr(coin->RTcredits),dstr(coin->RTdebits),dstr(coin->histbalance + coin->RTcredits - coin->RTdebits));
if ( coin->RTdatabad != 0 )
{
bits256 lastbundle;
//portable_mutex_lock(&coin->RTmutex);
printf("START DATABAD fixing\n");
iguana_RTramchainfree(coin,bp);
if ( coin->RTdatabad < 0 )
{
memset(lastbundle.bytes,0,sizeof(lastbundle));
iguana_initfinal(myinfo,coin,lastbundle);
}
coin->RTdatabad = 0;
//memset(bp->hashes,0,sizeof(bp->hashes));
memset(bp->blocks,0,sizeof(bp->blocks));
if ( 0 && bp->speculative != 0 )
{
ptr = bp->speculative;
bp->speculative = 0;
memset(ptr,0,sizeof(*bp->speculative)*bp->n);
myfree(ptr,(bp->n+1)*sizeof(*bp->speculative));
}
iguana_RTramchainalloc("RTbundle",coin,bp);
printf("DONE DATABAD fixing\n");
//portable_mutex_unlock(&coin->RTmutex);
}
#endif
return(flag);
}
#endif
//#define FAST_UTHASH
#ifdef FAST_UTHASH
@ -478,13 +27,19 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info *
void iguana_RTtxid_free(struct iguana_RTtxid *RTptr)
{
int32_t i;
int32_t i; struct iguana_RTspend *spend;
for (i=0; i<RTptr->numvouts; i++)
if ( RTptr->unspents[i] != 0 )
free(RTptr->unspents[i]);
for (i=0; i<RTptr->numvins; i++)
if ( RTptr->spends[i] != 0 )
free(RTptr->spends[i]);
{
if ( (spend= RTptr->spends[i]) != 0 )
{
if ( spend->bundle_unspent != 0 )
free(spend->bundle_unspent);
free(spend);
}
}
if ( RTptr->rawtxbytes != 0 )
free(RTptr->rawtxbytes);
free(RTptr);
@ -520,6 +75,7 @@ void iguana_RTreset(struct iguana_info *coin)
#endif
printf("%s RTreset %d\n",coin->symbol,coin->RTheight);
coin->RTheight = coin->firstRTheight;
coin->RTcredits = coin->RTdebits = 0;
}
struct iguana_RTaddr *iguana_RTaddrfind(struct iguana_info *coin,uint8_t *rmd160,char *coinaddr)
@ -549,6 +105,32 @@ int64_t iguana_RTbalance(struct iguana_info *coin,char *coinaddr)
}
}
int64_t iguana_RTnetbalance(struct iguana_info *coin)
{
struct iguana_RTaddr *RTaddr,*tmp; int64_t RTdebits,RTcredits;
RTdebits = RTcredits = 0;
HASH_ITER(hh,coin->RTaddrs,RTaddr,tmp)
{
RTcredits += RTaddr->credits;
RTdebits += RTaddr->debits;
}
if ( RTcredits != coin->RTcredits || RTdebits != coin->RTdebits )
printf("RTnetbalance mismatch (%.8f %.8f) != (%.8f %.8f)\n",dstr(RTcredits),dstr(RTdebits),dstr(coin->RTcredits),dstr(coin->RTdebits));
return(RTcredits - RTdebits);
}
int32_t iguana_RTbalance_verify(char *str,struct iguana_info *coin)
{
int64_t balance;
balance = iguana_RTnetbalance(coin);
if ( balance != (coin->RTcredits - coin->RTdebits) )
{
printf("%s RTbalance %.8f != %.8f (%.8f - %.8f)\n",str,dstr(balance),dstr(coin->RTcredits - coin->RTdebits),dstr(coin->RTcredits),dstr(coin->RTdebits));
return(-1);
}
return(0);
}
void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,char *coinaddr,uint8_t *rmd160,int32_t spendflag,int64_t value,struct iguana_RTunspent *unspent)
{
struct iguana_RTaddr *RTaddr; int32_t len = (int32_t)strlen(coinaddr);
@ -571,13 +153,14 @@ void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,stru
coin->RTcredits += polarity * value;
if ( polarity > 0 )
{
//printf("unspent[%d] <- %p\n",RTaddr->numunspents,unspent);
//printf("%s lastunspent[%d] <- %p\n",coinaddr,RTaddr->numunspents,unspent);
RTaddr->numunspents++;
unspent->prevunspent = RTaddr->lastunspent;
RTaddr->lastunspent = unspent;
}
else if ( polarity < 0 )
{
//printf("%s lastunspent[%d] -> last.%p %p\n",coinaddr,RTaddr->numunspents,RTaddr->lastunspent,unspent);
if ( RTaddr->lastunspent == unspent )
{
RTaddr->lastunspent = unspent->prevunspent;
@ -586,6 +169,7 @@ void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,stru
//RTaddr->unspents[i] = RTaddr->unspents[--RTaddr->numunspents];
}
}
//printf("%s %.8f [%.8f - %.8f] -> %.8f\n",coinaddr,dstr(value),dstr(coin->RTcredits),dstr(coin->RTdebits),dstr(coin->histbalance)+dstr(coin->RTcredits)-dstr(coin->RTdebits));
if ( 0 && strcmp("BTC",coin->symbol) != 0 && strcmp("LTC",coin->symbol) != 0 && strcmp("DOGE",coin->symbol) != 0 )
printf("%lld %s %.8f h %.8f, cr %.8f deb %.8f [%.8f] numunspents.%d %p\n",(long long)polarity,coinaddr,dstr(value),dstr(RTaddr->histbalance),dstr(RTaddr->credits),dstr(RTaddr->debits),dstr(RTaddr->credits)-dstr(RTaddr->debits)+dstr(RTaddr->histbalance),RTaddr->numunspents,unspent);
}
@ -630,8 +214,6 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struc
return;
}
}
if ( (unspent->spend == 0 && polarity < 0) || (unspent->spend != 0 && polarity > 0) )
printf("unspent spend.%p opposite when polarity.%lld\n",unspent->spend,(long long)polarity);
iguana_RTcoinaddr(coin,RTptr,block,polarity,coinaddr,unspent->rmd160,0,value,unspent);
if ( polarity < 0 )
RTptr->unspents[vout] = 0;
@ -646,9 +228,25 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struc
//fprintf(stderr,",");
}
void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout)
void iguana_RTvout_create(struct iguana_info *coin,int64_t polarity,struct iguana_RTtxid *RTptr,struct iguana_block *block,bits256 txid,int32_t j,struct iguana_msgvout *vout)
{
int32_t scriptlen,type,k; uint8_t *script; struct vin_info V; char coinaddr[64];
script = vout->pk_script;
scriptlen = vout->pk_scriptlen;
type = iguana_calcrmd160(coin,0,&V,script,scriptlen,txid,j,0xffffffff);
if ( (type == 12 && scriptlen == 0) || (type == 1 && bitcoin_pubkeylen(script+1) <= 0) )
{
for (k=0; k<scriptlen; k++)
printf("%02x",script[k]);
printf(" script type.%d scriptlen.%d\n",type,scriptlen);
}
bitcoin_address(coinaddr,coin->chain->pubtype,V.rmd160,sizeof(V.rmd160));
iguana_RTunspent(coin,RTptr,block,polarity,coinaddr,V.rmd160,type,script,scriptlen,txid,j,vout->value);
}
void iguana_RTspend_create(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout)
{
struct iguana_RTspend *spend; struct iguana_RTtxid *spentRTptr; struct iguana_RTunspent *unspent=0; char str[65],str2[65],coinaddr[64]; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint32_t unspentind; int32_t spendlen,height; uint64_t value; struct iguana_outpoint spentpt;
struct iguana_RTspend *spend; struct iguana_RTtxid *spentRTptr; struct iguana_RTunspent *unspent=0; char str[65],str2[65],coinaddr[64]; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint32_t unspentind; int32_t spendlen,height; uint64_t RTspent,value; struct iguana_outpoint spentpt;
//printf("RTspend %s vini.%d spend.(%s/v%d) %lld\n",bits256_str(str,txid),vini,bits256_str(str2,prev_hash),prev_vout,(long long)polarity);
if ( vini == 0 && bits256_nonz(prev_hash) == 0 && prev_vout < 0 )
return;
@ -689,27 +287,29 @@ void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct
}
else
{
if ( (unspentind= iguana_unspentindfind(myinfo,coin,coinaddr,spendscript,&spendlen,&value,&height,prev_hash,prev_vout,coin->bundlescount,0)) == 0 )
if ( (unspentind= iguana_unspentindfind(myinfo,coin,&RTspent,coinaddr,spendscript,&spendlen,&value,&height,prev_hash,prev_vout,coin->bundlescount,0)) == 0 )
printf("iguana_RTspend cant find spentRTptr.(%s) search history\n",bits256_str(str,prev_hash));
else
{
int32_t spentheight,lockedflag,RTspentflag;
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
//printf("found unspentind (%s %.8f).%d spendlen.%d\n",coinaddr,dstr(value),addrtype,spendlen);
unspent = iguana_RTunspent_create(rmd160,value,spendscript,spendlen>0?spendlen:0,0,prev_vout);
memset(&spentpt,0,sizeof(spentpt));
spentpt.unspentind = unspentind;
spentpt.hdrsi = height / coin->chain->bundlesize;
spentpt.value = value;
iguana_RTutxofunc(coin,&spentheight,&lockedflag,spentpt,&RTspentflag,0,RTptr->height);
spend->bundle_unspent = unspent;
}
}
if ( unspent != 0 )
{
bitcoin_address(coinaddr,coin->chain->pubtype,unspent->rmd160,sizeof(unspent->rmd160));
iguana_RTcoinaddr(coin,RTptr,block,polarity,coinaddr,unspent->rmd160,1,unspent->value,unspent);
if ( polarity < 0 )
unspent->spend = 0;
else unspent->spend = spend;
bitcoin_address(coinaddr,coin->chain->pubtype,unspent->rmd160,sizeof(unspent->rmd160));
iguana_RTcoinaddr(coin,RTptr,block,polarity,coinaddr,unspent->rmd160,1,unspent->value,unspent);
if ( polarity > 0 )
unspent->spend = spend;
}
}
} else printf("iguana_RTspend txid mismatch %llx != %llx\n",(long long)RTptr->txid.txid,(long long)txid.txid);
@ -763,10 +363,50 @@ struct iguana_RTtxid *iguana_RTtxid_create(struct iguana_info *coin,struct iguan
return(RTptr);
}
int64_t _RTgettxout(struct iguana_info *coin,int32_t *heightp,int32_t *scriptlenp,uint8_t *script,uint8_t *rmd160,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool)
int32_t iguana_RTramchaindata(struct supernet_info *myinfo,struct iguana_info *coin,int64_t polarity,struct iguana_block *block,struct iguana_msgtx *txarray,int32_t txn_count)
{
struct iguana_msgtx *tx; struct iguana_RTtxid *RTptr; int32_t i,j;
if ( block->RO.txn_count != txn_count )
{
printf("txn_count mismatch ht.%d %d != %d\n",block->height,block->RO.txn_count,txn_count);
return(-1);
}
if ( polarity > 0 )
{
for (i=0; i<txn_count; i++)
{
tx = &txarray[i];
RTptr = iguana_RTtxid_create(coin,block,polarity,i,txn_count,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,tx->serialized,tx->allocsize);
for (j=0; j<tx->tx_out; j++)
iguana_RTvout_create(coin,polarity,RTptr,block,tx->txid,j,&tx->vouts[j]);
for (j=0; j<tx->tx_in; j++)
{
iguana_RTspend_create(myinfo,coin,RTptr,block,polarity,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->txid,j,tx->vins[j].prev_hash,tx->vins[j].prev_vout);
}
}
}
else
{
for (i=txn_count-1; i>=0; i--)
{
tx = &txarray[i];
RTptr = iguana_RTtxid_create(coin,block,polarity,i,txn_count,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,tx->serialized,tx->allocsize);
for (j=tx->tx_in-1; j>=0; j--)
{
iguana_RTspend_create(myinfo,coin,RTptr,block,polarity,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->txid,j,tx->vins[j].prev_hash,tx->vins[j].prev_vout);
}
for (j=tx->tx_out-1; j>=0; j--)
iguana_RTvout_create(coin,polarity,RTptr,block,tx->txid,j,&tx->vouts[j]);
}
}
return(0);
}
int64_t _RTgettxout(struct iguana_info *coin,struct iguana_RTtxid **ptrp,int32_t *heightp,int32_t *scriptlenp,uint8_t *script,uint8_t *rmd160,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool)
{
int32_t scriptlen; int64_t value = 0; struct iguana_RTtxid *RTptr; struct iguana_RTunspent *unspent = 0;
HASH_FIND(hh,coin->RTdataset,txid.bytes,sizeof(txid),RTptr);
*ptrp = RTptr;
*heightp = -1;
if ( scriptlenp == 0 )
scriptlenp = &scriptlen;
@ -778,7 +418,7 @@ int64_t _RTgettxout(struct iguana_info *coin,int32_t *heightp,int32_t *scriptlen
if ( vout >= 0 && vout < RTptr->txn_count && (unspent= RTptr->unspents[vout]) != 0 )
{
*heightp = RTptr->height;
if ( unspent->spend == 0 && (*scriptlenp= unspent->scriptlen) > 0 )
if ( script != 0 && unspent->spend == 0 && (*scriptlenp= unspent->scriptlen) > 0 )
memcpy(script,unspent->script,*scriptlenp);
memcpy(rmd160,unspent->rmd160,sizeof(unspent->rmd160));
bitcoin_address(coinaddr,coin->chain->pubtype,rmd160,sizeof(unspent->rmd160));
@ -803,38 +443,71 @@ int32_t _iguana_RTunspentfind(struct supernet_info *myinfo,struct iguana_info *c
return(spendlen);
}
int32_t iguana_RTunspentindfind(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint8_t *spendscript,int32_t *spendlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi,int32_t mempool)
int32_t iguana_RTunspentindfind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_outpoint *outpt,char *coinaddr,uint8_t *spendscript,int32_t *spendlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi,int32_t mempool)
{
char _coinaddr[64]; uint8_t rmd160[20]; int64_t value;
char _coinaddr[64]; struct iguana_RTtxid *ptr; uint8_t rmd160[20]; uint64_t value,RTspend; uint32_t unspentind;
if ( coinaddr == 0 )
coinaddr = _coinaddr;
if ( (value= _RTgettxout(coin,heightp,spendlenp,spendscript,rmd160,coinaddr,txid,vout,mempool)) > 0 )
memset(outpt,0,sizeof(*outpt));
if ( (value= _RTgettxout(coin,&ptr,heightp,spendlenp,spendscript,rmd160,coinaddr,txid,vout,mempool)) > 0 )
{
outpt->ptr = ptr;
if ( valuep != 0 )
{
*valuep = value;
outpt->value = *valuep;
}
return(0);
}
else return(iguana_unspentindfind(myinfo,coin,coinaddr,spendscript,spendlenp,valuep,heightp,txid,vout,lasthdrsi,mempool));
else
{
if ( (unspentind= iguana_unspentindfind(myinfo,coin,&RTspend,coinaddr,spendscript,spendlenp,valuep,heightp,txid,vout,lasthdrsi,mempool)) != 0 )
{
if ( valuep != 0 && *valuep == 0 )
*valuep = RTspend;
outpt->hdrsi = *heightp / coin->chain->bundlesize;
outpt->unspentind = unspentind;
if ( valuep != 0 )
outpt->value = *valuep;
return(0);
}
return(-1);
}
}
int32_t iguana_outptset(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_outpoint *outpt,bits256 txid,int32_t vout,int64_t value,char *spendscriptstr)
{
int32_t spendlen;
memset(outpt,0,sizeof(*outpt));
spendlen = (int32_t)strlen(spendscriptstr) >> 1;
if ( spendlen > sizeof(outpt->spendscript) )
return(-1);
outpt->spendlen = spendlen;
decode_hex(outpt->spendscript,spendlen,spendscriptstr);
outpt->txid = txid;
outpt->vout = vout;
outpt->value = value;
return(0);
}
int32_t iguana_txidheight(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid)
{
int32_t spendlen,height = 0; uint64_t value; char coinaddr[64]; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
iguana_RTunspentindfind(myinfo,coin,coinaddr,spendscript,&spendlen,&value,&height,txid,0,(coin->firstRTheight/coin->chain->bundlesize) - 1,0);
struct iguana_outpoint outpt; int32_t spendlen,height = 0; uint64_t value; char coinaddr[64]; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
iguana_RTunspentindfind(myinfo,coin,&outpt,coinaddr,spendscript,&spendlen,&value,&height,txid,0,(coin->firstRTheight/coin->chain->bundlesize) - 1,0);
return(height);
}
int64_t iguana_txidamount(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout)
int64_t iguana_txidamount(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout)
{
int32_t spendlen,height = 0; uint64_t value; char coinaddr[64]; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
iguana_RTunspentindfind(myinfo,coin,coinaddr,spendscript,&spendlen,&value,&height,txid,vout,(coin->firstRTheight/coin->chain->bundlesize) - 1,0);
struct iguana_outpoint outpt; int32_t spendlen,height = 0; uint64_t value; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
iguana_RTunspentindfind(myinfo,coin,&outpt,coinaddr,spendscript,&spendlen,&value,&height,txid,vout,(coin->firstRTheight/coin->chain->bundlesize) - 1,0);
return(value);
}
char *iguana_txidcategory(struct supernet_info *myinfo,struct iguana_info *coin,char *account,char *coinaddr,bits256 txid,int32_t vout)
{
struct iguana_waccount *wacct; struct iguana_waddress *waddr; int32_t ismine=0,spendlen,height = 0; uint64_t value; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
iguana_RTunspentindfind(myinfo,coin,coinaddr,spendscript,&spendlen,&value,&height,txid,vout,(coin->firstRTheight/coin->chain->bundlesize) - 1,0);
struct iguana_outpoint outpt; struct iguana_waccount *wacct; struct iguana_waddress *waddr; int32_t ismine=0,spendlen,height = 0; uint64_t value; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
iguana_RTunspentindfind(myinfo,coin,&outpt,coinaddr,spendscript,&spendlen,&value,&height,txid,vout,(coin->firstRTheight/coin->chain->bundlesize) - 1,0);
account[0] = 0;
if ( coinaddr[0] != 0 )
{
@ -893,7 +566,7 @@ void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int3
return((void *)"already have rawdata");
return(0);
}
//printf("len.%d filesize.%ld\n",len,filesize);
printf("malformed delete.(%s) len.%d filesize.%ld\n",fname,len,filesize);
fclose(fp);
OS_removefile(fname,0);
}
@ -928,7 +601,7 @@ void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int3
return(&ptr[sizeof(*recvlenp) + sizeof(checknumtx)]);
} else printf("checklen.%d vs %d, checknumtx %d vs %d\n",checklen,(int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)),checknumtx,*numtxp);
}
else
else if ( 0 )
{
OS_removefile(fname,0);
printf("(%s) removed to suppress errors\n",fname);
@ -956,27 +629,37 @@ void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight)
int32_t iguana_RTiterate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t offset,struct iguana_block *block,int64_t polarity)
{
struct iguana_txblock txdata; uint8_t *serialized; struct iguana_bundle *bp; int32_t hdrsi,bundlei,height,i,n,errs=0,numtx,num,len; int32_t recvlen = 0;
struct iguana_txblock txdata; uint8_t *serialized; struct iguana_bundle *bp; int32_t hdrsi,bundlei,height,i,n,numtx,num,len; int32_t recvlen = 0;
if ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 )
{
char str[65];
//char str[65];
//printf("errs.%d cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",errs,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]);
coin->RTrecvlens[offset] = 0;
coin->RTrawdata[offset] = iguana_RTrawdata(coin,block->RO.hash2,0,&coin->RTrecvlens[offset],&coin->RTnumtx[offset],0);
if ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 )
{
printf("%s errs.%d cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",coin->symbol,errs,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]);
struct iguana_peer *addr;
iguana_blockQ("RTiterate",coin,coin->bundles[block->hdrsi],block->bundlei,block->RO.hash2,1);
if ( coin->peers != 0 )
//char str[65]; printf("%s cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",coin->symbol,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]);
struct iguana_peer *addr; // int32_t errs = 0;
iguana_blockhashset("RTblock",coin,coin->firstRTheight+offset,block->RO.hash2,1);
if ( (bp= coin->bundles[block->hdrsi]) != 0 )
{
if ( coin->peers->numranked > 0 )
bp->issued[block->bundlei] = 0;
bp->blocks[block->bundlei] = block;
bp->hashes[block->bundlei] = block->RO.hash2;
block->height = coin->firstRTheight+offset;
if ( coin->peers != 0 )
{
for (i=0; i<coin->peers->numranked&&i<8; i++)
if ( (addr= coin->peers->ranked[i]) != 0 )
iguana_sendblockreqPT(coin,addr,coin->bundles[block->hdrsi],block->bundlei,block->RO.hash2,1);
} else iguana_updatemetrics(myinfo,coin);
if ( coin->peers->numranked > 0 )
{
for (i=0; i<coin->peers->numranked&&i<8; i++)
if ( (addr= coin->peers->ranked[i]) != 0 )
{
iguana_sendblockreqPT(coin,addr,coin->bundles[block->hdrsi],block->bundlei,block->RO.hash2,1);
}
} else iguana_updatemetrics(myinfo,coin);
}
}
iguana_blockQ("RTiterate",coin,bp,block->bundlei,block->RO.hash2,1);
num = 0;
for (height=block->height+1; height<=coin->blocks.hwmchain.height; height++)
{
@ -989,7 +672,7 @@ int32_t iguana_RTiterate(struct supernet_info *myinfo,struct iguana_info *coin,i
{
num++;
iguana_blockQ("RTiterate",coin,0,-1,block->RO.hash2,1);
if ( coin->peers != 0 && (n= coin->peers->numranked) > 0 )
if ( 0 && coin->peers != 0 && (n= coin->peers->numranked) > 0 )
{
if ( (addr= coin->peers->ranked[rand() % n]) != 0 )
iguana_sendblockreqPT(coin,addr,0,-1,block->RO.hash2,1);
@ -997,29 +680,20 @@ int32_t iguana_RTiterate(struct supernet_info *myinfo,struct iguana_info *coin,i
}
}
}
printf("issue missing %d to ht.%d\n",num,height);
//printf("issue missing %d to ht.%d\n",num,height);
return(-1);
}
}
printf("%s RTiterate.%lld offset.%d numtx.%d len.%d\n",coin->symbol,(long long)polarity,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset]);
char str[65]; printf("%s %.8f [%.8f %.8f] RTiterate.%lld %d tx.%d len.%d %s\n",coin->symbol,dstr(coin->histbalance)+dstr(coin->RTcredits)-dstr(coin->RTdebits),dstr(coin->RTcredits),dstr(coin->RTdebits),(long long)polarity,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset],bits256_str(str,block->RO.hash2));
if ( coin->RTrawmem.ptr == 0 )
iguana_meminit(&coin->RTrawmem,"RTrawmem",0,IGUANA_MAXPACKETSIZE * 2,0);
if ( coin->RTmem.ptr == 0 )
iguana_meminit(&coin->RTmem,"RTmem",0,IGUANA_MAXPACKETSIZE * 2,0);
if ( coin->RThashmem.ptr == 0 )
iguana_meminit(&coin->RThashmem,"RThashmem",0,IGUANA_MAXPACKETSIZE * 2,0);
iguana_memreset(&coin->RTrawmem), iguana_memreset(&coin->RTmem), iguana_memreset(&coin->RThashmem);
memset(&txdata,0,sizeof(txdata));
//extern int32_t debugtest;
//debugtest = 1;
//fprintf(stderr,"T");
if ( (n= iguana_gentxarray(coin,&coin->RTrawmem,&txdata,&len,serialized,recvlen)) > 0 )
iguana_memreset(&coin->RTrawmem);
if ( (n= iguana_gentxarray(myinfo,coin,&coin->RTrawmem,&txdata,&len,serialized,recvlen)) > 0 )
{
//fprintf(stderr,"R");
iguana_RTramchaindata(myinfo,coin,&coin->RTmem,&coin->RThashmem,polarity,block,coin->RTrawmem.ptr,numtx);
iguana_RTramchaindata(myinfo,coin,polarity,block,coin->RTrawmem.ptr,numtx);
return(0);
} else printf("gentxarray n.%d RO.txn_count.%d recvlen.%d\n",n,numtx,recvlen);
//debugtest = 0;
iguana_RTreset(coin);
return(-1);
}
@ -1084,15 +758,34 @@ int32_t iguana_RTblocksub(struct supernet_info *myinfo,struct iguana_info *coin,
void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block)
{
int32_t i,n,height,hdrsi,bundlei; struct iguana_block *addblock,*subblock; struct iguana_bundle *bp;
int32_t i,n,height,hdrsi,bundlei; struct iguana_block *addblock=0,*subblock=0; struct iguana_bundle *bp;
if ( coin->RTreset_needed != 0 )
{
printf("RTreset_needed -> RTreset\n");
iguana_RTreset(coin);
coin->RTreset_needed = 0;
}
iguana_RTbalance_verify("start iterate",coin);
/*if ( strcmp(coin->symbol,"BTC") != 0 && strcmp(coin->symbol,"LTC") != 0 )
{
if ( block->height < coin->firstRTheight+coin->minconfirms )
return;
if ( (block= iguana_blockfind("RTnew",coin,iguana_blockhash(coin,block->height-coin->minconfirms))) == 0 )
return;
}*/
if ( block->height < coin->firstRTheight || block->height >= coin->firstRTheight+sizeof(coin->RTblocks)/sizeof(*coin->RTblocks) )
{
if ( coin->firstRTheight > 0 )
if ( 0 && coin->firstRTheight > 0 )
printf("iguana_RTnewblock illegal blockheight.%d\n",block->height);
return;
}
if ( block != 0 && coin->RTheight > 0 && coin->RTheight <= coin->blocks.hwmchain.height )
if ( block != 0 && coin->RTheight > 0 && coin->utxoaddrtable != 0 )//&& coin->RTheight <= coin->blocks.hwmchain.height )
{
if ( block->height <= coin->lastRTheight+coin->minconfirms )
return;
if ( (block= iguana_blockfind("RTnew",coin,iguana_blockhash(coin,block->height-coin->minconfirms))) == 0 )
return;
// error check to bundle boundary
portable_mutex_lock(&coin->RTmutex);
if ( block->height > coin->lastRTheight )
{
@ -1106,6 +799,10 @@ void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,str
{
if ( iguana_RTblockadd(myinfo,coin,addblock) < 0 )
break;
//if ( iguana_RTblocksub(myinfo,coin,addblock) < 0 )
// break;
//if ( iguana_RTblockadd(myinfo,coin,addblock) < 0 )
// break;
coin->lastRTheight = addblock->height;
}
else
@ -1115,6 +812,8 @@ void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,str
}
}
coin->RTheight += i;
if ( coin->RTheight != coin->lastRTheight+1 )
printf("ERROR: ");
//printf("%s >= RTnewblock RTheight %d prev %d\n",coin->symbol,coin->RTheight,coin->lastRTheight);
}
else if ( block->height == coin->lastRTheight )
@ -1123,6 +822,7 @@ void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,str
{
if ( iguana_RTblocksub(myinfo,coin,subblock) < 0 || iguana_RTblockadd(myinfo,coin,block) < 0 )
{
printf("error unwinding to current %d\n",coin->RTheight);
portable_mutex_unlock(&coin->RTmutex);
return;
}
@ -1131,38 +831,29 @@ void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,str
}
else
{
if ( block->height < coin->firstRTheight )
{
if ( coin->lastRTheight > 0 )
printf("%s ht.%d reorg past firstRTheight.%d\n",coin->symbol,block->height,coin->firstRTheight);
iguana_RTreset(coin);
}
else
char str[65]; printf("reorg RTheight.%d vs block.%d %s\n",coin->RTheight,block->height,bits256_str(str,block->RO.hash2));
iguana_RTreset(coin);
/*while ( coin->RTheight > block->height )
{
while ( coin->lastRTheight >= block->height )
{
if ( iguana_RTblocksub(myinfo,coin,iguana_RTblock(coin,coin->lastRTheight--)) < 0 )
{
coin->RTheight = coin->lastRTheight+1;
portable_mutex_unlock(&coin->RTmutex);
return;
}
}
coin->RTheight = coin->lastRTheight+1;
if ( iguana_RTblockadd(myinfo,coin,block) < 0 )
if ( iguana_RTblocksub(myinfo,coin,iguana_RTblock(coin,coin->RTheight-1)) < 0 )
{
printf("error subtracting %d\n",coin->RTheight-1);
coin->lastRTheight = coin->RTheight-1;
portable_mutex_unlock(&coin->RTmutex);
return;
}
coin->lastRTheight = block->height;
coin->RTheight = coin->lastRTheight+1;
coin->RTheight--;
}
if ( iguana_RTblockadd(myinfo,coin,block) < 0 )
{
printf("error adding %d\n",block->height);
portable_mutex_unlock(&coin->RTmutex);
return;
}
coin->lastRTheight = block->height;
coin->RTheight = coin->lastRTheight+1;*/
}
portable_mutex_unlock(&coin->RTmutex);
//block = iguana_blockfind("next",coin,iguana_blockhash(coin,block->height+1));
}
iguana_RTbalance_verify("end iterate",coin);
}
// infinite loops at bundle boundary?
// >= RTnewblock RTheight 1254001 prev 1254000
// B errs.0 cant load 15102564820405cd16506d2731567453c437af07cdd5954bc21b32304e39b1d4 ht.1254001 polarity.1 numtx.0 (nil) recvlen.0

576
iguana/iguana_recv.c

@ -63,7 +63,7 @@ int32_t iguana_speculativesearch(struct iguana_info *coin,struct iguana_block **
int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe)
{
static bits256 lastreq,lastreq2;
int32_t len,j,n,recvlen,numtx; struct iguana_bundle *checkbp; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; struct iguana_block *block=0;
int32_t len,j,n; struct iguana_bundle *checkbp; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; struct iguana_block *block=0;
char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2));
if ( addr == 0 && coin->peers != 0 && (n= coin->peers->numranked) > 0 )
addr = coin->peers->ranked[rand() % n];
@ -80,17 +80,11 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
checkbp = 0, j = -2;
if ( (checkbp= iguana_bundlefind(coin,&checkbp,&j,hash2)) != 0 && j >= 0 && j < checkbp->n )
{
if ( checkbp->emitfinish != 0 || ((block= checkbp->blocks[j]) != 0 && block->txvalid != 0 && block->mainchain != 0 && block->valid != 0 && block->bundlei != 0) )
{
//char str[65];
recvlen = numtx = 0;
if ( coin->RTheight > 0 && iguana_RTrawdata(coin,hash2,0,&recvlen,&numtx,1) != 0 )
{
printf("found valid [%d:%d] in blockreqPT\n",checkbp->hdrsi,j);
return(0);
} //else printf("no RTrawdata for %s\n",bits256_str(str,hash2));
}
if ( checkbp->emitfinish != 0 || ((block= checkbp->blocks[j]) != 0 && block->txvalid != 0 && block->mainchain != 0 && block->valid != 0 && block->bundlei != 0 && coin->RTheight == 0) )
return(0);
}
if ( checkbp != bp || j != bundlei )
bp = 0, bundlei = -1;
if ( 0 && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 )
{
if ( block != 0 && block->hdrsi != 0 && block->bundlei != 0 )
@ -109,7 +103,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
}
if ( addr->msgcounts.verack == 0 )
{
if ( (rand() % 100) == 0 )
if ( (rand() % 10000) == 0 )
printf("iguana_sendblockreq (%s) addrind.%d hasn't verack'ed yet\n",addr->ipaddr,addr->addrind);
//iguana_send_version(coin,addr,coin->myservices);
return(-1);
@ -123,10 +117,14 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
addr->pendblocks++;
addr->pendtime = (uint32_t)time(NULL);
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
{
if ( coin->RTheight == 0 && bp != coin->current && bp->issued[bundlei] > 1 && addr->pendtime < bp->issued[bundlei]+30 )
return(0);
bp->issued[bundlei] = addr->pendtime;
}
if ( block != 0 )
block->issued = addr->pendtime;
if ( 0 && coin->current == bp )
if ( 0 && coin->RTheight > 0 )//&& coin->current == bp )
printf("REQ.(%s) [%d:%d] %s n.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1,addr->ipaddr,addr->pendblocks);
} else printf("MSG_BLOCK null datalen.%d\n",len);
return(len);
@ -298,7 +296,6 @@ void iguana_bundletime(struct iguana_info *coin,struct iguana_bundle *bp,int32_t
starttime = block->issued;
if ( starttime == 0 || bp->issued[bundlei] > block->issued )
starttime = bp->issued[bundlei];
bp->issued[bundlei] = 1;
if ( starttime != 0 )
{
duration = (uint32_t)time(NULL) - starttime;
@ -312,13 +309,13 @@ void iguana_bundletime(struct iguana_info *coin,struct iguana_bundle *bp,int32_t
bp->totaldurations += duration;
bp->durationscount++;
}
if ( (block= bp->blocks[bundlei]) != 0 && block->lag == 0 )
if ( (block != 0 || (block= bp->blocks[bundlei]) != 0) && block->lag == 0 )
block->lag = duration;
}
}
}
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache)
void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache)
{
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,speculative=0,i,j,bundlei,copyflag,numtx; struct iguana_block *block; struct iguana_bundle *bp; uint32_t now; char str[65];
if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE )
@ -352,7 +349,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
}
}
origtxdata->zblock.RO.allocsize = sizeof(origtxdata->zblock);
if ( iguana_blockvalidate(coin,&valid,(struct iguana_block *)&origtxdata->zblock,1) < 0 )
if ( iguana_blockvalidate(myinfo,coin,&valid,(struct iguana_block *)&origtxdata->zblock,1) < 0 )
{
printf("got block that doesnt validate? %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
return;
@ -392,6 +389,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
copyflag = (coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0);
bp = 0, bundlei = -2;
bp = iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.hash2);
printf("[%d:%d].(%s) %s n%d\n",bp!=0?bp->hdrsi:-1,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr,addr->pendblocks);
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
{
block = bp->blocks[bundlei];
@ -492,25 +490,14 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
addr->recvblocks += 1.;
addr->recvtotal += recvlen;
}
if ( speculative == 0 && iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen) >= 0 )
if ( speculative == 0 && iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen,bp,block) >= 0 )
{
txdata->zblock.fpipbits = (uint32_t)addr->ipbits;
txdata->zblock.RO.recvlen = recvlen;
txdata->zblock.fpos = 0;
req->datalen = txdata->datalen;
req->ipbits = txdata->zblock.fpipbits;
/*if ( 0 )
{
struct iguana_txblock *checktxdata; struct OS_memspace checkmem; int32_t checkbundlei;
memset(&checkmem,0,sizeof(checkmem));
iguana_meminit(&checkmem,"checkmem",0,txdata->datalen + 4096,0);
if ( (checktxdata= iguana_peertxdata(coin,&checkbundlei,fname,&checkmem,(uint32_t)addr->ipbits,txdata->block.RO.hash2)) != 0 )
{
printf("check datalen.%d bundlei.%d T.%d U.%d S.%d P.%d X.%d\n",checktxdata->datalen,checkbundlei,checktxdata->numtxids,checktxdata->numunspents,checktxdata->numspends,checktxdata->numpkinds,checktxdata->numexternaltxids);
}
iguana_mempurge(&checkmem);
}*/
} //else printf("cant save block\n");
} //else printf("cant save block\n");
}
if ( txdata->zblock.fpos == 0 )
{
@ -542,6 +529,348 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
} else printf("nonz fpos.%d %s\n",txdata->zblock.fpos,bits256_str(str,origtxdata->zblock.RO.hash2));
}
void iguana_recvstats_update(struct iguana_info *coin,struct iguana_peer *addr,int32_t recvlen)
{
static uint64_t received[IGUANA_MAXPEERS],count[IGUANA_MAXPEERS],lastcount,lastreceived,last;
char str[65],str2[65],str3[65],str4[65]; uint32_t now; int32_t i; int64_t sum2= 0,sum = 0,diffr,diff; double bw = 0.;
coin->recvcount++;
coin->recvtime = (uint32_t)time(NULL);
netBLOCKS++;
if ( addr->pendblocks > 0 )
addr->pendblocks--;
addr->lastblockrecv = (uint32_t)time(NULL);
addr->recvblocks += 1.;
addr->recvtotal += recvlen;
received[addr->addrind] += recvlen;
count[addr->addrind]++;
now = (uint32_t)time(NULL);
if ( ((rand() % 10000) == 0 && now > last+60) || now > last+600 )
{
for (i=0; i<sizeof(received)/sizeof(*received); i++)
sum += received[i], sum2 += count[i];
diffr = (sum - lastreceived), diff = (sum2 - lastcount);
lastreceived = sum, lastcount = sum2;
if ( diff != 0 )
{
bw = ((double)diffr / (now - last + 1));
if ( bw > coin->maxbandwidth )
coin->maxbandwidth = bw;
}
dxblend(&coin->bandwidth,bw,.9);
printf("%s BLOCKS.%llu RECV %s ave %.1f | dup.%d %s after.%d %s %s/sec %.2f%% %s\n",coin->symbol,(long long)sum2,mbstr(str,sum),(double)sum/(sum2!=0?sum2:1),numDuplicates,mbstr(str2,sizeDuplicates),numAfteremit,mbstr(str3,sizeAfteremit),mbstr(str4,bw),coin->maxbandwidth!=0.?100.*coin->bandwidth/coin->maxbandwidth:0.,coin->maxbandwidth>4*coin->bandwidth?"SLOW":"");
last = now;
}
if ( coin->bandwidth < 0.25*coin->maxbandwidth )
{
//printf(">>SLOW.%d<< ",addr->addrind);
//iguana_blast(coin,addr);
}
}
int32_t iguana_bundlestats_update(struct iguana_info *coin,struct iguana_block **blockp,struct iguana_bundle *bp,int32_t bundlei,struct iguana_txblock *origtxdata,uint8_t *data,int32_t recvlen)
{
char str[65]; struct iguana_block *block; int32_t i,j;
*blockp = 0;
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
{
*blockp = block = bp->blocks[bundlei];
if ( bp->emitfinish != 0 )
{
numAfteremit++;
sizeAfteremit += recvlen;
if ( block != 0 )
iguana_bundletime(coin,bp,bundlei,block,1);
//printf("got [%d:%d] with emitfinish.%u\n",bp->hdrsi,bundlei,bp->emitfinish);
return(-1);
}
bp->dirty++;
if ( bundlei >= 0 && block != 0 )
{
if ( block->fpipbits != 0 && block->txvalid != 0 )
{
numDuplicates++;
sizeDuplicates += recvlen;
//printf("duplicate [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2));
if ( bits256_cmp(origtxdata->zblock.RO.hash2,block->RO.hash2) != 0 )
{
//printf("mismatched tx %s received? mainchain.%d\n",bits256_str(str,block->RO.hash2),block->mainchain);
return(-1);
}
else
{
iguana_bundletime(coin,bp,bundlei,block,1);
iguana_blockzcopyRO(coin->chain->zcash,&block->RO,0,&origtxdata->zblock.RO,0);
return(0);
}
}
else
{
iguana_bundletime(coin,bp,bundlei,block,0);
if ( 0 && bp == coin->current )
printf("recv [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2));
return(0);
}
}
}
else
{
if ( (bp= coin->current) != 0 )
{
for (i=0; i<coin->bundlescount; i++)
{
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 && bp->speculative != 0 && bp->numhashes < bp->n )
{
if ( (j= iguana_speculativefind(coin,bp,(struct iguana_block *)&origtxdata->zblock,data,recvlen)) >= 0 )
{
printf("speculative found\n");
//copyflag = 0;
//speculative = 1;
if ( (*blockp= bp->blocks[j]) != 0 )
iguana_bundletime(coin,bp,j,*blockp,0);
return(1);
}
}
}
}
}
return(0);
}
struct iguana_bundlereq *iguana_recv_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t copyflag,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,int32_t bundlei,struct iguana_txblock *txdata)
{
struct iguana_bundlereq *req; struct iguana_block *block = 0;
if ( copyflag != 0 && recvlen != 0 && (bp == 0 || bundlei < 0 || ((block= bp->blocks[bundlei]) != 0 && block->fpipbits == 0 && block->req == 0)) )
{
struct iguana_msghdr checkH;
req = iguana_bundlereq(coin,addr,'B',data,copyflag * recvlen);
req->copyflag = 1;
req->H = *H;
if ( 0 && iguana_sethdr(&checkH,coin->chain->netmagic,H->command,req->serializeddata,recvlen) > 0 && memcmp(&checkH,H,sizeof(checkH)) != 0 )
{
int z;
for (z=0; z<sizeof(checkH); z++)
printf("%02x",((uint8_t *)&checkH)[z]);
printf(" req->H datalen.%d crc.%08x error\n",recvlen,calc_crc32(0,data,recvlen));
}
}
else
{
copyflag = 0;
req = iguana_bundlereq(coin,addr,'B',0,0);
}
req->recvlen = recvlen;
req->datalen = txdata->datalen;
req->ipbits = txdata->zblock.fpipbits;
req->zblock = txdata->zblock;
req->zblock.RO.txn_count = req->numtx = txdata->zblock.RO.txn_count;
req->addr = addr;
return(req);
}
void iguana_RTgotblock(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp)
{
int32_t i; struct iguana_bundle *bp;
if ( coin->almostRT == 0 )
{
for (i=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 && bp->utxofinish <= 1 )
break;
if ( (i > coin->bundlescount-2 && coin->blocks.hwmchain.height > coin->longestchain-coin->chain->bundlesize*2) || coin->RTheight > 0 )
coin->almostRT = 1;
}
if ( coin->almostRT != 0 )
{
portable_mutex_lock(&coin->RTmutex);
iguana_RTrawdata(coin,hash2,data,recvlenp,numtxp,0);
portable_mutex_unlock(&coin->RTmutex);
}
}
int32_t iguana_txmerkle(struct iguana_info *coin,bits256 *tree,int32_t treesize,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray)
{
int32_t i,msize; bits256 merkle_root;
if ( bits256_nonz(origtxdata->zblock.RO.merkle_root) == 0 )
{
memset(&origtxdata->zblock.RO.prev_block,0,sizeof(bits256));
origtxdata->zblock.RO.recvlen = 0;
origtxdata->zblock.issued = 0;
return(-1);
}
msize = (int32_t)sizeof(bits256) * (origtxdata->zblock.RO.txn_count+1) * 2;
if ( msize <= treesize )
{
for (i=0; i<origtxdata->zblock.RO.txn_count; i++)
tree[i] = txarray[i].txid;
merkle_root = iguana_merkle(tree,origtxdata->zblock.RO.txn_count);
if ( bits256_cmp(merkle_root,origtxdata->zblock.RO.merkle_root) != 0 )
{
char str[65],str2[65];
printf(">>>>>>>>>> %s merkle mismatch.[%d] calc.(%s) vs (%s)\n",coin->symbol,origtxdata->zblock.RO.txn_count,bits256_str(str,merkle_root),bits256_str(str2,origtxdata->zblock.RO.merkle_root));
origtxdata->zblock.RO.recvlen = 0;
origtxdata->zblock.issued = 0;
return(-1);
} //else printf("matched merkle.%d\n",txn_count);
return(0);
} else printf("not enough memory for merkle verify %d vs %u\n",(int32_t)(sizeof(bits256)*(origtxdata->zblock.RO.txn_count+1)),treesize);
return(-1);
}
void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache)
{
static uint64_t totalrecv;
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t incr,i,numsaved,valid,speculative=0,bundlei,copyflag,numtx; struct iguana_bundle *bp; struct iguana_block *block; char str[65];
if ( addr == 0 )
addr = &coin->internaladdr;
if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE )
{
printf("iguana_getblockM: illegal recvlen.%d\n",recvlen);
return;
}
if ( fromcache == 0 && coin->virtualchain == 0 && addr != 0 && addr != &coin->internaladdr )
{
iguana_recvstats_update(coin,addr,recvlen);
totalrecv += recvlen;
}
origtxdata->zblock.RO.allocsize = sizeof(origtxdata->zblock);
if ( iguana_blockvalidate(myinfo,coin,&valid,(struct iguana_block *)&origtxdata->zblock,1) < 0 )
{
printf("got block that doesnt validate? %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
return;
}
iguana_peer_meminit(coin,addr);
if ( iguana_txmerkle(coin,addr->TXDATA.ptr,(int32_t)addr->TXDATA.totalsize,origtxdata,txarray) < 0 )
return;
origtxdata->zblock.txvalid = 1;
bp = 0, bundlei = -2;
if ( iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.hash2) == 0 )
{
bp = 0, bundlei = -2;
if ( iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.prev_block) == 0 )
{
//printf("gotblockM: RTblock? %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
numtx = origtxdata->zblock.RO.txn_count;
iguana_RTgotblock(coin,origtxdata->zblock.RO.hash2,data,&recvlen,&numtx);
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
}
else if ( bundlei < coin->chain->bundlesize-1 )
{
bundlei++;
iguana_hash2set(coin,"gotblockM",bp,bundlei,origtxdata->zblock.RO.hash2);
}
else // new bundle case, but bad context to extend
{
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
if ( (bp= iguana_bundlecreate(coin,&bundlei,bp->bundleheight + coin->chain->bundlesize,origtxdata->zblock.RO.hash2,zero,0)) == 0 )
{
origtxdata->zblock.issued = 0;
origtxdata->zblock.RO.recvlen = 0;
printf("gotblockM2: error finding block %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
return;
} else printf("getblockM autoextended.[%d]\n",bp->hdrsi);
}
}
if ( bp == 0 )
{
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
}
for (i=numsaved=0; i<coin->chain->bundlesize; i++)
{
if ( (block= bp->blocks[i]) != 0 && block->fpipbits != 0 && block->fpos >= 0 && block->txvalid != 0 )
numsaved++;
}
if ( (speculative= iguana_bundlestats_update(coin,&block,bp,bundlei,origtxdata,data,recvlen)) < 0 )
{
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
}
if ( block == 0 )
block = iguana_blockhashset("noblock",coin,bp->bundleheight+bundlei,origtxdata->zblock.RO.hash2,1);
if ( block->hdrsi != bp->hdrsi || block->bundlei != bundlei )
{
block->hdrsi = bp->hdrsi;
block->bundlei = bundlei;
}
if ( bp->blocks[bundlei] == 0 || bits256_nonz(bp->hashes[bundlei]) == 0 )
{
//printf("SET [%d:%d]\n",bp->hdrsi,bundlei);
//iguana_hash2set(coin,"noblock",bp,bundlei,origtxdata->zblock.RO.hash2);
bp->hashes[bundlei] = origtxdata->zblock.RO.hash2;
if ( bp->speculative != 0 )
bp->speculative[bundlei] = bp->hashes[bundlei];
bp->blocks[bundlei] = block;
}
numtx = origtxdata->zblock.RO.txn_count;
iguana_RTgotblock(coin,origtxdata->zblock.RO.hash2,data,&recvlen,&numtx);
//printf("getblockM update [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2));
block->txvalid = 1;
if ( block->fpipbits != 0 && block->fpos >= 0 )
{
static int32_t numredundant; static double redundantsize; static uint32_t lastdisp;
char str[65],str2[65];
numredundant++, redundantsize += recvlen;
if ( time(NULL) > lastdisp+30 )
{
lastdisp = (uint32_t)time(NULL);
printf("%s have %d:%d at %d | %d blocks %s redundant xfers total %s %.2f%% wasted\n",coin->symbol,bp->hdrsi,bundlei,block->fpos,numredundant,mbstr(str,redundantsize),mbstr(str2,totalrecv),100.*redundantsize/totalrecv);
}
if ( bundlei > 1 )
{
// printf("DUP s.%d [%d:%d].(%s) %s n%d\n",numsaved,bp!=0?bp->hdrsi:-1,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr,addr->pendblocks);
}
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
}
txdata = origtxdata;
if ( iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen,bp,block) >= 0 )
{
txdata->zblock.fpipbits = (uint32_t)addr->ipbits;
txdata->zblock.RO.recvlen = recvlen;
txdata->zblock.fpos = 0;
copyflag = (coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0);
req = iguana_recv_bundlereq(coin,addr,copyflag,H,data,recvlen,bp,bundlei,txdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
printf("[%d:%d].s%d %s Q.(%s) %s\n",bp->hdrsi,bundlei,numsaved,coin->symbol,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr);
//if ( (bp == coin->current || (coin->peers != 0 && ) && (rand() % coin->chain->bundlesize) < numsaved )
if ( numsaved < coin->chain->bundlesize )
{
for (i=numsaved=0; i<coin->chain->bundlesize; i++)
{
if ( (block= bp->blocks[i]) != 0 && block->fpipbits != 0 && block->fpos >= 0 && block->txvalid != 0 )
numsaved++;
}
if ( numsaved < coin->chain->bundlesize && bp->startutxo == 0 )
{
if ( (incr= coin->peers->numranked) == 0 )
incr = 1;
i = addr->addrind % incr;
for (; i<coin->chain->bundlesize; i+=incr)
{
if ( (bp->issued[i] == 0 && bits256_nonz(bp->hashes[i]) != 0) && ((block= bp->blocks[i]) == 0 || bits256_cmp(bp->hashes[i],block->RO.hash2) != 0 || block->fpipbits == 0 || block->fpos < 0 || block->txvalid == 0) )
{
bp->issued[i] = 1;
iguana_sendblockreqPT(coin,addr,0,-1,bp->hashes[i],0);
//printf("numsaved.%d auto issue.[%d:%d] %s\n",numsaved,bp->hdrsi,i,addr->ipaddr);
break;
} //else printf("numsaved.%d SKIP auto issue.[%d:%d] %s\n",numsaved,bp->hdrsi,i,addr->ipaddr);
}
}
else if ( bp->queued == 0 && bp->startutxo == 0 )
{
iguana_bundleQ(myinfo,coin,bp,0);
//printf("numsaved.%d [%d] %s\n",numsaved,bp->hdrsi,addr->ipaddr);
}
}
} else printf("nonz fpos.%d %s\n",txdata->zblock.fpos,bits256_str(str,origtxdata->zblock.RO.hash2));
}
void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *txids,int32_t n)
{
struct iguana_bundlereq *req;
@ -553,7 +882,9 @@ void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256
int32_t iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_zblock *zblocks,int32_t n)
{
struct iguana_bundlereq *req; int32_t i,num;
struct iguana_bundlereq *req; int32_t i,num; struct iguana_bundle *bp;
if ( n <= 1 )
return(-1);
if ( addr != 0 )
{
static uint32_t hdrsreceived[IGUANA_MAXPEERS];
@ -564,7 +895,7 @@ int32_t iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,str
uint32_t i,sum = 0;
for (i=0; i<sizeof(hdrsreceived)/sizeof(*hdrsreceived); i++)
sum += hdrsreceived[i];
printf("TOTAL HDRS RECEIVED %u -> %s\n",sum,mbstr(str,sum*80));
printf("%s TOTAL HDRS RECEIVED %u -> %s\n",coin->symbol,sum,mbstr(str,sum*80));
}
addr->recvhdrs++;
if ( addr->pendhdrs > 0 )
@ -578,6 +909,13 @@ int32_t iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,str
addr->numRThashes = num;
}
}
if ( strcmp("BTC",coin->symbol) != 0 && n == 2 )
iguana_sendblockreqPT(coin,addr,0,-1,zblocks[1].RO.hash2,0);
for (i=0; i<coin->bundlescount; i++)
{
if ( (bp= coin->bundles[i]) != 0 && bits256_cmp(zblocks[1].RO.hash2,bp->hashes[1]) == 0 && bp->numhashes >= coin->chain->bundlesize )
return(-1);
}
req = iguana_bundlereq(coin,addr,'H',0,0);
req->blocks = zblocks, req->n = n;
HDRnet++;
@ -649,19 +987,23 @@ uint32_t iguana_allhashcmp(struct supernet_info *myinfo,struct iguana_info *coin
prev->hh.next = block;
block->hh.prev = prev;
}
//if ( bp->hdrsi < coin->MAXBUNDLES )
// iguana_blockQ(coin,bp,i,blockhashes[i],0);
if ( bp->startutxo == 0 && bp->issued[i] == 0 )
{
iguana_blockQ("allhashes",coin,bp,i,blockhashes[i],1);
iguana_blockQ("allhashes",coin,bp,i,blockhashes[i],0);
n++;
}
} else printf("no allhashes block.%p or mismatch.%p\n",block,bp->blocks[i]);
prev = block;
}
coin->allhashes++;
n = 0;
if ( bp->hdrsi < coin->MAXBUNDLES || (coin->current != 0 && coin->lastpending != 0 && bp->hdrsi >= coin->current->hdrsi && bp->hdrsi <= coin->lastpending->hdrsi) )
n = iguana_bundleissuemissing(myinfo,coin,bp,1,3.);
if ( 0 && n > 0 )
//n = 0;
//if ( bp->hdrsi < coin->MAXBUNDLES || (coin->current != 0 && coin->lastpending != 0 && bp->hdrsi >= coin->current->hdrsi && bp->hdrsi <= coin->lastpending->hdrsi) )
// n = iguana_bundleissuemissing(myinfo,coin,bp,1,3.);
if ( 0 && n > 2 )
printf("ALLHASHES FOUND! %d allhashes.%d issued %d\n",bp->bundleheight,coin->allhashes,n);
if ( bp->queued == 0 )
iguana_bundleQ(coin,bp,bp->n*5 + (rand() % 500));
//if ( bp->queued == 0 )
// iguana_bundleQ(myinfo,coin,bp,bp->n*5 + (rand() % 500));
return(bp->queued);
}
}
@ -678,16 +1020,6 @@ void iguana_bundlespeculate(struct iguana_info *coin,struct iguana_bundle *bp,in
//fprintf(stderr,"Afound block -> %d %d hdr.%s\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
}
/*else if ( bp->speculative != 0 && bundlei < bp->numspec && memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)) == 0 )
{
bundlei += offset;
if ( bundlei < bp->n && bundlei < bp->numspec && time(NULL) > bp->issued[bundlei]+30 )
{
char str[65]; printf("speculative req[%d] %s\n",bundlei,bits256_str(str,bp->speculative[bundlei]));
iguana_blockQ("speculate",coin,0,-1,bp->speculative[bundlei],0);
bp->issued[bundlei] = (uint32_t)time(NULL);
}
} */ //else printf("speculative.%p %d vs %d cmp.%d\n",bp->speculative,bundlei,bp->numspec,bp->speculative!=0?memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)):-1);*/
}
int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block)
@ -751,7 +1083,7 @@ int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,i
void iguana_bundle_set(struct iguana_info *coin,struct iguana_block *block,int32_t height)
{
int32_t hdrsi,bundlei; struct iguana_bundle *bp;
int32_t hdrsi,bundlei; struct iguana_bundle *bp; char str[65];
if ( block->height < 0 || block->height == height )
{
hdrsi = (height / coin->chain->bundlesize);
@ -764,7 +1096,7 @@ void iguana_bundle_set(struct iguana_info *coin,struct iguana_block *block,int32
bp->speculative[bundlei] = block->RO.hash2;
//char str[65]; printf("SET %s ht.%d in [%d:%d]\n",bits256_str(str,block->RO.hash2),height,hdrsi,bundlei);
} //else printf("iguana_bundle_set: no bundle at [%d]\n",hdrsi);
} else printf("iguana_bundle_set: mismatch ht.%d vs %d\n",block->height,height);
} else printf("iguana_bundle_set: %s mismatch ht.%d vs %d\n",bits256_str(str,block->RO.hash2),block->height,height);
}
void iguana_hwmchain_set(struct iguana_info *coin,struct iguana_block *block,int32_t height)
@ -774,12 +1106,12 @@ void iguana_hwmchain_set(struct iguana_info *coin,struct iguana_block *block,int
if ( block->height == height )
{
iguana_blockcopy(coin->chain->zcash,coin->chain->auxpow,coin,(struct iguana_block *)&coin->blocks.hwmchain,block);
char str[65]; printf("SET HWM.%s ht.%d\n",bits256_str(str,block->RO.hash2),height);
char str[65]; printf("SET %s HWM.%s ht.%d\n",coin->symbol,bits256_str(str,block->RO.hash2),height);
} else printf("iguana_hwmchain_set: mismatched ht.%d vs %d\n",block->height,height);
}
}
void iguana_mainchain_clear(struct iguana_info *coin,struct iguana_block *mainchain,struct iguana_block *oldhwm,int32_t n)
void iguana_mainchain_clear(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *mainchain,struct iguana_block *oldhwm,int32_t n)
{
int32_t i,height; char str[65]; struct iguana_block *tmp = oldhwm;
if ( mainchain != oldhwm )
@ -787,15 +1119,16 @@ void iguana_mainchain_clear(struct iguana_info *coin,struct iguana_block *mainch
height = oldhwm->height;
for (i=0; i<n; i++,height--)
{
iguana_RTnewblock(myinfo,coin,tmp);
bits256_str(str,tmp->RO.hash2);
if ( tmp->mainchain == 0 )
printf("%s iguana_mainchain_clear: unexpected non-main ht.%d %s\n",coin->symbol,tmp->height,str);
printf("%s iguana_mainchain_clear: ORPHANED ht.%d %s\n",coin->symbol,tmp->height,str);
else if ( tmp->height != height )
printf("iguana_mainchain_clear: unexpected ht.%d vs %d %s\n",tmp->height,height,str);
else
{
tmp->mainchain = 0;
printf("CLEAR mainchain.%d %s\n",height,str);
//printf("CLEAR %s mainchain.%d %s\n",coin->symbol,height,str);
}
if ( (tmp= iguana_blockfind("clear",coin,tmp->RO.prev_block)) == 0 )
{
@ -803,7 +1136,7 @@ void iguana_mainchain_clear(struct iguana_info *coin,struct iguana_block *mainch
return;
}
}
if ( tmp != mainchain && coin->RTheight > 0 )
if ( 0 && tmp != mainchain && coin->RTheight > 0 )
printf("iguana_mainchain_clear: unexpected mismatch ht.%d vs %d %s\n",tmp->height,mainchain->height,bits256_str(str,tmp->RO.hash2));
}
}
@ -834,7 +1167,7 @@ int32_t iguana_height_estimate(struct iguana_info *coin,struct iguana_block **ma
// main context, ie single threaded
struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock)
{
struct iguana_block *block,*prevblock,*tmp,*mainchain,*hwmblock; bits256 zero,hash2,prevhash2; struct iguana_bundle *prevbp,*bp = 0; int32_t i,newheight,prevbundlei,bundlei = -2; // struct iguana_ramchain blockR;
struct iguana_block *block,*prevblock,*tmp,*mainchain,*hwmblock; bits256 zero,hash2,prevhash2; struct iguana_bundle *prevbp,*bp = 0; int32_t i,n,hdrsi,newheight,prevbundlei,bundlei = -2; // struct iguana_ramchain blockR;
*bundleip = -2; *blockp = 0;
if ( origblock == 0 )
return(0);
@ -853,17 +1186,26 @@ struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguan
{
if ( (newheight= iguana_height_estimate(coin,&mainchain,block)) >= coin->blocks.hwmchain.height )
{
iguana_mainchain_clear(coin,mainchain,hwmblock,coin->blocks.hwmchain.height-mainchain->height);
tmp = block;
for (i=0; i<newheight-mainchain->height; i++)
iguana_mainchain_clear(myinfo,coin,mainchain,hwmblock,coin->blocks.hwmchain.height-mainchain->height);
n = (newheight - mainchain->height);
for (i=1; i<n; i++)
{
iguana_bundle_set(coin,tmp,newheight-i);
if ( (tmp= iguana_blockfind("hwmprev",coin,tmp->RO.prev_block)) == 0 )
break;
iguana_RTnewblock(myinfo,coin,tmp);
hdrsi = ((mainchain->height+i) / coin->chain->bundlesize);
bundlei = ((mainchain->height+i) % coin->chain->bundlesize);
if ( hdrsi < coin->bundlescount && (bp= coin->bundles[hdrsi]) != 0 )
{
if ( (tmp= bp->blocks[hdrsi]) != 0 && tmp->height == mainchain->height+i )
{
iguana_bundle_set(coin,tmp,mainchain->height+i);
iguana_RTnewblock(myinfo,coin,tmp);
} else break;
}
}
if ( mainchain != hwmblock )
if ( i == n && mainchain != hwmblock )
{
iguana_hwmchain_set(coin,mainchain,mainchain->height); // trigger reprocess
iguana_RTnewblock(myinfo,coin,mainchain);
}
}
else if ( coin->RTheight > 0 && newheight == coin->RTheight )
{
@ -877,7 +1219,7 @@ struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguan
{
if ( iguana_bundlehashadd(coin,bp,bundlei,block) < 0 )
{
if ( bp->emitfinish == 0 && block->issued == 0 && strcmp("BTC",coin->symbol) != 0 )//|| coin->PREFETCHLAG < 0) )
if ( bp->emitfinish == 0 && bp->issued[bundlei] == 0 && block->issued == 0 && strcmp("BTC",coin->symbol) != 0 )//|| coin->PREFETCHLAG < 0) )
iguana_blockQ("bundleset",coin,bp,bundlei,block->RO.hash2,1);//coin->current == 0 || bp->hdrsi <= coin->current->hdrsi+coin->MAXBUNDLES);
}
//fprintf(stderr,"bundle found %d:%d\n",bp->hdrsi,bundlei);
@ -907,7 +1249,7 @@ struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguan
if ( (bp= iguana_bundlecreate(coin,bundleip,prevbp->bundleheight + coin->chain->bundlesize,hash2,zero,0)) != 0 )
{
if ( bp->queued == 0 )
iguana_bundleQ(coin,bp,1000);
iguana_bundleQ(myinfo,coin,bp,1000);
}
}
if ( prevbundlei < coin->chain->bundlesize-1 )
@ -959,7 +1301,7 @@ void iguana_checklongestchain(struct iguana_info *coin,struct iguana_bundle *bp,
struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundlereq *req,struct iguana_zblock *zblocks,int32_t n,int32_t *newhwmp)
{
int32_t i,bundlei,match; struct iguana_block *block; bits256 prevhash2; uint8_t serialized[sizeof(struct iguana_msgblock) + sizeof(struct iguana_msgblockhdr_zcash)]; struct iguana_peer *addr; struct iguana_bundle *bp,*firstbp = 0;
int32_t i,bundlei,match; struct iguana_block *block; bits256 prevhash2; uint8_t serialized[sizeof(struct iguana_msgblock) + sizeof(struct iguana_msgzblockhdr)]; struct iguana_peer *addr; struct iguana_bundle *bp,*firstbp = 0;
if ( zblocks == 0 )
{
printf("iguana_recvblockhdrs null blocks?\n");
@ -988,8 +1330,11 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc
if ( (bp= iguana_bundleset(myinfo,coin,&block,&bundlei,(struct iguana_block *)&zblocks[i])) != 0 )
{
bp->dirty++;
if ( 0 && bp->issued[bundlei] == 0 && bp->hdrsi < coin->MAXBUNDLES )
iguana_blockQ("recvhdr",coin,bp,bundlei,block->RO.hash2,1);
if ( bp->issued[bundlei] == 0 && coin->RTheight > 0 )
{
bp->issued[bundlei] = 0;
iguana_blockQ("recvhdr",coin,bp,bundlei,block->RO.hash2,0);
}
//printf("{%d:%d} ",bp->hdrsi,bundlei);
if ( i == 0 )
{
@ -1018,7 +1363,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc
if ( firstbp->queued == 0 )
{
//fprintf(stderr,"firstbp blockQ %d\n",firstbp->bundleheight);
iguana_bundleQ(coin,firstbp,1000);
iguana_bundleQ(myinfo,coin,firstbp,1000);
}
}
if ( i == n && i == match && firstbp == coin->current && (addr= req->addr) != 0 )
@ -1026,7 +1371,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc
addr->RThashes[i] = firstbp->hashes[0];
for (i=1; i<n; i++)
{
iguana_serialize_block(coin->chain,&addr->RThashes[i],serialized,(struct iguana_block *)&zblocks[i]);
iguana_serialize_block(myinfo,coin->chain,&addr->RThashes[i],serialized,(struct iguana_block *)&zblocks[i]);
}
//memcpy(addr->RThashes,blockhashes,bp->numspec * sizeof(*addr->RThashes));
addr->numRThashes = n;
@ -1035,7 +1380,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc
return(req);
}
void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp)
void iguana_autoextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp)
{
char hashstr[65]; struct iguana_bundle *newbp; int32_t bundlei; static const bits256 zero;
if ( bp->hdrsi == coin->bundlescount-1 && bits256_nonz(bp->nextbundlehash2) != 0 )
@ -1058,7 +1403,7 @@ void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp)
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
//char str[65],str2[65]; printf("EXTEND last bundle %s/%s ht.%d\n",bits256_str(str,newbp->hashes[0]),bits256_str(str2,bp->nextbundlehash2),newbp->bundleheight);
if ( newbp->queued == 0 )
iguana_bundleQ(coin,newbp,1000);
iguana_bundleQ(myinfo,coin,newbp,1000);
}
}
}
@ -1101,7 +1446,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
}
//printf("call allhashes\n");
if ( 0 && bp->hdrsi == coin->bundlescount-1 )
iguana_autoextend(coin,bp);
iguana_autoextend(myinfo,coin,bp);
if ( iguana_allhashcmp(myinfo,coin,bp,blockhashes,num) > 0 )
return(req);
//printf("done allhashes\n");
@ -1118,22 +1463,22 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
}
}
}
if ( strcmp("BTC",coin->symbol) != 0 && (bp->speculative == 0 || num > bp->numspec) && bp->emitfinish == 0 )
if ( strcmp("BTCD",coin->symbol) == 0 && (bp->speculative == 0 || num > bp->numspec) && bp->emitfinish == 0 )
{
//printf("FOUND speculative.%s BLOCKHASHES[%d] ht.%d\n",bits256_str(str,blockhashes[1]),num,bp->bundleheight);
if ( bp->speculative == 0 )
{
bp->speculative = mycalloc('s',bp->n+1,sizeof(*bp->speculative));
for (i=0; i<bp->n; i++)
if ( GETBIT(bp->haveblock,i) == 0 )
bp->issued[i] = 0;
iguana_bundleissuemissing(myinfo,coin,bp,3,1.);
//for (i=0; i<bp->n; i++)
// if ( GETBIT(bp->haveblock,i) == 0 )
// bp->issued[i] = 0;
//iguana_bundleissuemissing(myinfo,coin,bp,3,1.);
}
for (i=1; i<num&&i<=bp->n; i++)
{
bp->speculative[i] = blockhashes[i];
//if ( bp->blocks[i] == 0 || bp->blocks[i]->issued == 0 )
// iguana_blockQ("speculate",coin,bp,-i,blockhashes[i],0);
if ( bp->blocks[i] == 0 || bp->blocks[i]->issued == 0 )
iguana_blockQ("speculate",coin,bp,-i,blockhashes[i],0);
if ( bp->blocks[i] == 0 )
bp->blocks[i] = iguana_blockhashset("recvhashes3",coin,bp->bundleheight+i,blockhashes[i],1);
//printf("speculate new issue [%d:%d]\n",bp->hdrsi,i);
@ -1198,7 +1543,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
{
if ( (block= iguana_blockfind("recvhashes2",coin,blockhashes[1])) == 0 )
{
iguana_blockhashset("recvhashes3",coin,-1,blockhashes[1],1);
//iguana_blockhashset("recvhashes3",coin,-1,blockhashes[1],1);
if ( (block= iguana_blockfind("recvhashes4",coin,blockhashes[1])) != 0 )
iguana_blockQ("recvhash6",coin,0,-6,blockhashes[1],1); // should be RT block
}
@ -1208,9 +1553,9 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
}
if ( strcmp("BTC",coin->symbol) != 0 )
{
iguana_blockQ("recvhash7",coin,0,-7,blockhashes[1],1);
//iguana_blockQ("recvhash7",coin,0,-7,blockhashes[1],1);
iguana_blockQ("recvhash7",coin,0,-7,blockhashes[num-1],1);
//if ( 1 && coin->RTheight > 0 )
if ( 1 && coin->RTheight > 0 )
{
for (i=1; i<num; i++)
{
@ -1229,8 +1574,6 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundlereq *req,struct iguana_zblock *origblock,int32_t numtx,int32_t datalen,int32_t recvlen,int32_t *newhwmp)
{
struct iguana_bundle *bp=0,*prev; int32_t n,bundlei = -2; struct iguana_block *block,*next,*prevblock; char str[65]; bits256 hash2;
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
printf("%s received.(%s) %s\n",coin->symbol,bits256_str(str,origblock->RO.hash2),addr->ipaddr);
if ( (block= iguana_blockfind("recv",coin,origblock->RO.hash2)) != 0 )
iguana_blockcopy(coin->chain->zcash,coin->chain->auxpow,coin,block,(struct iguana_block *)origblock);
else if ( (block= iguana_blockhashset("recvblock",coin,-1,origblock->RO.hash2,1)) == 0 )
@ -1240,12 +1583,17 @@ struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct ig
}
if ( bits256_nonz(origblock->RO.prev_block) != 0 )
{
if ( (prevblock= iguana_blockfind("prev",coin,origblock->RO.prev_block)) != 0 && prevblock->height+1 > coin->longestchain )
coin->longestchain = prevblock->height+1;
else iguana_blockQ("prev",coin,0,-1,origblock->RO.prev_block,1);
if ( (prevblock= iguana_blockfind("prev",coin,origblock->RO.prev_block)) != 0 )
{
if ( prevblock->height+1 > coin->longestchain )
coin->longestchain = prevblock->height+1;
} else iguana_blockQ("prev",coin,0,-1,origblock->RO.prev_block,1);
}
//printf("%s received.(%s) %s\n",coin->symbol,bits256_str(str,origblock->RO.hash2),addr->ipaddr);
if ( (bp= iguana_bundleset(myinfo,coin,&block,&bundlei,(struct iguana_block *)origblock)) != 0 && bp == coin->current && block != 0 && bp->speculative != 0 && bundlei >= 0 )
{
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
printf("%s received.(%s) %s\n",coin->symbol,bits256_str(str,origblock->RO.hash2),addr->ipaddr);
if ( bp->speculative != 0 && bp->numspec <= bundlei )
{
bp->speculative[bundlei] = block->RO.hash2;
@ -1258,7 +1606,7 @@ struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct ig
block = iguana_bundleblock(coin,&hash2,bp,bundlei);
}
//printf("autoadd [%d:%d]\n",bp->hdrsi,bundlei);
} // else printf("couldnt find.(%s)\n",bits256_str(str,block->RO.hash2));
} //else printf("couldnt find.(%s)\n",bits256_str(str,block->RO.hash2));
if ( bp != 0 )
{
bp->dirty++;
@ -1374,12 +1722,11 @@ int32_t iguana_reqblocks(struct supernet_info *myinfo,struct iguana_info *coin)
int32_t hdrsi,lflag,bundlei,iters=0,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp;
if ( (block= iguana_blockfind("hwmcheck",coin,coin->blocks.hwmchain.RO.hash2)) == 0 || block->mainchain == 0 || block->height != coin->blocks.hwmchain.height )
{
printf("HWM mismatch ht.%d vs %d or not mainchain.%d\n",block->height,coin->blocks.hwmchain.height,block->mainchain);
//printf("HWM %s mismatch ht.%d vs %d or not mainchain.%d\n",coin->symbol,block->height,coin->blocks.hwmchain.height,block->mainchain);
if ( coin->blocks.hwmchain.height > 0 )
{
if ( (block= iguana_blockfind("hwmcheckb",coin,coin->blocks.hwmchain.RO.prev_block)) != 0 )
{
printf("decrement HWM\n");
iguana_blockzcopy(coin->chain->zcash,(struct iguana_block *)&coin->blocks.hwmchain,block);
return(0);
}
@ -1531,7 +1878,8 @@ int32_t iguana_processrecvQ(struct supernet_info *myinfo,struct iguana_info *coi
*newhwmp = 0;
while ( flag < IGUANA_MAXITERATIONS && coin->active != 0 && (req= queue_dequeue(&coin->recvQ,0)) != 0 )
{
flag++;
if ( req->type != 'H' )
flag++;
//fprintf(stderr,"%s flag.%d %s recvQ.%p type.%c n.%d\n",coin->symbol,flag,req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n);
if ( req->type == 'B' ) // one block with all txdata
{
@ -1574,9 +1922,9 @@ int32_t iguana_processrecvQ(struct supernet_info *myinfo,struct iguana_info *coi
int32_t iguana_needhdrs(struct iguana_info *coin)
{
if ( coin->longestchain == 0 || coin->blocks.hashblocks < coin->longestchain-coin->chain->bundlesize )
//if ( coin->longestchain == 0 || coin->blocks.hashblocks < coin->longestchain-coin->chain->bundlesize )
return(1);
else return(0);
//else return(0);
}
int32_t iguana_reqhdrs(struct iguana_info *coin)
@ -1591,25 +1939,30 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
if ( (bp= coin->bundles[i]) != 0 && (bp == coin->current || bp->hdrsi == coin->blocks.hwmchain.height/coin->chain->bundlesize || i == coin->bundlescount-1 || bp->numhashes < bp->n) )
{
if ( bp == coin->current )
lag = 13;
lag = 7;
else if ( coin->current == 0 || bp->hdrsi > coin->current->hdrsi+coin->MAXBUNDLES )
continue;
else lag = 17;
if ( time(NULL) > bp->issuetime+lag )
{
if ( 0 && bp == coin->current )
printf("LAG.%ld hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",time(NULL)-bp->hdrtime,i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
printf("LAG.%d hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",(uint32_t)(time(NULL)-bp->hdrtime),i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
if ( bp->issuetime == 0 )
coin->numpendings++;
init_hexbytes_noT(hashstr,bp->hashes[0].bytes,sizeof(bits256));
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
if ( bp == coin->current && coin->blocks.hwmchain.height > 100 )
if ( bp == coin->current )
{
init_hexbytes_noT(hashstr,bp->hashes[0].bytes,sizeof(bits256));
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
//printf("%s issue HWM HDRS [%d] %s\n",coin->symbol,bp->hdrsi,hashstr);
bits256 hash2 = iguana_blockhash(coin,coin->blocks.hwmchain.height-10);
init_hexbytes_noT(hashstr,hash2.bytes,sizeof(bits256));
//printf("%s issue HWM HDRS %d-10 %s\n",coin->symbol,coin->blocks.hwmchain.height,hashstr);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
if ( coin->blocks.hwmchain.height > 10 )
{
bits256 hash2 = iguana_blockhash(coin,coin->blocks.hwmchain.height-10);
init_hexbytes_noT(hashstr,hash2.bytes,sizeof(bits256));
//printf("%s issue HWM HDRS %d-10 %s\n",coin->symbol,coin->blocks.hwmchain.height,hashstr);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
}
}
//printf("hdrsi.%d reqHDR.(%s) numhashes.%d\n",bp->hdrsi,hashstr,bp->numhashes);
if ( 1 )
@ -1690,8 +2043,13 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
return(0);
height = block->height;
}
if ( bp != 0 && bp->emitfinish != 0 )
return(0);
if ( bp != 0 )
{
if ( bp->emitfinish != 0 )
return(0);
if ( coin->RTheight == 0 && bp->issued[bundlei] > 0 )
return(0);
}
if ( priority != 0 )
str = "priorityQ", Q = &coin->priorityQ;
else str = "blocksQ", Q = &coin->blocksQ;
@ -1842,7 +2200,7 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin
int32_t newhwm = 0,hwmheight,flag = 0; char str[2000];
hwmheight = coin->blocks.hwmchain.height;
coin->RTramchain_busy = 1;
if ( coin->balanceflush != 0 )
if ( coin->balanceflush != 0 && coin->longestchain > coin->chain->bundlesize )
{
fprintf(stderr,"%s call balanceflush\n",coin->symbol);
//portable_mutex_lock(&coin->RTmutex);
@ -1866,10 +2224,10 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin
}
}
flag += iguana_processrecvQ(myinfo,coin,&newhwm);
if ( coin->RTheight == 0 || (rand() % 30) == 0 )
if ( coin->RTheight == 0 || (rand() % 7) == 0 )
flag += iguana_reqblocks(myinfo,coin);
iguana_jsonQ(myinfo,coin);
if ( time(NULL) > coin->laststats+30 )
if ( time(NULL) > coin->laststats+3 )
{
flag += iguana_reqhdrs(coin);
iguana_bundlestats(myinfo,coin,str,IGUANA_DEFAULTLAG);

4
iguana/iguana_rpc.c

@ -23,7 +23,7 @@
char *sglue(GLUEARGS,char *agent,char *method)
{
char *retstr,*rpcretstr,*walletstr,checkstr[64],dcheckstr[64]; cJSON *retjson,*tmpjson,*result,*error,*wallet; int32_t i,j,len; int64_t val; double dval;
char *retstr,*rpcretstr,*walletstr,checkstr[65],dcheckstr[65]; cJSON *retjson,*tmpjson,*result,*error,*wallet; int32_t i,j,len; int64_t val; double dval;
if ( json == 0 )
json = cJSON_CreateObject();
//printf("sglue.(%s)\n",jprint(json,0));
@ -1107,7 +1107,7 @@ void iguana_rpcloop(void *args)
sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen);
if ( sock < 0 )
{
//printf("iguana_rpcloop ERROR on accept usock.%d\n",sock);
//printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno));
continue;
}
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));

24
iguana/iguana_scripts.c

@ -91,11 +91,11 @@ int32_t bitcoin_p2shscript(uint8_t *script,int32_t n,const uint8_t *p2shscript,c
script[n++] = (p2shlen & 0xff);
script[n++] = ((p2shlen >> 8) & 0xff);
}
else
else if ( p2shlen > 76 )
{
script[n++] = 0x4c;
script[n++] = p2shlen;
}
} else script[n++] = p2shlen;
memcpy(&script[n],p2shscript,p2shlen), n += p2shlen;
return(n);
}
@ -287,7 +287,7 @@ int32_t iguana_scriptgen(struct iguana_info *coin,int32_t *Mp,int32_t *nump,char
int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp)
{
static uint8_t zero_rmd160[20];
char hexstr[8192]; uint8_t sha256[32],*script,type; int32_t i,n,m,plen;
char hexstr[8192]; uint8_t *script,type; int32_t i,n,m,plen;
vp->N = 1;
vp->M = 1;
type = IGUANA_SCRIPT_STRANGE;
@ -301,7 +301,6 @@ int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp)
//vcalc_sha256(0,sha256,vp->spendscript,vp->spendlen); // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
//calc_rmd160(0,zero_rmd160,sha256,sizeof(sha256)); // b472a266d0bd89c13706a4132ccfb16f7c3b9fcb
init_hexbytes_noT(hexstr,zero_rmd160,20);
char str[65]; printf("iguana_calcrmd160 zero len %s -> %s\n",bits256_str(str,*(bits256 *)sha256),hexstr);
}
memcpy(vp->rmd160,zero_rmd160,sizeof(zero_rmd160));
return(IGUANA_SCRIPT_NULL);
@ -447,6 +446,18 @@ int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info
return(vp->type);
}
char *iguana_scriptaddress(struct iguana_info *coin,char *coinaddr,uint8_t *script,int32_t scriptlen)
{
struct vin_info V;
iguana_calcrmd160(coin,0,&V,script,scriptlen,GENESIS_PUBKEY,0,0xffffffff);
if ( V.coinaddr[0] != 0 )
{
strcpy(coinaddr,V.coinaddr);
return(coinaddr);
}
return(0);
}
//error memalloc mem.0x7f6fc6e4a2a8 94.242.229.158 alloc 1 used 2162688 totalsize.2162688 -> 94.242.229.158 (nil)
int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t *sigsizep,uint32_t *pubkeysizep,uint8_t **userdatap,uint32_t *userdatalenp,struct vin_info *vp,uint8_t *scriptsig,int32_t len,int32_t spendtype)
@ -495,7 +506,8 @@ int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t *
}
vp->numpubkeys = j;
*userdatap = &scriptsig[n];
*userdatalenp = (len - n);
if ( len > n )
*userdatalenp = (len - n);
p2shscript = 0;
while ( n < len )
{
@ -681,6 +693,8 @@ int32_t iguana_vinscriptdecode(struct iguana_info *coin,struct iguana_ramchain *
if ( p2shlen > 0 && p2shlen < IGUANA_MAXSCRIPTSIZE )
{
if ( p2shlen <= 75 )
_script[scriptlen++] = p2shlen;
else if ( p2shlen <= 0xff )
_script[scriptlen++] = 0x4c, _script[scriptlen++] = p2shlen;
else _script[scriptlen++] = 0x4d, _script[scriptlen++] = p2shlen & 0xff, _script[scriptlen++] = (p2shlen>>8) & 0xff;
//printf("p2shlen.%d\n",p2shlen);

4
iguana/iguana_secp.c

@ -68,7 +68,7 @@ bits256 bitcoin_pubkey33(secp256k1_context *ctx,uint8_t *data,bits256 privkey)
{
if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 )
{
printf("bitcoin_sign illegal privkey\n");
//printf("bitcoin_sign illegal privkey\n");
return(pubkey);
}
if ( secp256k1_ec_pubkey_create(ctx,&secppub,privkey.bytes) != 0 )
@ -108,7 +108,7 @@ int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256
{
if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 )
{
printf("bitcoin_sign illegal privkey\n");
//printf("bitcoin_sign illegal privkey\n");
return(-1);
}
if ( secp256k1_context_randomize(ctx,seed.bytes) != 0 )

120
iguana/iguana_sign.c

@ -62,7 +62,7 @@ int32_t iguana_vinparse(struct iguana_info *coin,int32_t rwflag,uint8_t *seriali
else
{
if ( msg->vinscript != 0 && msg->scriptlen > 0 )
memcpy(&serialized[len],msg->vinscript,msg->scriptlen), len += msg->scriptlen; // pubkeys here
memcpy(&serialized[len],msg->vinscript,msg->scriptlen), len += msg->scriptlen; // pubkeys here
if ( msg->userdatalen > 0 && msg->userdata != 0 )
{
//printf("userdata.%d scriptlen.%d\n",msg->userdatalen,msg->scriptlen);
@ -111,14 +111,17 @@ int32_t iguana_voutparse(int32_t rwflag,uint8_t *serialized,struct iguana_msgvou
}
if ( rwflag == 0 )
msg->pk_script = &serialized[len];
else memcpy(&serialized[len],msg->pk_script,msg->pk_scriptlen);
if ( 0 )
else if ( msg->pk_scriptlen > 0 )
{
int32_t i;
for (i=0; i<msg->pk_scriptlen; i++)
printf("%02x",msg->pk_script[i]);
printf(" [%p] scriptlen.%d rwflag.%d %.8f\n",msg->pk_script,msg->pk_scriptlen,rwflag,dstr(msg->value));
}
memcpy(&serialized[len],msg->pk_script,msg->pk_scriptlen);
if ( 0 )
{
int32_t i;
for (i=0; i<msg->pk_scriptlen; i++)
printf("%02x",msg->pk_script[i]);
printf(" [%p] scriptlen.%d rwflag.%d %.8f\n",msg->pk_script,msg->pk_scriptlen,rwflag,dstr(msg->value));
}
} // else serialized[len++] = 0;
len += msg->pk_scriptlen;
return(len);
}
@ -154,7 +157,10 @@ int32_t iguana_parsehexstr(uint8_t **destp,uint16_t *lenp,uint8_t *dest2,int32_t
n = (int32_t)strlen(hexstr) >> 1;
//printf("addhex.(%s) %d\n",hexstr,n);
if ( serialized == 0 )
serialized = *destp;
{
if ( (serialized= *destp) == 0 )
printf("iguana_parsehexstr null serialized and destp\n");
}
if ( serialized != 0 )
{
decode_hex(serialized,n,hexstr);
@ -171,7 +177,7 @@ int32_t iguana_parsehexstr(uint8_t **destp,uint16_t *lenp,uint8_t *dest2,int32_t
int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvin *vin,cJSON *vinobj,struct vin_info *V)
{
struct iguana_waddress *waddr; struct iguana_waccount *wacct; uint8_t lastbyte; uint32_t tmp=0; int32_t i,n,starti,suppress_pubkeys,siglen,plen,m,rwflag=1,need_op0=0,len = 0; char *userdata,*pubkeystr,*hexstr = 0,*redeemstr = 0,*spendstr = 0; cJSON *scriptjson = 0,*obj,*pubkeysjson = 0;
struct iguana_outpoint outpt; struct iguana_waddress *waddr; struct iguana_waccount *wacct; uint8_t lastbyte; uint32_t tmp=0; int32_t i,n,starti,suppress_pubkeys,siglen,plen,m,rwflag=1,need_op0=0,len = 0; char *userdata=0,*pubkeystr,*hexstr = 0,*redeemstr = 0,*spendstr = 0; cJSON *scriptjson = 0,*obj,*pubkeysjson = 0;
//printf("PARSEVIN.(%s) vin.%p\n",jprint(vinobj,0),vin);
if ( V == 0 )
memset(vin,0,sizeof(*vin));
@ -218,8 +224,9 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
{
if ( vin->vinscript == 0 )
{
if ( (V->unspentind= iguana_RTunspentindfind(myinfo,coin,V->coinaddr,V->spendscript,&V->spendlen,&V->amount,&V->height,vin->prev_hash,vin->prev_vout,coin->bundlescount-1,0)) > 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,V->coinaddr,V->spendscript,&V->spendlen,&V->amount,&V->height,vin->prev_hash,vin->prev_vout,coin->bundlescount-1,0) == 0 )
{
V->unspentind = outpt.unspentind;
if ( V->coinaddr[0] != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,V->coinaddr)) != 0 )
{
memcpy(V->signers[0].pubkey,waddr->pubkey,bitcoin_pubkeylen(waddr->pubkey));
@ -236,7 +243,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
if ( hexstr != 0 )
{
n = (int32_t)strlen(hexstr) >> 1;
printf("add.(%s) offset.%d\n",hexstr,len);
//printf("add.(%s) offset.%d\n",hexstr,len);
vin->vinscript = &serialized[len];
decode_hex(&serialized[len],n,hexstr);
vin->scriptlen = n + need_op0;
@ -253,8 +260,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
i++;
}
if ( m != n )
printf("ERROR: ");
printf("len.%d n.%d i.%d\n",m,n,i);
printf("ERROR: len.%d n.%d i.%d\n",m,n,i);
}
len += n;
} //else printf("iguana_parsevinobj: hex script missing (%s)\n",jprint(vinobj,0));
@ -289,7 +295,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
if ( userdata != 0 )
{
n = iguana_parsehexstr(&vin->userdata,&vin->userdatalen,V!=0?V->userdata:0,V!=0?&V->userdatalen:0,&serialized[len],userdata);
printf("parsed userdata.%d\n",n);
//printf("parsed userdata.%d\n",n);
len += n;
}
//printf("len.%d: ",len);
@ -313,16 +319,36 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
len += n;
}
tmp = (len - starti);
for (i=0; i<len; i++)
printf("%02x",serialized[i]);
printf(" <- offset.%d tmp.%d starti.%d\n",len,tmp,starti);
serialized[starti-2] = (tmp & 0xff);
serialized[starti-1] = ((tmp >> 8) & 0xff);
if ( tmp < 76 )
{
serialized[starti-3] = tmp;
for (i=starti-2; i<starti-2+tmp; i++)
serialized[i] = serialized[i+2];
len -= 2;
}
else if ( tmp < 0x100 )
{
serialized[starti-3] = 0xfc;
serialized[starti-2] = tmp;
for (i=starti-1; i<starti-1+tmp; i++)
serialized[i] = serialized[i+1];
len--;
}
else
{
//for (i=0; i<len; i++)
// printf("%02x",serialized[i]);
//printf(" <- offset.%d tmp.%d starti.%d\n",len,tmp,starti);
serialized[starti-2] = (tmp & 0xff);
serialized[starti-1] = ((tmp >> 8) & 0xff);
}
//printf("output sequence.[%d] <- %x\n",len,vin->sequence);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(vin->sequence),&vin->sequence);
if ( spendstr != 0 )
{
n = iguana_parsehexstr(&vin->spendscript,&vin->spendlen,V!=0?V->spendscript:0,V!=0?&V->spendlen:0,0,spendstr);
//printf("serialized.%p len.%d\n",serialized,len);
n = iguana_parsehexstr(&vin->spendscript,&vin->spendlen,V!=0?V->spendscript:0,V!=0?&V->spendlen:0,&serialized[len],spendstr);
len += n;
}
return(len);
}
@ -345,8 +371,8 @@ int32_t iguana_parsevoutobj(struct iguana_info *coin,uint8_t *serialized,int32_t
decode_hex(&serialized[len],n,hexstr);
vout->pk_script = &serialized[len];
len += n;
}
}
} // else serialized[len++] = 0;
} //else serialized[len++] = 0;
return(len);
}
@ -425,7 +451,7 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,int32_t height,uint8_t *seriali
dest.vins[i].redeemscript = 0;
}
len = iguana_rwmsgtx(coin,height,1,0,serialized,maxlen,&dest,&txid,vpnstr,0,0,0,suppress_pubkeys);
if ( len > 0 )
if ( len > 0 ) // (dest.tx_in != 1 || bits256_nonz(dest.vins[0].prev_hash) != 0) && dest.vins[0].scriptlen > 0 &&
{
#ifdef BTC2_VERSION
if ( height >= BTC2_HARDFORK_HEIGHT )
@ -525,7 +551,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
}
for (i=0; i<msg->tx_out; i++)
{
//printf("vout.%d starts %d\n",i,len);
//printf("rwflag.%d vout.%d starts %d\n",rwflag,i,len);
if ( (n= iguana_voutparse(rwflag,&serialized[len],&msg->vouts[i])) < 0 )
return(-1);
len += n;
@ -543,7 +569,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
jaddnum(json,"numvouts",msg->tx_out);
}
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time);
//printf("lock_time.%08x\n",msg->lock_time);
//printf("lock_time.%08x len.%d\n",msg->lock_time,len);
if ( strcmp(coin->symbol,"VPN") == 0 )
{
uint16_t ddosflag = 0;
@ -602,11 +628,12 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,
return(txid);
maxsize -= (sizeof(struct iguana_msgvin) * msg->tx_in);
msg->vins = (struct iguana_msgvin *)&serialized[maxsize];
memset(msg->vins,0,sizeof(struct iguana_msgvin) * msg->tx_in);
if ( msg->tx_in > 0 && msg->tx_in*sizeof(struct iguana_msgvin) < maxsize )
{
for (i=0; i<msg->tx_in; i++)
{
//printf("vinobj.%d starts offset.%d\n",i,len);
//printf("parsetxobj vinobj.%d starts offset.%d\n",i,len);
len += iguana_parsevinobj(myinfo,coin,&serialized[len],maxsize,&msg->vins[i],jitem(array,i),V!=0?&V[i]:0);
}
}
@ -619,11 +646,12 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,
return(txid);
maxsize -= (sizeof(struct iguana_msgvout) * msg->tx_out);
msg->vouts = (struct iguana_msgvout *)&serialized[maxsize];
memset(msg->vouts,0,sizeof(struct iguana_msgvout) * msg->tx_out);
if ( msg->tx_out > 0 && msg->tx_out*sizeof(struct iguana_msgvout) < maxsize )
{
for (i=0; i<msg->tx_out; i++)
{
//printf("parsevout.%d starts %d\n",i,len);
//printf("parsetxobj parsevout.%d starts %d\n",i,len);
len += iguana_parsevoutobj(coin,&serialized[len],maxsize,&msg->vouts[i],jitem(array,i));
}
}
@ -634,17 +662,6 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,
*txstartp = 0;
msg->allocsize = len;
msg->txid = txid = bits256_doublesha256(0,serialized,len);
//for (i=0; i<len; i++)
// printf("%02x",serialized[i]);
//printf(" parsetxobj len.%d\n",len);
/*if ( (len= iguana_rwmsgtx(coin,1,0,&serialized[len],maxsize-len,msg,&txid,vpnstr,0,0,0,V!=0?V->suppress_pubkeys:0)) != msg->allocsize )
{
//memset(txid.bytes,0,sizeof(txid));
printf("error parsing txobj: expected %d got %d\n",msg->allocsize,len);
//msg->allocsize = 0;
}
msg->txid = txid;*/
//char str[65]; printf("json -> %s\n",bits256_str(str,txid));
return(txid);
}
@ -701,6 +718,8 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,int32_t height,bits256 *txidp,
jaddstr(txobj,"error","couldnt decode transaction");
jaddstr(txobj,"coin",coin->symbol);
}
if ( n != len )
printf("data2json n.%d vs len.%d\n",n,len);
return(txobj);
}
@ -711,7 +730,7 @@ cJSON *bitcoin_hex2json(struct iguana_info *coin,int32_t height,bits256 *txidp,s
return(0);
len = (int32_t)strlen(txbytes) >> 1;
if ( (serialized= origserialized) == 0 )
serialized = calloc(1,len);
serialized = calloc(1,len+4096);
decode_hex(serialized,len,txbytes);
txobj = bitcoin_data2json(coin,height,txidp,msgtx,extraspace,extralen,serialized,len,vins,suppress_pubkeys);
if ( serialized != origserialized )
@ -783,7 +802,7 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m
msgtx->vins[vini].userdatalen = userdatalen;
scriptlen += userdatalen;
}
printf("USERDATALEN.%d scriptlen.%d redeemlen.%d\n",userdatalen,scriptlen,p2shlen);
//printf("USERDATALEN.%d scriptlen.%d redeemlen.%d\n",userdatalen,scriptlen,p2shlen);
if ( p2shlen != 0 )
{
if ( p2shlen < 76 )
@ -814,7 +833,7 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m
return(len);
}
int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,int32_t sighash,int32_t signtx,int32_t suppress_pubkeys)
int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,uint32_t sighash,int32_t signtx,int32_t suppress_pubkeys)
{
bits256 sigtxid; uint8_t *sig; struct vin_info *vp; char vpnstr[64]; int32_t complete=0,plen,j,vini=0,flag=0,siglen,numvouts,numsigs;
numvouts = msgtx->tx_out;
@ -855,7 +874,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign
if ( bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,vp->signers[j].pubkey,bitcoin_pubkeylen(vp->signers[j].pubkey)) < 0 )
{
printf("SIG.%d.%d ERROR\n",vini,j);
//printf("SIG.%d.%d ERROR siglen.%d\n",vini,j,siglen);
}
else
{
@ -866,8 +885,8 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign
printf("%02x",sig[z]);
printf(" <- sig[%d]n\n",j);
for (z=0; z<33; z++)
printf("%02x",vp->signers[j].pubkey[z]);
printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);*/
printf("%02x",vp->signers[j].pubkey[z]);*/
//printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);
}
}
if ( numsigs >= vp->M )
@ -877,14 +896,14 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign
iguana_msgtx_Vset(coin,serialized,maxlen,msgtx,V);
cJSON *txobj = cJSON_CreateObject();
*signedtx = iguana_rawtxbytes(coin,height,txobj,msgtx,suppress_pubkeys);
printf("SIGNEDTX.(%s)\n",jprint(txobj,1));
//printf("SIGNEDTX.(%s)\n",jprint(txobj,1));
*signedtxidp = msgtx->txid;
return(complete);
}
int32_t iguana_vininfo_create(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msgtx,cJSON *vins,int32_t numinputs,struct vin_info *V)
{
int32_t i,plen,finalized = 1,len = 0; struct vin_info *vp; struct iguana_waccount *wacct; struct iguana_waddress *waddr; uint32_t sigsize,pubkeysize,p2shsize,userdatalen;
struct iguana_outpoint outpt; int32_t i,plen,finalized = 1,len = 0; struct vin_info *vp; struct iguana_waccount *wacct; struct iguana_waddress *waddr; uint32_t sigsize,pubkeysize,p2shsize,userdatalen;
msgtx->tx_in = numinputs;
maxsize -= (sizeof(struct iguana_msgvin) * msgtx->tx_in);
msgtx->vins = (struct iguana_msgvin *)&serialized[maxsize];
@ -899,8 +918,9 @@ int32_t iguana_vininfo_create(struct supernet_info *myinfo,struct iguana_info *c
finalized = 0;
if ( msgtx->vins[i].spendscript == 0 )
{
if ( (vp->unspentind= iguana_RTunspentindfind(myinfo,coin,vp->coinaddr,vp->spendscript,&vp->spendlen,&vp->amount,&vp->height,msgtx->vins[i].prev_hash,msgtx->vins[i].prev_vout,coin->bundlescount-1,0)) > 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,vp->coinaddr,vp->spendscript,&vp->spendlen,&vp->amount,&vp->height,msgtx->vins[i].prev_hash,msgtx->vins[i].prev_vout,coin->bundlescount-1,0) == 0 )
{
vp->unspentind = outpt.unspentind;
msgtx->vins[i].spendscript = vp->spendscript;
msgtx->vins[i].spendlen = vp->spendlen;
vp->hashtype = iguana_vinscriptparse(coin,vp,&sigsize,&pubkeysize,&p2shsize,&userdatalen,vp->spendscript,vp->spendlen);
@ -1140,6 +1160,8 @@ int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLoc
activescriptlen = V[vini].spendlen;
}
spendscript = iguana_spendasm(coin,activescript,activescriptlen);
if ( activescriptlen < 16 )
continue;
//printf("interpreter.(%s)\n",jprint(spendscript,0));
if ( (scriptlen= bitcoin_assembler(coin,logarray,script,spendscript,1,nLockTime,&V[vini])) < 0 )
{
@ -1254,7 +1276,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
{
printf("txobj.(%s)\n",jprint(txobj,0));
}
if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 )
if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 ) // no guarantee of identical regen
{
if ( strcmp(rawtx,checkstr) != 0 )
{

123
iguana/iguana_spendvectors.c

@ -97,7 +97,7 @@ int32_t iguana_spendvectorsave(struct iguana_info *coin,struct iguana_bundle *bp
return(retval);
}
struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spent_hdrsi,struct iguana_spend *s,int32_t prefetchflag)
struct iguana_bundle *iguana_externalspent(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spent_hdrsi,struct iguana_spend *s,int32_t prefetchflag)
{
int32_t prev_vout,height,hdrsi; uint32_t sequenceid,unspentind; char str[65]; struct iguana_bundle *spentbp=0; struct iguana_txid *T,TX,*tp; bits256 *X; bits256 prev_hash; struct iguana_ramchaindata *rdata;
if ( (rdata= ramchain->H.data) != 0 )
@ -155,7 +155,8 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre
else
{
printf("illegal hdrsi.%d prev_hash.(%s) for bp.[%d]\n",hdrsi,bits256_str(str,prev_hash),spent_hdrsi);
exit(-1);
iguana_exit(myinfo,0);
return(0);
}
}
else
@ -163,8 +164,8 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre
printf("cant find prev_hash.(%s) for bp.[%d]\n",bits256_str(str,prev_hash),spent_hdrsi);
if ( spent_hdrsi < coin->current->hdrsi )
{
iguana_bundleremove(coin,spent_hdrsi,1);
exit(-1);
//iguana_bundleremove(coin,spent_hdrsi,1);
iguana_exit(myinfo,coin->bundles[spent_hdrsi]);
}
coin->RTdatabad = 1;
return(0);
@ -176,7 +177,8 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre
else if ( unspentind == 0 || unspentind >= spentbp->ramchain.H.data->numunspents )
printf("%s illegal unspentind.%d vs max.%d spentbp.%p[%d]\n",coin->symbol,unspentind,spentbp->ramchain.H.data->numunspents,spentbp,hdrsi);
else return(spentbp);
iguana_bundleremove(coin,spent_hdrsi,1);
//iguana_bundleremove(coin,spent_hdrsi,1);
iguana_exit(myinfo,coin->bundles[spent_hdrsi]);
}
//exit(-1);
return(0);
@ -184,7 +186,7 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre
struct iguana_bundle *iguana_fastexternalspent(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spent_hdrsi,struct iguana_spend *s)
{
int32_t prev_vout,height,hdrsi,unspentind; uint32_t ind;
int32_t prev_vout,height,hdrsi,unspentind; uint32_t ind; uint64_t RTspent;
struct iguana_txid *T; bits256 *X; bits256 prev_hash; struct iguana_ramchaindata *rdata;
if ( (rdata= ramchain->H.data) == 0 )
return(0);
@ -202,7 +204,7 @@ struct iguana_bundle *iguana_fastexternalspent(struct supernet_info *myinfo,stru
X = RAMCHAIN_PTR(rdata,Xoffset);
//X = (void *)(long)((long)rdata + rdata->Xoffset);
*prevhashp = prev_hash = X[ind];
if ( (unspentind= iguana_unspentindfind(myinfo,coin,0,0,0,0,&height,prev_hash,prev_vout,spent_hdrsi-1,0)) != 0 )
if ( (unspentind= iguana_unspentindfind(myinfo,coin,&RTspent,0,0,0,0,&height,prev_hash,prev_vout,spent_hdrsi-1,0)) != 0 )
//if ( (firstvout= iguana_txidfastfind(coin,&height,prev_hash,spent_hdrsi-1)) >= 0 )
{
/*duration = (OS_milliseconds() - startmillis);
@ -279,6 +281,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
//coin->fast[iter] = calloc(1,coin->fastsizes[iter]);
//memcpy(coin->fast[iter],fastfind,coin->fastsizes[iter]);
}
//need zB[]?
txidind = B[starti].firsttxidind;
spendind = B[starti].firstvin;
for (i=starti; i<numblocks; i++)
@ -294,7 +297,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
now = (uint32_t)time(NULL);
if ( txidind != T[txidind].txidind || spendind != T[txidind].firstvin )
{
printf("spendvectors: txidind %u != %u nextT[txidind].firsttxidind || spendind %u != %u nextT[txidind].firstvin\n",txidind,T[txidind].txidind,spendind,T[txidind].firstvin);
printf("spendvectors: txidind %u != %u nextT[txidind].firsttxidind || spendind %u != %u nextT[txidind].firstvin\n",txidind,(uint32_t)T[txidind].txidind,spendind,(uint32_t)T[txidind].firstvin);
myfree(ptr,sizeof(*ptr) * n);
return(-1);
}
@ -315,7 +318,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
}
else if ( spentbp == 0 )
{
if ( (spentbp= iguana_externalspent(coin,&prevhash,&spent_unspentind,ramchain,bp->hdrsi,s,2)) != 0 )
if ( (spentbp= iguana_externalspent(myinfo,coin,&prevhash,&spent_unspentind,ramchain,bp->hdrsi,s,2)) != 0 )
{
if ( coin->fastfind != 0 )
printf("found prevhash using slow, not fast\n");
@ -439,7 +442,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
if ( ptr != 0 )
myfree(ptr,sizeof(*ptr) * n);
//if ( bp != coin->current )
printf("UTXO [%4d].%-6d dur.%-2d [milli %8.3f] vectors %-6d err.%d [%5.2f%%] %7d %9s of %d\n",bp->hdrsi,bp->numtmpspends,(uint32_t)time(NULL)-starttime,OS_milliseconds()-startmillis,spendind,errs,100.*(double)emitted/(total+1),emit,mbstr(str,sizeof(*ptr) * emit),n);
printf("%s UTXO [%4d].%-6d dur.%-2d [%8.3f] vec %-6d err.%d [%5.2f%%] %7d %9s of %d\n",coin->symbol,bp->hdrsi,bp->numtmpspends,(uint32_t)time(NULL)-starttime,OS_milliseconds()-startmillis,spendind,errs,100.*(double)emitted/(total+1),emit,mbstr(str,sizeof(*ptr) * emit),n);
return(-errs);
}
@ -496,7 +499,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
now = (uint32_t)time(NULL);
if ( txidind != T[txidind].txidind || spendind != T[txidind].firstvin || unspentind != T[txidind].firstvout )
{
printf("balancegen: txidind %u != %u T[txidind].firsttxidind || spendind %u != %u T[txidind].firstvin errs.%d (%d %d)\n",txidind,T[txidind].txidind,spendind,T[txidind].firstvin,errs,unspentind,B[i].firstvout);
printf("balancegen: txidind %u != %u T[txidind].firsttxidind || spendind %u != %u T[txidind].firstvin errs.%d (%d %d)\n",txidind,(uint32_t)T[txidind].txidind,spendind,(uint32_t)T[txidind].firstvin,errs,unspentind,B[i].firstvout);
return(-1);
}
if ( 0 && bp == coin->current )
@ -659,7 +662,7 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co
fclose(fp);
}
if ( filecrc != 0 )
printf("have filecrc.%08x for %s milli.%.0f from_ro.%d\n",filecrc,bits256_str(str,balancehash),OS_milliseconds(),from_ro);
printf("%s have filecrc.%08x for %s milli.%.0f from_ro.%d\n",coin->symbol,filecrc,bits256_str(str,balancehash),OS_milliseconds(),from_ro);
if ( from_ro == 0 || filecrc == 0 )
{
if ( filecrc == 0 )
@ -677,6 +680,7 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co
fprintf(stderr,".");
if ( filecrc == 0 )
{
//fprintf(stderr,"balancehash add [%d]\n",bp->hdrsi);
vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr) * numpkinds);
vupdate_sha256(balancehash.bytes,&vstate,(void *)Uptr,sizeof(*Uptr) * numunspents);
vupdate_sha256(allbundles.bytes,&bstate,(void *)bp->hashes,sizeof(bp->hashes[0]) * bp->n);
@ -687,16 +691,16 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co
} //else printf("missing hdrs.[%d] data.%p num.(%u %d) %p %p\n",i,bp->ramchain.H.data,numpkinds,numunspents,Aptr,Uptr);
}
} else crc = filecrc;
printf("millis %.0f from_ro.%d written.%d crc.%08x/%08x balancehash.(%s) vs (%s)\n",OS_milliseconds(),from_ro,coin->balanceswritten,crc,filecrc,bits256_str(str,balancehash),bits256_str(str2,coin->balancehash));
printf("%s millis %.0f from_ro.%d written.%d crc.%08x/%08x balancehash.(%s) vs (%s)\n",coin->symbol,OS_milliseconds(),from_ro,coin->balanceswritten,crc,filecrc,bits256_str(str,balancehash),bits256_str(str2,coin->balancehash));
if ( (filecrc != 0 && filecrc != crc) || memcmp(balancehash.bytes,coin->balancehash.bytes,sizeof(balancehash)) != 0 || memcmp(allbundles.bytes,coin->allbundles.bytes,sizeof(allbundles)) != 0 )
{
printf("balancehash or crc.(%x %x) mismatch or allbundles.(%llx %llx) mismatch\n",crc,filecrc,(long long)allbundles.txid,(long long)coin->allbundles.txid);
printf("%s balancehash or crc.(%x %x) mismatch or allbundles.(%llx %llx) mismatch\n",coin->symbol,crc,filecrc,(long long)allbundles.txid,(long long)coin->allbundles.txid);
iguana_truncatebalances(coin);
OS_removefile(crcfname,0);
}
else
{
printf("MATCHED balancehash numhdrsi.%d crc.%08x\n",coin->balanceswritten,crc);
printf("%s MATCHED balancehash numhdrsi.%d crc.%08x\n",coin->symbol,coin->balanceswritten,crc);
if ( (fp= fopen(crcfname,"wb")) != 0 )
{
if ( fwrite(&crc,1,sizeof(crc),fp) != sizeof(crc) || fwrite(&balancehash,1,sizeof(balancehash),fp) != sizeof(balancehash) || fwrite(&allbundles,1,sizeof(allbundles),fp) != sizeof(allbundles) )
@ -722,7 +726,6 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co
iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block);
}
}
//printf("end volatilesinit\n");
if ( iguana_fastfindinit(coin) == 0 )//&& coin->PREFETCHLAG >= 0 )
iguana_fastfindcreate(coin);
/*for (j=0; j<coin->bundlescount; j++)
@ -734,6 +737,7 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co
iguana_update_balances(coin);*/
iguana_datachain_scan(myinfo,coin,CRYPTO777_RMD160);
//iguana_utxoaddr_gen(myinfo,coin,(coin->bundlescount - 1) * coin->chain->bundlesize);*/
printf("end %s volatilesinit\n",coin->symbol);
return(coin->bundlescount);
}
@ -743,14 +747,13 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits
if ( bits256_nonz(lastbundle) > 0 )
{
init_hexbytes_noT(hashstr,lastbundle.bytes,sizeof(bits256));
printf("req lastbundle.(%s)\n",hashstr);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
}
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish <= 1 )
{
printf("initfinal break.[%d]: bp.%p or emit.%u utxofinish.%u\n",i,bp,bp!=0?bp->emitfinish:-1,bp!=0?bp->utxofinish:-1);
printf("%s initfinal break.[%d]: bp.%p or emit.%u utxofinish.%u\n",coin->symbol,i,bp,bp!=0?bp->emitfinish:-1,bp!=0?bp->utxofinish:-1);
break;
}
if ( i == 0 )
@ -758,11 +761,11 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits
}
if ( i < coin->bundlescount-1 )
{
printf("spendvectors.[%d] max.%d missing, will regen all of them\n",i,coin->bundlescount-1);
printf("%s spendvectors.[%d] max.%d missing, will regen all of them\n",coin->symbol,i,coin->bundlescount-1);
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
bp->startutxo = bp->utxofinish = 0;
bp->startutxo = bp->utxofinish = bp->converted = bp->balancefinish = bp->validated = 0;
}
}
else
@ -773,19 +776,21 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits
bp->converted = (uint32_t)time(NULL);
}
}
printf("i.%d bundlescount.%d\n",i,coin->bundlescount);
printf("%s i.%d bundlescount.%d\n",coin->symbol,i,coin->bundlescount);
if ( coin->balanceswritten > 1 )
coin->balanceswritten = iguana_volatilesinit(myinfo,coin);
if ( coin->balanceswritten > 1 )
/*if ( coin->balanceswritten > 1 )
{
//for (i=0; i<coin->balanceswritten; i++)
for (i=0; i<coin->bundlescount; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
iguana_bundlevalidate(myinfo,coin,bp,0);
//printf("%d ",i);
iguana_validateQ(coin,coin->bundles[i]);
//iguana_validateQ(coin,coin->bundles[i]);
}
}
printf("i.%d balanceswritten.%d\n",i,coin->balanceswritten);
}*/
printf("%s i.%d balanceswritten.%d\n",coin->symbol,i,coin->balanceswritten);
if ( coin->balanceswritten < coin->bundlescount )
{
for (i=0*coin->balanceswritten; i<coin->bundlescount; i++)
@ -793,7 +798,7 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits
if ( (bp= coin->bundles[i]) != 0 && bp->queued == 0 )
{
//printf("%d ",i);
iguana_bundleQ(coin,bp,1000);
iguana_bundleQ(myinfo,coin,bp,1000);
}
}
printf("iguana_bundlesQ %d to %d\n",coin->balanceswritten,coin->bundlescount);
@ -802,7 +807,6 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits
iguana_volatilesinit(myinfo,coin);
iguana_savehdrs(coin);
iguana_fastlink(coin,coin->balanceswritten * coin->chain->bundlesize - 1);
printf("walkchain\n");
iguana_walkchain(coin,0);
hash2 = iguana_blockhash(coin,coin->balanceswritten * coin->chain->bundlesize);
if ( bits256_nonz(hash2) != 0 && (block= iguana_blockfind("initfinal",coin,hash2)) != 0 )
@ -838,7 +842,9 @@ int32_t iguana_balanceflush(struct supernet_info *myinfo,struct iguana_info *coi
Aptr = 0;
Uptr = 0;
numunspents = numpkinds = 0;
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->ramchain.H.data != 0 && (numpkinds= bp->ramchain.H.data->numpkinds) > 0 && (numunspents= bp->ramchain.H.data->numunspents) > 0 && (Aptr= bp->ramchain.A2) != 0 && (Uptr= bp->ramchain.Uextras) != 0 )
if ( (bp= coin->bundles[hdrsi]) == 0 )
continue;
if ( bp != 0 && bp->ramchain.H.data != 0 && (numpkinds= bp->ramchain.H.data->numpkinds) > 0 && (numunspents= bp->ramchain.H.data->numunspents) > 0 && (Aptr= bp->ramchain.A2) != 0 && (Uptr= bp->ramchain.Uextras) != 0 )
{
sprintf(fname,"%s/%s/debits.%d_N%d",GLOBAL_TMPDIR,coin->symbol,bp->hdrsi,numhdrsi);
sprintf(fname2,"%s/%s/lastspends.%d_N%d",GLOBAL_TMPDIR,coin->symbol,bp->hdrsi,numhdrsi);
@ -855,9 +861,9 @@ int32_t iguana_balanceflush(struct supernet_info *myinfo,struct iguana_info *coi
err = -1;
if ( fwrite(&numhdrsi,1,sizeof(numhdrsi),fp) == sizeof(numhdrsi) && fwrite(&numhdrsi,1,sizeof(numhdrsi),fp2) == sizeof(numhdrsi) && fwrite(balancehash.bytes,1,sizeof(balancehash),fp) == sizeof(balancehash) && fwrite(balancehash.bytes,1,sizeof(balancehash),fp2) == sizeof(balancehash) && fwrite(allbundles.bytes,1,sizeof(allbundles),fp) == sizeof(allbundles) && fwrite(allbundles.bytes,1,sizeof(allbundles),fp2) == sizeof(allbundles) )
{
if ( fwrite(Aptr,sizeof(*Aptr),numpkinds,fp) == numpkinds )
if ( numpkinds == 0 || fwrite(Aptr,sizeof(*Aptr),numpkinds,fp) == numpkinds )
{
if ( fwrite(Uptr,sizeof(*Uptr),numunspents,fp2) == numunspents )
if ( numunspents == 0 || fwrite(Uptr,sizeof(*Uptr),numunspents,fp2) == numunspents )
{
err = 0;
if ( (hdrsi % 100) == 0 )
@ -884,26 +890,30 @@ int32_t iguana_balanceflush(struct supernet_info *myinfo,struct iguana_info *coi
else if ( iter == 2 )
{
sprintf(destfname,"%s/%s/accounts/debits.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
if ( OS_copyfile(fname,destfname,1) < 0 )
OS_removefile(destfname,0);
OS_renamefile(fname,destfname);
/*if ( OS_copyfile(fname,destfname,1) < 0 )
{
printf("balances error copying (%s) -> (%s)\n",fname,destfname);
return(-1);
}
}*/
sprintf(destfname,"%s/%s/accounts/lastspends.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
if ( OS_copyfile(fname2,destfname,1) < 0 )
OS_removefile(destfname,0);
OS_renamefile(fname2,destfname);
/*if ( OS_copyfile(fname2,destfname,1) < 0 )
{
printf("balances error copying (%s) -> (%s)\n",fname2,destfname);
return(-1);
}
}*/
if ( (hdrsi % 100) == 0 )
printf("%s -> %s\n",fname,destfname);
OS_removefile(fname,0);
OS_removefile(fname2,0);
//OS_removefile(fname,0);
//OS_removefile(fname2,0);
}
if ( bp->ramchain.allocatedA2 == 0 || bp->ramchain.allocatedU2 == 0 )
{
printf("skip saving.[%d] files as not allocated\n",bp->hdrsi);
break;
printf("account.[%d] files not allocated %u %u\n",bp->hdrsi,(uint32_t)bp->ramchain.allocatedA2,(uint32_t)bp->ramchain.allocatedU2);
//break;
}
}
else if ( hdrsi > 0 && hdrsi != coin->bundlescount && (coin->current == 0 || hdrsi != coin->current->hdrsi ) )
@ -953,12 +963,7 @@ int32_t iguana_balanceflush(struct supernet_info *myinfo,struct iguana_info *coi
}
}
#endif
for (i=0; i<30; i++)
{
printf("need to exit, please restart after shutdown in %d seconds, or just ctrl-C\n",30-i);
sleep(1);
}
exit(-1);
iguana_exit(myinfo,0);
}
coin->balanceswritten = iguana_volatilesinit(myinfo,coin);
//printf("flush free\n");
@ -988,7 +993,7 @@ int32_t iguana_spendvectorsaves(struct iguana_info *coin)
for (j=0; j<bp->numtmpspends; j++)
if ( bp->tmpspends[j].tmpflag != 0 )
{
printf("vectorsave.[%d] vec.%d still has tmpflag\n",i,j);
printf("%s vectorsave.[%d] vec.%d still has tmpflag\n",coin->symbol,i,j);
return(-1);
}
}
@ -1092,11 +1097,16 @@ int32_t iguana_convert(struct iguana_info *coin,int32_t helperid,struct iguana_b
return(converted);
}
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag)
int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag)
{
static int32_t totalerrs,totalvalidated;
FILE *fp; char fname[1024]; uint8_t *blockspace; //uint32_t now = (uint32_t)time(NULL);
FILE *fp; char fname[1024]; uint8_t *blockspace; uint32_t now = (uint32_t)time(NULL);
int32_t i,max,len,errs = 0; struct sha256_vstate vstate; bits256 validatehash; int64_t total = 0;
if ( coin->chain->zcash != 0 )
{
printf("need to process joinsplits before can validate.%s\n",coin->symbol);
return(bp->n);
}
if ( (coin->MAXPEERS > 1 && coin->VALIDATENODE == 0 && coin->FULLNODE == 0) || bp->ramchain.from_ro != 0 || bp == coin->current )
{
bp->validated = (uint32_t)time(NULL);
@ -1124,12 +1134,18 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,
{
max = coin->blockspacesize;
blockspace = calloc(1,max);
iguana_volatilespurge(coin,&bp->ramchain);
iguana_volatilesmap(coin,&bp->ramchain);
for (i=0; i<bp->n; i++)
{
if ( (len= iguana_peerblockrequest(coin,blockspace,max,0,bp->hashes[i],1)) < 0 )
char str[65];
if ( coin->chain->fixit != 0 )
printf("validate %s.[%d:%d] %s\n",coin->symbol,bp->hdrsi,i,bits256_str(str,bp->hashes[i]));
if ( (len= iguana_peerblockrequest(myinfo,coin,blockspace,max,0,bp->hashes[i],1)) < 0 )
{
errs++;
//fprintf(stderr,"-%s.[%d:%d] ",coin->symbol,bp->hdrsi,i);
//printf("bundlevalidate: %s delete [%d:%d]\n",coin->symbol,bp->hdrsi,i);
iguana_blockunmark(coin,bp->blocks[i],bp,i,1);
totalerrs++;
}
@ -1140,8 +1156,10 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,
}
}
free(blockspace);
bp->validated = (uint32_t)time(NULL);
// printf("VALIDATED.[%d] ht.%d duration.%d errs.%d total.%lld %u | total errs.%d validated.%d %llx\n",bp->hdrsi,bp->bundleheight,bp->validated - now,errs,(long long)total,bp->validated,totalerrs,totalvalidated,(long long)validatehash.txid);
printf("%s %s VALIDATED.[%d] ht.%d duration.%d errs.%d total.%lld %u | total errs.%d validated.%d %llx\n",coin->symbol,errs!=0?"NOT":"",bp->hdrsi,bp->bundleheight,(uint32_t)time(NULL) - now,errs,(long long)total,bp->validated,totalerrs,totalvalidated,(long long)validatehash.txid);
if ( errs == 0 )
bp->validated = (uint32_t)time(NULL);
else bp->startutxo = bp->utxofinish = 0;
//iguana_volatilesmap(coin,&bp->ramchain);
//if ( bp == coin->current )
// coin->RTdatabad = -1;
@ -1159,8 +1177,9 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,
} // else printf("skip validate.[%d] validated.%u force.%d\n",bp->hdrsi,bp->validated,forceflag);
if ( errs != 0 )
{
printf("remove.[%d]\n",bp->hdrsi);
iguana_bundleremove(coin,bp->hdrsi,0);
printf("%s remove.[%d]\n",coin->symbol,bp->hdrsi);
//iguana_bundleremove(coin,bp->hdrsi,0);
return(-errs);
}
return(bp->n - errs);
}

2
iguana/iguana_tradebots.c

@ -38,7 +38,7 @@ struct tradebot_info
cJSON *tradebot_json(struct supernet_info *myinfo,struct exchange_info *exchange,struct tradebot_info *bot)
{
char str[64]; int32_t i,numpending; double pendsum,pendvolume,vol; cJSON *json,*array,*item;
char str[65]; int32_t i,numpending; double pendsum,pendvolume,vol; cJSON *json,*array,*item;
json = cJSON_CreateObject();
jaddstr(json,"exchange",exchange->name);
jaddstr(json,"started",utc_str(str,bot->started));

133
iguana/iguana_tx.c

@ -14,13 +14,6 @@
******************************************************************************/
#include "iguana777.h"
//#include "SuperNET.h"
//struct iguana_txid { bits256 txid; uint32_t txidind,firstvout,firstvin,locktime,version,timestamp; uint16_t numvouts,numvins; } __attribute__((packed));
//struct iguana_msgvin { bits256 prev_hash; uint8_t *script; uint32_t prev_vout,scriptlen,sequence; } __attribute__((packed));
//struct iguana_spend { uint32_t spendtxidind; int16_t prevout; uint16_t tbd:14,external:1,diffsequence:1; } __attribute__((packed));
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen)
{
@ -89,7 +82,7 @@ int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t heig
{
iguana_vinsfname(coin,bp->ramchain.from_ro,fname,s->fileid);
if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->vinptrs[s->fileid],fname,s->scriptpos,s->scriptlen)) != s->scriptlen )
printf("err.%d getting %d bytes from fileid.%llu[%d] %s for s%d\n",err,s->scriptlen,(long long)s->scriptpos,s->fileid,fname,spendind);
printf("err.%d getting %d bytes from fileid.%u[%u] %s for s%d\n",err,(int32_t)s->scriptlen,(uint32_t)s->scriptpos,(uint32_t)s->fileid,fname,spendind);
}
vin->scriptlen = s->scriptlen;
vin->vinscript = scriptspace;
@ -107,8 +100,10 @@ int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint
if ( u->scriptpos > 0 && u->scriptlen > 0 )
{
iguana_voutsfname(coin,bp->ramchain.from_ro,fname,u->fileid);
if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->voutptrs[u->fileid],fname,u->scriptpos,u->scriptlen)) != u->scriptlen )
printf("%d bytes from fileid.%d[%d] %s for type.%d\n",u->scriptlen,u->fileid,u->scriptpos,fname,u->type);
if ( (int32_t)(scriptlen= iguana_scriptdata(coin,scriptspace,coin->voutptrs[u->fileid],fname,u->scriptpos,u->scriptlen)) != (int32_t)u->scriptlen )
printf("scriptlen.%d != %d bytes from fileid.%d[%d] %s for type.%d\n",scriptlen,u->scriptlen,u->fileid,u->scriptpos,fname,u->type);
if ( scriptlen < 0 )
scriptlen = 0;
}
else
{
@ -134,8 +129,13 @@ int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmst
//P = (void *)(long)((long)rdata + rdata->Poffset);
unspentind = (tx->firstvout + i);
u = &U[unspentind];
if ( u->txidind != tx->txidind || u->vout != i || u->hdrsi != height / coin->chain->bundlesize )
printf("iguana_voutset: txidind mismatch %d vs %d || %d vs %d || (%d vs %d)\n",u->txidind,u->txidind,u->vout,i,u->hdrsi,height / coin->chain->bundlesize);
if ( u->vout != i || u->hdrsi != height / coin->chain->bundlesize ) //u->txidind != tx->txidind ||
{
static uint32_t counter;
if ( counter++ < 3 )
printf("%s.[%d].%d iguana_voutset: vout mismatch t%d u%u || %d vs %d, type.%d scriptpos.%d scriptlen.%d\n",coin->symbol,height/coin->chain->bundlesize,u->hdrsi,u->txidind,unspentind,u->vout,i,u->type,u->scriptpos,u->scriptlen);
return(-1);
}
vout->value = u->value;
vout->pk_script = scriptspace;
scriptlen = iguana_voutscript(coin,bp,scriptspace,asmstr,u,&P[u->pkind],i);
@ -164,7 +164,7 @@ struct iguana_txid *iguana_blocktx(struct iguana_info *coin,struct iguana_txid *
return(0);
} else printf("iguana_blocktx null txidind [%d:%d] i.%d\n",block->hdrsi,block->bundlei,i);
} else printf("iguana_blocktx no bp.[%d]\n",block->hdrsi);
} else printf("blocktx illegal height.%d\n",block->height);
} else printf("%s blocktx illegal height.%d\n",coin->symbol,block->height);
} else printf("i.%d vs txn_count.%d\n",i,block->RO.txn_count);
return(0);
}
@ -193,14 +193,16 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
for (i=0; i<numvins; i++)
{
if ( vins == 0 )
iguana_vinset(coin,space,height,&vin,tx,i);
else vin = vins[i];
if ( validatesigs != 0 && iguana_validatesigs(coin,&vin) < 0 )
{
printf("error validating vin.%d ht.%d\n",i,height);
return(0);
}
len += iguana_rwvin(rwflag,0,&serialized[len],&vin);
if ( iguana_vinset(coin,space,height,&vin,tx,i) < 0 )
{
printf("iguana_ramtxbytes vinset error %d of %d\n",i,numvins);
return(0);
}
} else vin = vins[i];
len += iguana_rwvin(rwflag,coin,0,&serialized[len],&vin,i);
if ( len > maxlen )
break;
}
if ( len > maxlen )
{
@ -211,9 +213,18 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
for (i=0; i<numvouts; i++)
{
if ( vouts == 0 )
iguana_voutset(coin,space,asmstr,height,&vout,tx,i);
else vout = vouts[i];
{
if ( iguana_voutset(coin,space,asmstr,height,&vout,tx,i) < 0 )
{
static uint32_t counter;
if ( counter++ < 10 )
printf("iguana_ramtxbytes voutset error %d of %d\n",i,numvouts);
return(0);
}
} else vout = vouts[i];
len += iguana_rwvout(rwflag,0,&serialized[len],&vout);
if ( len > maxlen )
break;
}
if ( len > maxlen )
{
@ -226,17 +237,17 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
*txidp = bits256_doublesha256(txidstr,serialized,len);
if ( memcmp(txidp,tx->txid.bytes,sizeof(*txidp)) != 0 )
{
for (i=0; i<len; i++)
printf("%02x",serialized[i]);
//for (i=0; i<len; i++)
// printf("%02x",serialized[i]);
char str[65],str2[65]; printf("\nrw.%d numvins.%d numvouts.%d error generating txbytes txid %s vs %s\n",rwflag,numvins,numvouts,bits256_str(str,*txidp),bits256_str(str2,tx->txid));
return(-1);
}
return(len);
}
int32_t iguana_peerblockrequest(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)
{
struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgblock msgB; 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;
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n )
{
if ( (rdata= bp->ramchain.H.data) == 0 )//&& bp == coin->current )
@ -247,9 +258,9 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
}
if ( (block= bp->blocks[bundlei]) != 0 && rdata != 0 )
{
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&msgB,block,0);
msgB.txn_count = block->RO.txn_count;
total = iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB,max);
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&zmsgB,(void *)block,0);
zmsgB.txn_count = block->RO.txn_count;
total = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&zmsgB,max);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{
//static int counter;
@ -261,24 +272,24 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
{
if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
{
if ( (len= iguana_ramtxbytes(coin,&blockspace[sizeof(struct iguana_msghdr) + total],max - total,&checktxid,tx,block->height,0,0,validatesigs)) > 0 && bits256_cmp(checktxid,T.txid) == 0 )
if ( (len= iguana_ramtxbytes(coin,&blockspace[sizeof(struct iguana_msghdr) + total],max - total,&checktxid,tx,block->height,0,0,validatesigs)) > 0 )//&& bits256_cmp(checktxid,T.txid) == 0 )
total += len;
else
{
//static int counter;
static uint32_t counter;
char str[65],str2[65];
//if ( counter++ < 100 )
if ( counter++ < 100 )
{
for (i=0; i<len; i++)
printf("%02x",blockspace[sizeof(struct iguana_msghdr)+i]);
printf(" error getting txi.%d [%d:%d] cmp.%s %s\n",i,bp->hdrsi,bundlei,bits256_str(str,checktxid),bits256_str(str2,T.txid));
printf(" len.%d error getting txi.%d [%d:%d] cmp.%s %s\n",len,i,bp->hdrsi,bundlei,bits256_str(str,checktxid),bits256_str(str2,T.txid));
}
break;
}
}
else
{
printf("null tx error getting txi.%d [%d:%d]\n",i,bp->hdrsi,bundlei);
printf("%s null tx error getting txi.%d [%d:%d]\n",coin->symbol,i,bp->hdrsi,bundlei);
break;
}
}
@ -320,7 +331,7 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
for (i=0; i<16; i++)
printf("%02x",blockspace[i + sizeof(struct iguana_msghdr)+81]);
printf(" txhdr\n");
if ( (checklen= iguana_gentxarray(coin,&RAWMEM,&txdata,&checklen,&blockspace[sizeof(struct iguana_msghdr)],total)) != total && checklen != total-1 )
if ( (checklen= iguana_gentxarray(myinfo,coin,&RAWMEM,&txdata,&checklen,&blockspace[sizeof(struct iguana_msghdr)],total)) != total && checklen != total-1 )
printf("Error reconstructing txarray checklen.%d total.%d\n",checklen,total);
}
return(iguana_queue_send(addr,0,blockspace,"block",total));
@ -330,9 +341,15 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
//printf("validated.[%d:%d] len.%d\n",bp->hdrsi,bundlei,total);
return(total);
}
} else printf("iguana_peerblockrequest: error merkle cmp tx.[%d] for ht.%d\n",i,bp->bundleheight+bundlei);
} else printf("iguana_peerblockrequest: %s error merkle cmp tx.[%d] for ht.%d\n",coin->symbol,i,bp->bundleheight+bundlei);
} else printf("iguana_peerblockrequest: error merkle verify tx.[%d] for ht.%d\n",i,bp->bundleheight+bundlei);
} else printf("iguana_peerblockrequest: error getting tx.[%d] for ht.%d block.%p main.%d ht.%d\n",i,bp->bundleheight+bundlei,block,block!=0?block->mainchain:-1,block!=0?block->height:-1);
}
else
{
static uint32_t counter;
if ( counter++ < 10 )
printf("%s iguana_peerblockrequest: error getting tx.[%d] for ht.%d block.%p main.%d ht.%d\n",coin->symbol,i,bp->bundleheight+bundlei,block,block!=0?block->mainchain:-1,block!=0?block->height:-1);
}
}
else
{
@ -346,9 +363,9 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
return(-1);
}
cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag)
cJSON *iguana_blockjson(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag)
{
char str[65],hexstr[1024]; int32_t i,len,size; struct iguana_txid *tx,T; struct iguana_msgblock msg;
char str[65],hexstr[1024]; int32_t i,len,size; struct iguana_txid *tx,T; struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; struct iguana_zblock *zblock;
bits256 hash2,nexthash2; uint8_t serialized[1024]; cJSON *array,*json = cJSON_CreateObject();
jaddstr(json,"result","success");
jaddstr(json,"hash",bits256_str(str,block->RO.hash2));
@ -383,20 +400,34 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3
serialized[3] = ((uint8_t *)&block->RO.bits)[0];
init_hexbytes_noT(hexstr,serialized,sizeof(uint32_t));
jaddstr(json,"nBitshex",hexstr);
memset(&msg,0,sizeof(msg));
msg.H.version = block->RO.version;
msg.H.merkle_root = block->RO.merkle_root;
msg.H.timestamp = block->RO.timestamp;
msg.H.bits = block->RO.bits;
if ( block->RO.allocsize == sizeof(struct iguana_zblock) )
{
msg.zH.bignonce = block->zRO[0].bignonce;
msg.zH.numelements = ZCASH_SOLUTION_ELEMENTS;
zblock = (void *)block;
memset(&zmsg,0,sizeof(zmsg));
zmsg.zH.version = zblock->RO.version;
zmsg.zH.merkle_root = zblock->RO.merkle_root;
zmsg.zH.timestamp = zblock->RO.timestamp;
zmsg.zH.bits = zblock->RO.bits;
zmsg.zH.bignonce = zblock->zRO.bignonce;
if ( iguana_rwvarint32(1,zmsg.zH.var_numelements,&zblock->zRO.numelements) != sizeof(zmsg.zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d\n",zblock->zRO.numelements);
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
msg.zH.solution[i] = block->zRO[0].solution[i];
} else msg.H.nonce = block->RO.nonce;
msg.txn_count = 0;//block->RO.txn_count;
len = iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&msg,IGUANA_MAXPACKETSIZE*2);
zmsg.zH.solution[i] = zblock->zRO.solution[i];
zmsg.txn_count = 0;//block->RO.txn_count;
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&zmsg,IGUANA_MAXPACKETSIZE*2);
}
else
{
memset(msg,0,sizeof(&msg));
msg->H.version = block->RO.version;
msg->H.prev_block = block->RO.prev_block;
msg->H.merkle_root = block->RO.merkle_root;
msg->H.timestamp = block->RO.timestamp;
msg->H.bits = block->RO.bits;
msg->H.nonce = block->RO.nonce;
msg->txn_count = 0;//block->RO.txn_count;
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&zmsg,IGUANA_MAXPACKETSIZE*2);
}
init_hexbytes_noT(hexstr,serialized,len);
jaddstr(json,"blockheader",hexstr);
if ( txidsflag != 0 )
@ -410,7 +441,7 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3
jadd(json,"tx",array);
//printf("add txids[%d]\n",block->txn_count);
}
if ( (size= iguana_peerblockrequest(coin,coin->blockspace,coin->blockspacesize,0,block->RO.hash2,0)) < 0 )
if ( (size= iguana_peerblockrequest(myinfo,coin,coin->blockspace,coin->blockspacesize,0,block->RO.hash2,0)) < 0 )
jaddstr(json,"error","couldnt generate raw bytes for block");
else jaddnum(json,"size",size);
return(json);

15
iguana/iguana_txidfind.c

@ -81,7 +81,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
x |= (*ptr & masks[modval]) >> modval;
}
if ( x != 0 )
printf("%s ",bits256_str(str,*(bits256 *)(refdata + x*refsize))), n++;
printf("%s ",bits256_str(str,*(bits256 *)((long)refdata + x*refsize))), n++;
}
printf("tableentries.%d\n",n);
}
@ -316,7 +316,7 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
if ( j < bp->n )
{
if ( j != T[txidind].bundlei )
printf("bundlei mismatch j.%d != %d\n",j,T[txidind].bundlei);
printf("bundlei mismatch j.%d != %u\n",j,(uint32_t)T[txidind].bundlei);
else
{
*heightp = bp->bundleheight + T[txidind].bundlei;
@ -335,7 +335,7 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
return(tx);
}
}
char str[65],str2[65]; printf("iguana_txidfind mismatch.[%d:%d] %d %s vs %s\n",bp->hdrsi,T[txidind].extraoffset,txidind,bits256_str(str,txid),bits256_str(str2,T[txidind].txid));
char str[65],str2[65]; printf("iguana_txidfind mismatch.[%d:%u] %d %s vs %s\n",bp->hdrsi,(uint32_t)T[txidind].extraoffset,txidind,bits256_str(str,txid),bits256_str(str2,T[txidind].txid));
return(0);
}
}
@ -621,7 +621,7 @@ struct iguana_monitorinfo *iguana_monitorfind(struct iguana_info *coin,bits256 t
struct iguana_monitorinfo *iguana_txidreport(struct iguana_info *coin,bits256 txid,struct iguana_peer *addr)
{
struct iguana_monitorinfo *ptr; char str[65];
struct iguana_monitorinfo *ptr; //char str[65];
if ( (ptr= iguana_monitorfind(coin,txid)) != 0 )
{
if ( GETBIT(ptr->peerbits,addr->addrind) == 0 )
@ -630,7 +630,7 @@ struct iguana_monitorinfo *iguana_txidreport(struct iguana_info *coin,bits256 tx
SETBIT(ptr->peerbits,addr->addrind);
ptr->numreported++;
}
} else printf("txid.%s not being monitored\n",bits256_str(str,txid));
} // else printf("%s txid.%s not being monitored\n",coin->symbol,bits256_str(str,txid));
return(0);
}
@ -653,11 +653,12 @@ struct iguana_monitorinfo *iguana_txidmonitor(struct iguana_info *coin,bits256 t
double iguana_txidstatus(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid)
{
int32_t height,firstvout,numranked; struct iguana_monitorinfo *ptr; char str[65];
struct iguana_outpoint outpt; int32_t height,firstvout,numranked; struct iguana_monitorinfo *ptr; char str[65];
if ( coin != 0 && coin->peers != 0 && (numranked= coin->peers->numranked) > 0 )
{
if ( (firstvout= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,txid,0,coin->bundlescount-1,0)) != 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,0,0,0,0,&height,txid,0,coin->bundlescount-1,0) == 0 )
{
firstvout = outpt.unspentind;
if ( (ptr= iguana_monitorfind(coin,txid)) != 0 )
memset(ptr,0,sizeof(*ptr));
return((double)coin->longestchain - height);

347
iguana/iguana_unspents.c

@ -64,12 +64,13 @@ int32_t iguana_RTunspentind2txid(struct supernet_info *myinfo,struct iguana_info
return(-1);
}
int32_t iguana_unspentindfind(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint8_t *spendscript,int32_t *spendlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi,int32_t mempool)
int32_t iguana_unspentindfind(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *spentamountp,char *coinaddr,uint8_t *spendscript,int32_t *spendlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi,int32_t mempool)
{
struct iguana_txid *tp,TX; struct gecko_memtx *memtx; struct iguana_pkhash *P; struct iguana_unspent *U; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int64_t RTspend; int64_t value; struct iguana_outpoint spentpt; int32_t pkind,hdrsi,firstvout,spentheight,flag=0,unspentind = -1;
//portable_mutex_lock(&coin->RTmutex);
if ( valuep != 0 )
*valuep = 0;
*spentamountp = 0;
if ( coinaddr != 0 )
coinaddr[0] = 0;
if ( coin->fastfind != 0 && (firstvout= iguana_txidfastfind(coin,heightp,txid,lasthdrsi)) >= 0 )
@ -94,14 +95,14 @@ int32_t iguana_unspentindfind(struct supernet_info *myinfo,struct iguana_info *c
memset(&spentpt,0,sizeof(spentpt));
spentpt.hdrsi = bp->hdrsi;
spentpt.unspentind = unspentind;
bitcoin_address(coinaddr,iguana_addrtype(coin,U[unspentind].type),P[pkind].rmd160,sizeof(P[pkind].rmd160));
if ( iguana_RTspentflag(myinfo,coin,&RTspend,&spentheight,&bp->ramchain,spentpt,0,1,coin->longestchain,U[unspentind].value) == 0 ) //bp == coin->current ? &coin->RTramchain :
{
if ( valuep != 0 )
*valuep = U[unspentind].value;
bitcoin_address(coinaddr,iguana_addrtype(coin,U[unspentind].type),P[pkind].rmd160,sizeof(P[pkind].rmd160));
if ( spendscript != 0 && spendlenp != 0 )
*spendlenp = iguana_voutscript(coin,bp,spendscript,0,&U[unspentind],&P[pkind],1);
}
} else *spentamountp = RTspend;
}
}
if ( flag == 0 && mempool != 0 )
@ -136,10 +137,8 @@ char *iguana_RTinputaddress(struct supernet_info *myinfo,struct iguana_info *coi
vout = jint(vinobj,"vout");
height = jint(vinobj,"height");
checkind = jint(vinobj,"checkind");
if ( (height != 0 && checkind != 0) || (checkind= iguana_RTunspentindfind(myinfo,coin,coinaddr,0,0,0,&height,txid,vout,coin->bundlescount-1,0)) > 0 )
if ( (height != 0 && checkind != 0) || iguana_RTunspentindfind(myinfo,coin,spentp,coinaddr,0,0,0,&height,txid,vout,coin->bundlescount-1,0) == 0 )
{
spentp->hdrsi = (height / coin->chain->bundlesize);
spentp->unspentind = checkind;
return(coinaddr);
}
else
@ -168,10 +167,9 @@ cJSON *ramchain_unspentjson(struct iguana_unspent *up,uint32_t unspentind)
return(item);
}
cJSON *ramchain_spentjson(struct iguana_info *coin,int32_t spentheight,bits256 txid,int32_t vout,int64_t uvalue)
cJSON *ramchain_spentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t spentheight,bits256 txid,int32_t vout,int64_t uvalue)
{
char coinaddr[64]; bits256 hash2,*X; struct iguana_txid T,*tx,*spentT,*spent_tx; struct iguana_bundle *bp; int32_t j,i,ind; struct iguana_block *block; int64_t total = 0; struct iguana_unspent *U,*u; struct iguana_pkhash *P; struct iguana_spend *S,*s; struct iguana_ramchaindata *rdata; cJSON *addrs,*item,*voutobj;
//RTpath!
char coinaddr[64]; bits256 hash2,*X; struct iguana_txid T,*tx,*spentT,*spent_tx; struct iguana_bundle *bp; int32_t j,i,ind; struct iguana_block *block; int64_t value,total = 0; struct iguana_unspent *U,*u; struct iguana_pkhash *P; struct iguana_spend *S,*s; struct iguana_ramchaindata *rdata; cJSON *addrs,*item,*voutobj;
item = cJSON_CreateObject();
hash2 = iguana_blockhash(coin,spentheight);
if ( (block= iguana_blockfind("spent",coin,hash2)) != 0 && (bp= coin->bundles[spentheight/coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 )
@ -185,8 +183,6 @@ cJSON *ramchain_spentjson(struct iguana_info *coin,int32_t spentheight,bits256 t
{
if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
{
// struct iguana_txid { bits256 txid; uint32_t txidind:29,firstvout:28,firstvin:28,bundlei:11,locktime,version,timestamp,extraoffset; uint16_t numvouts,numvins; } __attribute__((packed));
// struct iguana_spend { uint64_t scriptpos:48,scriptlen:16; uint32_t spendtxidind,sequenceid; int16_t prevout; uint16_t fileid:15,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4
s = &S[tx->firstvin];
for (j=0; j<tx->numvins; j++,s++)
{
@ -226,6 +222,34 @@ cJSON *ramchain_spentjson(struct iguana_info *coin,int32_t spentheight,bits256 t
}
}
}
else
{
struct iguana_RTtxid *RTptr,*tmp; struct iguana_RTspend *spend;
HASH_ITER(hh,coin->RTdataset,RTptr,tmp)
{
for (i=0; i<RTptr->numvins; i++)
{
if ( (spend= RTptr->spends[i]) != 0 )
{
if ( bits256_cmp(spend->prev_hash,txid) == 0 && spend->prev_vout == vout )
{
value = iguana_txidamount(myinfo,coin,coinaddr,txid,vout);
jaddnum(item,"total",dstr(value));
jaddbits256(item,"spentfrom",RTptr->txid);
jaddnum(item,"vin",i);
addrs = cJSON_CreateArray();
voutobj = cJSON_CreateObject();
jaddnum(voutobj,coinaddr,dstr(value));
jaddi(addrs,voutobj);
jadd(item,"vouts",addrs);
jaddnum(item,"timestamp",RTptr->timestamp);
//printf("Found MATCH! (%s %.8f)\n",coinaddr,dstr(value));
return(item);
}
}
}
}
}
jaddstr(item,"error","couldnt find spent info");
return(item);
}
@ -242,8 +266,7 @@ cJSON *iguana_RTunspentjson(struct supernet_info *myinfo,struct iguana_info *coi
"confirmations" : 6210,
"spendable" : true
},*/
//struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind; uint16_t hdrsi:12,type:4,vout; } __attribute__((packed));
struct iguana_waccount *wacct; struct iguana_waddress *waddr; int32_t height; char scriptstr[8192],asmstr[sizeof(scriptstr)+1024]; cJSON *item; uint32_t checkind; struct iguana_RTunspent *unspent;
struct iguana_waccount *wacct; struct iguana_waddress *waddr; int32_t height; char scriptstr[8192],asmstr[sizeof(scriptstr)+1024]; cJSON *item; uint32_t checkind; struct iguana_RTunspent *unspent; struct iguana_block *block;
item = cJSON_CreateObject();
jaddbits256(item,"txid",txid);
jaddnum(item,"vout",vout);
@ -263,8 +286,11 @@ cJSON *iguana_RTunspentjson(struct supernet_info *myinfo,struct iguana_info *coi
}
jaddnum(item,"amount",dstr(value));
//jaddnum(item,"timestamp",T[up->txidind].timestamp);
if ( (checkind= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,txid,vout,coin->bundlescount-1,0)) != 0 )
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,0,0,0,0,&height,txid,vout,coin->bundlescount-1,0) == 0 )
{
checkind = outpt.unspentind;
if ( (block= iguana_blockfind("unspentjson",coin,iguana_blockhash(coin,height))) != 0 && block->RO.timestamp != 0 )
jaddnum(item,"timestamp",block->RO.timestamp);
jaddnum(item,"height",height);
jaddnum(item,"confirmations",coin->blocks.hwmchain.height - height + 1);
jaddnum(item,"checkind",checkind);
@ -284,7 +310,7 @@ cJSON *iguana_RTunspentjson(struct supernet_info *myinfo,struct iguana_info *coi
if ( up != 0 )
jadd(item,"spent",ramchain_unspentjson(up,outpt.unspentind));
jaddnum(item,"spentheight",spentheight);
jadd(item,"dest",ramchain_spentjson(coin,spentheight,txid,vout,value));
jadd(item,"dest",ramchain_spentjson(myinfo,coin,spentheight,txid,vout,value));
}
else if ( up != 0 )
jadd(item,"unspent",ramchain_unspentjson(up,outpt.unspentind));
@ -400,7 +426,7 @@ int32_t iguana_RTscanunspents(struct supernet_info *myinfo,struct iguana_info *c
{
if ( unspent->spend == 0 )
{
spentheight = unspent->height;
spentheight = 0;
memset(&outpt,0,sizeof(outpt));
memset(&txid,0,sizeof(txid));
if ( (parent= unspent->parent) != 0 )
@ -408,6 +434,9 @@ int32_t iguana_RTscanunspents(struct supernet_info *myinfo,struct iguana_info *c
else printf("unspent has no parent?\n");
outpt.isptr = 1;
outpt.ptr = unspent;
outpt.txid = txid;
outpt.vout = unspent->vout;
outpt.value = unspent->value;
outpt.hdrsi = unspent->height / coin->chain->bundlesize;
if ( array != 0 )
jaddi(array,iguana_RTunspentjson(myinfo,coin,outpt,txid,unspent->vout,unspent->value,0,rmd160,coinaddr,pubkey33,spentheight,remoteaddr));
@ -437,7 +466,12 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info *
if ( lastpt.isptr != 0 )
{
*nump = iguana_RTscanunspents(myinfo,coin,remoteaddr,array,spentp,&deposits,unspents,max,rmd160,coinaddr,pubkey33,lastpt,lastheight);
} else printf("iguana_pkhashbalance: unexpected non-ptr lastpt\n");
}
else
{
printf("iguana_pkhashbalance: unexpected RT non-ptr lastpt\n");
coin->RTreset_needed = 1;
}
return(deposits - *spentp);
}
if ( ramchain->Uextras == 0 || (rdata= ramchain->H.data) == 0 )
@ -459,8 +493,11 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info *
uheight = iguana_uheight(coin,ramchain->height,T,rdata->numtxids,&U[unspentind]);
if ( lastheight <= 0 || uheight < lastheight )
{
//printf("u%u ",unspentind);
deposits += U[unspentind].value;
memset(&outpt,0,sizeof(outpt));
outpt.txid = T[U[unspentind].txidind].txid;
outpt.vout = unspentind - T[U[unspentind].txidind].firstvout;
outpt.hdrsi = lastpt.hdrsi;
outpt.isptr = 0;
outpt.unspentind = unspentind;
@ -507,7 +544,7 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info *
printf("spend %s: [%d] deposits %.8f spent %.8f check %.8f (%.8f) vs A2[%u] %.8f\n",lastheight==IGUANA_MAXHEIGHT?"checkerr":"",lastpt.hdrsi,dstr(deposits),dstr(spent),dstr(checkval)+dstr(RTspend),dstr(*spentp),pkind,dstr(A2[pkind].total));
}
(*spentp) = spent;
//printf("(%s) spent %.8f, RTspent %.8f deposits %.8f\n",coinaddr,dstr(spent),dstr(RTspend),dstr(deposits));
//printf("[%d] (%s) spent %.8f, RTspent %.8f deposits %.8f\n",ramchain->height/coin->chain->bundlesize,coinaddr,dstr(spent),dstr(RTspend),dstr(deposits));
return(deposits - spent);
}
@ -527,12 +564,12 @@ int32_t iguana_RTpkhasharray(struct supernet_info *myinfo,struct iguana_info *co
if ( max > coin->bundlescount )
max = coin->bundlescount;
//printf("minconf.%d maxconf.%d max.%d addr.%s last.%d maxunspents.%d\n",minconf,maxconf,max,coinaddr,lastheight,maxunspents);
for (total=n=i=0; i<max+(lastheight>=coin->RTheight); i++)
for (total=n=i=0; i<max+(lastheight>=coin->firstRTheight); i++)
{
bp = 0;
if ( i != max && (bp= coin->bundles[i]) == 0 )
continue;
else bp = 0;
if ( 0 && bp != 0 )
if ( bp != 0 )
{
if ( lastheight > 0 && bp->bundleheight > lastheight )
{
@ -583,7 +620,7 @@ int32_t iguana_RTpkhasharray(struct supernet_info *myinfo,struct iguana_info *co
int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,struct iguana_outpoint *unspents,int32_t *numunspentsp,char *remoteaddr,int32_t includespent)
{
uint64_t total=0,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,numunspents,maxunspents,flag = 0; char coinaddr[64];
uint64_t total=0,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,j,numunspents,maxunspents,flag = 0; char coinaddr[64];
//portable_mutex_lock(&coin->RTmutex);
while ( 0 && coin->RTramchain_busy != 0 )
{
@ -600,9 +637,14 @@ int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin,
P = calloc(coin->bundlescount,sizeof(*P));
for (i=0; i<numrmds; i++)
{
for (j=0; j<20; j++)
if ( rmdarray[i*20 + j] != 0 )
break;
if ( j == 20 )
continue;
bitcoin_address(coinaddr,addrtypes[i],&rmdarray[i * 20],20);
*numunspentsp = 0;
iguana_RTpkhasharray(myinfo,coin,array,minconf,maxconf,&total,P,coin->bundlescount,&rmdarray[i * 20],coinaddr,&pubkeys[33*i],lastheight,&unspents[numunspents],numunspentsp,maxunspents,remoteaddr,includespent);
iguana_RTpkhasharray(myinfo,coin,array,minconf,maxconf,&total,P,coin->bundlescount,&rmdarray[i * 20],coinaddr,&pubkeys[33*i],lastheight,unspents != 0 ? &unspents[numunspents] : 0,numunspentsp,maxunspents,remoteaddr,includespent);
//printf("iguana_unspents: i.%d of %d: %s %.8f numunspents.%d\n",i,numrmds,coinaddr,dstr(total),*numunspentsp);
maxunspents -= *numunspentsp;
numunspents += *numunspentsp;
@ -620,7 +662,7 @@ int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin,
uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti)
{
int32_t i,n,flag=0,j=0; char *coinaddr,rmdstr[41]; uint8_t *addrtypes,*rmdarray = 0;
int32_t i,n,flag=0,k,j=0; char *coinaddr,rmdstr[41]; uint8_t addrtype,*addrtypes,*rmdarray = 0;
*numrmdsp = 0;
if ( array == 0 || cJSON_GetArraySize(array) == 0 )
array = iguana_getaddressesbyaccount(myinfo,coin,"*");
@ -633,9 +675,19 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i
{
if ( (coinaddr= jstr(jitem(array,i),0)) != 0 )
{
//printf("(%s %s) ",coinaddr,rmdstr);
if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 )
{
printf("i.%d illegal coinaddr.(%s) longest.%d\n",i,coinaddr,coin->longestchain);
continue;
}
bitcoin_addr2rmd160(&addrtypes[j],&rmdarray[20 * j],coinaddr);
for (k=0; k<20; k++)
if ( rmdarray[20 * j + k] != 0 )
break;
if ( k == 20 )
continue;
init_hexbytes_noT(rmdstr,&rmdarray[20 * j],20);
//printf("(%s %s) ",coinaddr,rmdstr);
j++;
}
}
@ -648,7 +700,7 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i
int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight)
{
int64_t balance,total,supply,*weights=0; uint32_t pkind; int32_t numrmds,minconf,neg,numunspents,nonz,num=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; struct iguana_pkhash *refP; uint8_t rmd160[20],*rmdarray; cJSON *array; char coinaddr[64]; //struct iguana_account *A2; struct iguana_utxo *U2;
int64_t balance,total,supply,*weights=0; uint32_t pkind; int32_t j,numrmds,minconf,neg,numunspents,nonz,num=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; struct iguana_pkhash *refP; uint8_t rmd160[20],*rmdarray; cJSON *array; char coinaddr[64]; //struct iguana_account *A2; struct iguana_utxo *U2;
*supplyp = 0;
*numacctsp = *nonzp = 0;
*errsp = 1;
@ -666,6 +718,11 @@ int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coi
{
total = 0;
memcpy(rmd160,refP[pkind].rmd160,sizeof(rmd160));
for (j=0; j<20; j++)
if ( rmd160[j] != 0 )
break;
if ( j == 20 )
continue;
array = cJSON_CreateArray();
bitcoin_address(coinaddr,coin->chain->pubtype,rmd160,sizeof(rmd160));
jaddistr(array,coinaddr);
@ -754,11 +811,13 @@ int32_t iguana_RTunspent_check(struct supernet_info *myinfo,struct iguana_info *
if ( iguana_RTunspentind2txid(myinfo,coin,&spentheight,&txid,&vout,outpt) == 0 )
{
//char str[65]; printf("verify %s/v%d is not already used\n",bits256_str(str,txid),vout);
if ( basilisk_addspend(myinfo,coin->symbol,txid,vout,0) != 0 )
//return(iguana_RTspentflag(myinfo,coin,&RTspend,&spentheight,ramchain,outpt,height,minconf,coin->longestchain,U[unspentind].value));
/*if ( basilisk_addspend(myinfo,coin->symbol,txid,vout,0) != 0 )
{
char str[65]; printf("iguana_unspent_check found unspentind (%u %d) %s\n",outpt.hdrsi,outpt.unspentind,bits256_str(str,txid));
return(1);
} else return(0);
} else return(0);*/
return(0);
}
printf("iguana_unspent_check: couldnt find (%d %d)\n",outpt.hdrsi,outpt.unspentind);
return(-1);
@ -766,10 +825,20 @@ int32_t iguana_RTunspent_check(struct supernet_info *myinfo,struct iguana_info *
int32_t iguana_RTaddr_unspents(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *sump,struct iguana_outpoint *unspents,int32_t max,char *coinaddr,char *remoteaddr,int32_t lastheight,int32_t includespent)
{
int32_t n,k,numunspents,minconf = 0; uint64_t total; uint8_t rmd160[20],pubkey[65],addrtype;
int32_t n,j,k,numunspents,minconf = 0; uint64_t total; uint8_t rmd160[20],pubkey[65],addrtype;
total = 0;
n = numunspents = 0;
if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 )
{
printf("illegal coinaddr.(%s) minconf.%d longest.%d diff.%d\n",coinaddr,minconf,coin->longestchain,coin->blocks.hwmchain.height - minconf);
return(0);
}
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
for (j=0; j<20; j++)
if ( rmd160[j] != 0 )
break;
if ( j == 20 )
return(0);
iguana_RTpkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,lastheight,unspents,&n,max-1000,remoteaddr,includespent);
numunspents = n;
for (k=0; k<n; k++)
@ -777,65 +846,6 @@ int32_t iguana_RTaddr_unspents(struct supernet_info *myinfo,struct iguana_info *
return(numunspents);
}
int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr)
{
uint64_t sum = 0; int32_t k,i,j,r,numunspents,numaddrs; uint8_t pubkey[65]; char *coinaddr,str[65]; struct iguana_waddress *waddr; struct iguana_waccount *wacct; struct basilisk_unspent *bu; struct iguana_outpoint outpt;
*totalp = 0;
if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 )
{
printf("null addresses.(%s)\n",jprint(addresses,0));
return(0);
}
memset(pubkey,0,sizeof(pubkey));
//remains = required * 1.1 + coin->txfee;
for (i=numunspents=0; i<numaddrs; i++)
{
if ( (coinaddr= jstri(addresses,i)) != 0 )
{
//printf("i.%d coinaddr.(%s) minconf.%d longest.%d diff.%d\n",i,coinaddr,minconf,coin->longestchain,coin->blocks.hwmchain.height - minconf);
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
numunspents += iguana_RTaddr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,remoteaddr,coin->blocks.hwmchain.height - minconf,0);
}
else
{
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 && waddr->numunspents > 0 )
{
r = (rand() % waddr->numunspents);
for (j=0; j<waddr->numunspents; j++)
{
i = ((j + r) % waddr->numunspents);
bu = &waddr->unspents[i];
if ( basilisk_addspend(myinfo,coin->symbol,bu->txid,bu->vout,0) == 0 )
{
for (k=0; k<numunspents; k++)
{
// filterout duplicates here
}
memset(&outpt,0,sizeof(outpt));
outpt.hdrsi = bu->hdrsi;
outpt.isptr = 0;
outpt.unspentind = bu->unspentind;
outpt.value = bu->value;
*unspents = outpt;
sum += bu->value;
printf("ADD unspent, mark spent\n");
basilisk_addspend(myinfo,coin->symbol,bu->txid,bu->vout,1);
unspents++;
numunspents++;
} else printf("skip pending txid.%s/v%d\n",bits256_str(str,bu->txid),bu->vout);
}
}
}
if ( numunspents > max || sum > required )
break;
//printf("n.%d max.%d total %.8f\n",n,max,dstr(total));
}
}
*totalp = sum;
return(numunspents);
}
int32_t iguana_RTuvaltxid(struct supernet_info *myinfo,bits256 *txidp,struct iguana_info *coin,struct iguana_outpoint outpt)
{
struct iguana_bundle *bp; struct iguana_unspent *U,*u; struct iguana_txid *T; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_RTunspent *unspent; struct iguana_RTtxid *parent;
@ -894,13 +904,95 @@ uint64_t iguana_unspentavail(struct supernet_info *myinfo,struct iguana_info *co
else return(0);
}
cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *argarray,int32_t minconf,int32_t maxconf,char *remoteaddr)
int32_t iguana_unspentfindjson(cJSON *destarray,cJSON *item)
{
int32_t numrmds,numunspents=0; uint8_t *rmdarray; cJSON *retjson = cJSON_CreateArray();
rmdarray = iguana_rmdarray(myinfo,coin,&numrmds,argarray,0);
iguana_RTunspents(myinfo,coin,retjson,minconf,maxconf,rmdarray,numrmds,(1 << 30),0,&numunspents,remoteaddr,0);
if ( rmdarray != 0 )
free(rmdarray);
cJSON *destitem; int32_t i,n;
if ( (n= cJSON_GetArraySize(destarray)) > 0 )
{
for (i=0; i<n; i++)
{
destitem = jitem(destarray,i);
if ( jint(destitem,"vout") == jint(item,"vout") && bits256_cmp(jbits256(destitem,"txid"),jbits256(item,"txid")) == 0 )
return(i);
}
}
return(-1);
}
cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *argarray,int32_t minconf,int32_t maxconf,char *remoteaddr,int32_t includespends)
{
int32_t i,j,m,n,numrmds,numunspents=0; char *coinaddr,*retstr; uint8_t *rmdarray; cJSON *vals,*unspents,*item,*array,*retjson,*retarray; bits256 hash;
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
retjson = cJSON_CreateArray();
rmdarray = iguana_rmdarray(myinfo,coin,&numrmds,argarray,0);
iguana_RTunspents(myinfo,coin,retjson,minconf,maxconf,rmdarray,numrmds,(1 << 30),0,&numunspents,remoteaddr,includespends);
if ( rmdarray != 0 )
free(rmdarray);
}
else
{
portable_mutex_lock(&myinfo->bu_mutex);
if ( (unspents= myinfo->Cunspents) != 0 && (array= jobj(unspents,coin->symbol)) != 0 )
unspents = jduplicate(array);
portable_mutex_unlock(&myinfo->bu_mutex);
retjson = cJSON_CreateArray();
if ( unspents != 0 )
{
if ( (n= cJSON_GetArraySize(unspents)) > 0 && (m= cJSON_GetArraySize(argarray)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(unspents,i);
if ( (coinaddr= jstr(item,"address")) != 0 )
{
for (j=0; j<m; j++)
if ( strcmp(coinaddr,jstri(argarray,j)) == 0 )
{
jaddi(retjson,jduplicate(item));
break;
}
}
}
}
//printf("RET.(%s)\n",jprint(retjson,0));
free_json(unspents);
}
if ( cJSON_GetArraySize(retjson) == 0 && cJSON_GetArraySize(argarray) > 0 )
{
memset(hash.bytes,0,sizeof(hash));
vals = cJSON_CreateObject();
jaddstr(vals,"coin",coin->symbol);
jaddnum(vals,"history",1);
jaddnum(vals,"firstheight",0);
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
jaddnum(vals,"numrequired",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
jadd(vals,"addresses",jduplicate(argarray));
if ( (retstr= basilisk_standardservice("BAL",myinfo,0,hash,vals,"",1)) != 0 )
{
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(retarray)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(retarray,i);
if ( (unspents= jarray(&m,item,"unspents")) != 0 )
{
for (j=0; j<m; j++)
if ( iguana_unspentfindjson(retjson,jitem(unspents,j)) < 0 )
jaddi(retjson,jduplicate(jitem(unspents,j)));
}
}
}
free_json(retarray);
}
//printf("LIST.(%s)\n",retstr);
free(retstr);
}
free_json(vals);
}
}
/*{
"txid" : "d54994ece1d11b19785c7248868696250ab195605b469632b7bd68130e880c9a",
"vout" : 1,
@ -911,10 +1003,63 @@ cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coi
"confirmations" : 6210,
"spendable" : true
},*/
return(retjson);
}
int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr)
{
uint64_t sum = 0; int32_t i,n,numunspents,numaddrs; uint8_t pubkey[65]; char *coinaddr,*spendscriptstr; struct iguana_outpoint outpt; cJSON *array,*item;
*totalp = 0;
numunspents = 0;
if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 )
{
printf("null addresses.(%s)\n",jprint(addresses,0));
return(0);
}
memset(pubkey,0,sizeof(pubkey));
//remains = required * 1.1 + coin->txfee;
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
for (i=numunspents=0; i<numaddrs; i++)
{
if ( (coinaddr= jstri(addresses,i)) != 0 )
{
numunspents += iguana_RTaddr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,remoteaddr,1<<30,0);
}
}
}
else
{
if ( (array= iguana_RTlistunspent(myinfo,coin,addresses,minconf,1<<30,remoteaddr,0)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (spendscriptstr= jstr(item,"scriptPubKey")) == 0 )
{
printf("no spendscriptstr.(%s)\n",jprint(item,0));
continue;
}
iguana_outptset(myinfo,coin,&outpt,jbits256(item,"txid"),jint(item,"vout"),jdouble(item,"amount") * SATOSHIDEN,spendscriptstr);
*unspents = outpt;
sum += outpt.value;
printf("ITEM.(%s) %.8f\n",jprint(item,0),dstr(outpt.value));
unspents++;
numunspents++;
if ( numunspents > max || sum > required )
break;
}
}
free_json(array);
}
}
*totalp = sum;
printf("numunspents.%d max.%d sum %.8f required %.8f\n",numunspents,max,dstr(sum),dstr(required));
return(numunspents);
}
#define UTXOADDR_ITEMSIZE 32
#define iguana_utxotable_numinds(ind) (((ind) == 0xffff) ? coin->utxoaddrlastcount : (coin->utxoaddroffsets[(ind) + 1] - coin->utxoaddroffsets[ind]))
@ -1268,9 +1413,15 @@ uint64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *co
{
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight )
{
balance += iguana_bundle_unspents(coin,bp,&last);
fprintf(stderr,"(%d %.8f) ",hdrsi,dstr(balance));
height = bp->bundleheight + bp->n;
iguana_volatilespurge(coin,&bp->ramchain);
if ( iguana_volatilesmap(coin,&bp->ramchain) != 0 )
printf("error mapping bundle.[%d]\n",hdrsi);
else
{
balance += iguana_bundle_unspents(coin,bp,&last);
fprintf(stderr,"(%d %.8f) ",hdrsi,dstr(balance));
height = bp->bundleheight + bp->n;
}
}
}
sprintf(fname,"%s/%s/utxoaddrs",GLOBAL_DBDIR,coin->symbol), OS_portable_path(fname);

52
iguana/iguana_volatiles.c

@ -162,14 +162,16 @@ int32_t iguana_RTutxofunc(struct iguana_info *coin,int32_t *fromheightp,int32_t
if ( (rdata= ramchain->H.data) == 0 )
return(1);
val = ((uint64_t)spentpt.hdrsi << 32) | spentpt.unspentind;
if ( (utxo.fromheight= fromheight) != 0 )
utxo.spentflag = 1;
if ( fromheight != 0 )
utxo.fromheight = fromheight, utxo.spentflag = 1;
if ( spentpt.unspentind > 0 && spentpt.unspentind < rdata->numunspents )
{
if ( ramchain->Uextras != 0 )
{
utxo = ramchain->Uextras[spentpt.unspentind];
if ( lockflag != 0 )
if ( fromheight != 0 )
utxo.fromheight = fromheight, utxo.spentflag = 1;
if ( lockflag != 0 || fromheight != 0 )
{
if ( (hhutxo= iguana_hhutxofind(coin,val)) == 0 )
{
@ -178,13 +180,20 @@ int32_t iguana_RTutxofunc(struct iguana_info *coin,int32_t *fromheightp,int32_t
hhutxo->u = utxo;
HASH_ADD_KEYPTR(hh,coin->utxotable,&hhutxo->uval,sizeof(hhutxo->uval),hhutxo);
}
printf("iguana_utxofind: need to change to new RT lock method\n");
//printf("iguana_utxofind: need to change to new RT lock method\n");
}
}
if ( ramchain->Uextras == 0 || utxo.spentflag == 0 )
{
if ( (hhutxo= iguana_hhutxofind(coin,val)) != 0 )
{
utxo = hhutxo->u;
if ( fromheight != 0 )
{
utxo.fromheight = fromheight, utxo.spentflag = 1;
hhutxo->u = utxo;
}
}
//printf("iguana_utxofind: need to change to new RT method\n");
}
}
@ -207,7 +216,7 @@ int32_t iguana_RTutxofunc(struct iguana_info *coin,int32_t *fromheightp,int32_t
int32_t iguana_RTspentflag(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *RTspendp,int32_t *spentheightp,struct iguana_ramchain *ramchain,struct iguana_outpoint spentpt,int32_t height,int32_t minconf,int32_t maxconf,uint64_t amount)
{
uint32_t numunspents; int32_t RTspentflag,spentflag,lockedflag,fromheight; uint64_t confs;//,RTspend = 0;
uint32_t numunspents; int32_t RTspentflag,spentflag,lockedflag,fromheight=0; uint64_t confs;//,RTspend = 0;
struct iguana_ramchaindata *rdata; struct iguana_RTunspent *unspent;
*spentheightp = -1;
if ( coin->disableUTXO != 0 )
@ -219,6 +228,7 @@ int32_t iguana_RTspentflag(struct supernet_info *myinfo,struct iguana_info *coin
{
if ( (unspent= spentpt.ptr) != 0 )
{
*spentheightp = unspent->fromheight;
if ( unspent->spend != 0 )
{
*RTspendp += (amount == 0) ? coin->txfee : amount;
@ -305,30 +315,10 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
{
//double startmillis = OS_milliseconds(); static double totalmillis; static int32_t utxon;
printf("hhutxo deprecated\n");
exit(-1);
/*spentP = RAMCHAIN_PTR(rdata,Poffset);
spentU = RAMCHAIN_PTR(rdata,Uoffset);
if ( iguana_utxoupdate(coin,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,fromheight,spentP[spent_pkind].rmd160) == 0 )
{
//totalmillis += (OS_milliseconds() - startmillis);
// if ( (++utxon % 100000) == 0 )
// printf("ave utxo[%d] %.2f micros total %.2f seconds\n",utxon,(1000. * totalmillis)/utxon,totalmillis/1000.);
//portable_mutex_unlock(&coin->RTmutex);
return(0);
}*/
iguana_exit(0,0);
}
//portable_mutex_unlock(&coin->RTmutex);
printf("end iguana_volatileupdate.%d: [%d] spent.(u%u %.8f pkind.%d) double spend? at ht.%d [%d] spendind.%d (%p %p)\n",incremental,spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind,spentchain->Uextras,spentchain->A2);
/*if ( coin->current != 0 && fromheight >= coin->current->bundleheight )
coin->RTdatabad = 1;
else
{
printf("from.%d vs current.%d\n",fromheight,coin->current->bundleheight);
iguana_bundleremove(coin,fromheight/coin->chain->bundlesize,0);
}
coin->spendvectorsaved = 0;
coin->started = 0;
coin->active = 0;*/
coin->RTdatabad = 1;
if ( coin->current != 0 && spent_hdrsi != coin->current->hdrsi && spent_hdrsi != fromheight/coin->chain->bundlesize )
{
@ -346,7 +336,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
bp->ramchain.H.data = 0;
}
portable_mutex_unlock(&coin->special_mutex);
exit(-1);
iguana_exit(0,0);
}
}
else if ( coin->spendvectorsaved > 1 )
@ -406,9 +396,9 @@ void iguana_volatilespurge(struct iguana_info *coin,struct iguana_ramchain *ramc
if ( ramchain != 0 )
{
//printf("volatilespurge.[%d] (%p %p) %p %p\n",ramchain->height/coin->chain->bundlesize,ramchain->A2,ramchain->Uextras,ramchain->debitsfileptr,ramchain->lastspendsfileptr);
if ( ramchain->allocatedA2 != 0 && ramchain->A2 != 0 && ramchain->A2 != ramchain->debitsfileptr+sizeof(bits256)*2+sizeof(int32_t) )
if ( ramchain->allocatedA2 != 0 && ramchain->A2 != 0 && (long)ramchain->A2 != (long)ramchain->debitsfileptr+sizeof(bits256)*2+sizeof(int32_t) )
free(ramchain->A2);
if ( ramchain->allocatedU2 != 0 && ramchain->Uextras != 0 && ramchain->Uextras != ramchain->lastspendsfileptr+sizeof(bits256)*2+sizeof(int32_t) )
if ( ramchain->allocatedU2 != 0 && ramchain->Uextras != 0 && (long)ramchain->Uextras != (long)ramchain->lastspendsfileptr+sizeof(bits256)*2+sizeof(int32_t) )
free(ramchain->Uextras);
ramchain->A2 = 0;
ramchain->Uextras = 0;
@ -492,7 +482,9 @@ int32_t iguana_volatilesmap(struct iguana_info *coin,struct iguana_ramchain *ram
}
else
{
printf("ramchain.[%d] map error balanceswritten %d vs %d hashes %x %x\n",rdata->height,coin->balanceswritten,numhdrsi,coin->balancehash.uints[0],balancehash.uints[0]);
static uint32_t counter;
if ( counter++ < 3 )
printf("ramchain.[%d] map error balanceswritten %d vs %d hashes %x %x\n",rdata->height,coin->balanceswritten,numhdrsi,coin->balancehash.uints[0],balancehash.uints[0]);
err++;
OS_removefile(fname,0);
}

257
iguana/iguana_wallet.c

@ -31,10 +31,18 @@ void scrubfree(char *sensitivestr)
struct iguana_waddress *iguana_waddressfind(struct supernet_info *myinfo,struct iguana_waccount *wacct,char *coinaddr)
{
struct iguana_waddress *waddr; uint8_t addrtype,rmd160[20];
struct iguana_waddress *waddr,*tmp; uint8_t addrtype,rmd160[20];
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
//calc_rmd160_sha256(rmd160,pubkey33,33);
HASH_FIND(hh,wacct->waddr,rmd160,sizeof(rmd160),waddr);
if ( waddr == 0 )
{
HASH_ITER(hh,wacct->waddr,waddr,tmp)
{
printf("%s ",waddr->coinaddr);
}
printf("not in %s\n",wacct->account);
}
//if ( waddr != 0 && coin != 0 && strcmp(coin->symbol,waddr->symbol) != 0 )
// return(0);
//printf("%s (%s).%d in (%s)\n",waddr==0?"couldnt find":"found",coinaddr,len,wacct->account);
@ -78,7 +86,7 @@ struct iguana_waccount *iguana_waccountcreate(struct supernet_info *myinfo,char
wacct = mycalloc('w',1,sizeof(*wacct) + len);
strcpy(wacct->account,account);
HASH_ADD_KEYPTR(hh,myinfo->wallet,wacct->account,len,wacct);
printf("waccountcreate.(%s) -> wacct.%p\n",account,wacct);
//printf("waccountcreate.(%s) -> wacct.%p\n",account,wacct);
if ( (ptr= iguana_waccountfind(myinfo,account)) != wacct )
{
printf("ERROR: iguana_waccountcreate verify error %p vs %p\n",ptr,wacct);
@ -116,7 +124,7 @@ struct iguana_waddress *iguana_waddresscreate(struct supernet_info *myinfo,struc
struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,struct iguana_waddress *addwaddr,char *redeemScript)
{
struct iguana_waddress *waddr,*ptr; uint8_t rmd160[20],addrtype;
printf("search for (%s)\n",addwaddr->coinaddr);
//printf("search for (%s)\n",addwaddr->coinaddr);
bitcoin_addr2rmd160(&addrtype,rmd160,addwaddr->coinaddr);
HASH_FIND(hh,wacct->waddr,rmd160,sizeof(rmd160),waddr);
if ( waddr == 0 )
@ -151,9 +159,9 @@ struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct i
{
waddr->addrtype = addrtype;//coin->chain->pubtype;
waddr->wiftype = addwaddr->wiftype;
if ( bits256_nonz(waddr->privkey) == 0 )
//if ( bits256_nonz(waddr->privkey) == 0 )
waddr->privkey = addwaddr->privkey;
if ( addwaddr->wifstr[0] != 0 )
//if ( addwaddr->wifstr[0] != 0 )
strcpy(waddr->wifstr,addwaddr->wifstr);
memcpy(waddr->rmd160,rmd160,sizeof(waddr->rmd160));
calc_rmd160_sha256(rmd160,addwaddr->pubkey,bitcoin_pubkeylen(addwaddr->pubkey));
@ -167,9 +175,9 @@ struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct i
{
HASH_ADD_KEYPTR(hh,wacct->waddr,waddr->rmd160,sizeof(waddr->rmd160),waddr);
myinfo->dirty = (uint32_t)time(NULL);
int32_t i; for (i=0; i<20; i++)
printf("%02x",waddr->rmd160[i]);
printf(" add (%s) scriptlen.%d -> (%s) wif.(%s)\n",waddr->coinaddr,waddr->scriptlen,wacct->account,waddr->wifstr);
//int32_t i; for (i=0; i<20; i++)
// printf("%02x",waddr->rmd160[i]);
//printf(" add (%s) scriptlen.%d -> (%s) wif.(%s)\n",waddr->coinaddr,waddr->scriptlen,wacct->account,waddr->wifstr);
}
else
{
@ -245,17 +253,21 @@ struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struc
addr = *waddr;
flag = 1;
iguana_waddressdelete(myinfo,coin,wacct,coinaddr);
waddr = 0;
}
}
if ( (wacct= iguana_waccountcreate(myinfo,account)) != 0 )
{
waddr = iguana_waddresscreate(myinfo,coin,wacct,coinaddr,redeemScript);
if ( waddr == 0 )
waddr = iguana_waddresscreate(myinfo,coin,wacct,coinaddr,redeemScript);
if ( waddr != 0 )
{
if ( redeemScript == 0 )
iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,waddr,addr.privkey);
strcpy(waddr->coinaddr,coinaddr);
waddr = iguana_waddressadd(myinfo,coin,wacct,waddr,redeemScript);
if ( flag != 0 )
waddr->privkey = addr.privkey;
} else waddr = 0;
}
myinfo->dirty = (uint32_t)time(NULL);
@ -264,7 +276,7 @@ struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struc
uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp)
{
int32_t iter,n,m; struct iguana_waccount *acct,*tmp; uint8_t *pubkeys,*addrtypes,*rmdarray = 0; struct iguana_waddress *waddr,*tmp2;
int32_t iter,n,m; struct iguana_waccount *acct,*tmp; uint8_t *pubkeys=0,*addrtypes=0,*rmdarray = 0; struct iguana_waddress *waddr,*tmp2;
for (iter=n=m=0; iter<2; iter++)
{
HASH_ITER(hh,myinfo->wallet,acct,tmp)
@ -273,7 +285,7 @@ uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin
{
if ( iter == 0 )
n++;
else if ( m < n )
else if ( addrtypes != 0 && pubkeys != 0 && m < n )
{
addrtypes[m] = waddr->addrtype;
memcpy(&rmdarray[m * 20],waddr->rmd160,20);
@ -295,6 +307,8 @@ uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin
cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account)
{
struct iguana_waccount *subset,*tmp; char refaddr[64],coinaddr[64]; struct iguana_waddress *waddr,*tmp2; cJSON *retjson,*array;
if ( coin == 0 )
return(0);
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
if ( account == 0 || account[0] == 0 )
@ -453,6 +467,7 @@ char *iguana_walletvalue(char *buf,struct iguana_waddress *waddr)
if ( waddr->scriptlen > 0 )
init_hexbytes_noT(buf,waddr->redeemScript,waddr->scriptlen);
else init_hexbytes_noT(buf,waddr->privkey.bytes,sizeof(waddr->privkey));
//char str[65]; printf("%s -> walletvalue.(%s)\n",bits256_str(str,waddr->privkey),buf);
return(buf);
}
@ -464,6 +479,7 @@ int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *co
if ( account == 0 || account[0] == 0 )
account = "default";
payload = cJSON_DetachItemFromObject(retjson,"wallet");
//printf("PAYLOAD.(%s)\n",jprint(payload,0));
if ( payload == 0 )
payload = cJSON_CreateObject();
if ( waddr != 0 && (valuestr= iguana_walletvalue(valuebuf,waddr)) != 0 )
@ -479,13 +495,13 @@ int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *co
{
accountobj = cJSON_CreateObject();
jadd(payload,account,accountobj);
//printf("ADDACCOUNT.(%s)\n",jprint(accountobj,0));
}
jaddstr(accountobj,rmdstr,valuestr);
}
jadd(retjson,"wallet",payload);
newstr = jprint(retjson,1);
retval = iguana_loginsave(myinfo,coin,newstr);
//printf("newstr.(%s) retval.%d\n",newstr,retval);
free(newstr);
} else printf("iguana_payloadupdate: error parsing.(%s)\n",retstr);
return(retval);
@ -518,7 +534,8 @@ cJSON *iguana_payloadmerge(cJSON *loginjson,cJSON *importjson)
cJSON *iguana_walletadd(struct supernet_info *myinfo,struct iguana_waddress **waddrp,struct iguana_info *coin,char *retstr,char *account,struct iguana_waddress *refwaddr,int32_t setcurrent,char *redeemScript)
{
cJSON *retjson=0; struct iguana_waccount *wacct; struct iguana_waddress *waddr;
cJSON *retjson=0; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0;
printf("walletaddr.(%s)\n",retstr);
if ( (wacct= iguana_waccountfind(myinfo,account)) == 0 )
wacct = iguana_waccountcreate(myinfo,account);
if ( wacct != 0 )
@ -599,7 +616,7 @@ char *iguana_walletfields(struct iguana_info *coin,int32_t *p2shflagp,char *wifs
int32_t iguana_walletemit(struct supernet_info *myinfo,char *fname,struct iguana_info *coin,cJSON *array)
{
cJSON *item,*child; char str[64],wifstr[128],*account,coinaddr[64],*privstr; int32_t i,n,p2shflag; FILE *fp;
cJSON *item,*child; char str[65],wifstr[128],*account,coinaddr[64],*privstr; int32_t i,n,p2shflag; FILE *fp;
if ( (fp= fopen(fname,"wb")) == 0 )
return(-1);
n = cJSON_GetArraySize(array);
@ -745,8 +762,11 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
if ( flag < -1 )
{
HASH_DELETE(hh,wacct->waddr,waddr);
if ( waddr->unspents != 0 )
free(waddr->unspents);
/*if ( waddr->Cunspents != 0 )
free_json(waddr->Cunspents), waddr->Cunspents = 0;
if ( waddr->Cspends != 0 )
free_json(waddr->Cspends), waddr->Cspends = 0;
*/
//printf("walletiterate: %p free %s\n",waddr,waddr->coinaddr);
myfree(waddr,sizeof(*waddr) + waddr->scriptlen);
}
@ -798,7 +818,7 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
}
printf("persistent address not found in wallet, autoadd.(%s)\n",coinaddr);
}
else if ( persistent_flag != 0 )
else if ( persistent_flag != 0 && 0 )
printf("found persistent address in wallet\n");
}
portable_mutex_unlock(&myinfo->bu_mutex);
@ -808,9 +828,8 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
*badp = bad;
if ( iguana_waddresssearch(myinfo,&wacct,myinfo->myaddr.BTCD) != 0 )
{
printf("found persistent address.(%s)\n",myinfo->myaddr.BTCD);
//printf("found persistent address.(%s)\n",myinfo->myaddr.BTCD);
}
return(array);
}
@ -833,7 +852,6 @@ char *iguana_walletscan(struct supernet_info *myinfo,struct iguana_info *coin,in
void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coin)
{
// "wallet":{"test":{"R9S7zZzzvgb4CkiBH1i7gnFcwJuL1MYbxN":"18ab9c89ce83929db720cf26b663bf762532276146cd9d3e1f89086fcdf00053"}}
cJSON *payload,*item,*array,*child; char *account,coinaddr[128],*privstr,wifstr[128]; int32_t i,p2shflag,n; struct iguana_waccount *wacct; struct iguana_waddress waddr; bits256 privkey;
if ( myinfo->wallet == 0 && myinfo->decryptstr != 0 && (payload= cJSON_Parse(myinfo->decryptstr)) != 0 )
{
@ -862,14 +880,16 @@ void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coi
{
privkey = bits256_conv(child->valuestring);
if ( iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,&waddr,privkey) != 0 )
{
iguana_waddressadd(myinfo,coin,wacct,&waddr,0);
else printf("walletinitcheck: error waddresscalc\n");
printf("(%s) ",waddr.coinaddr);
} else printf("walletinitcheck: error waddresscalc\n");
}
}
}
child = child->next;
}
//printf("account.(%s)\n",account);
printf("account.(%s)\n",account);
}
item = item->next;
}
@ -879,7 +899,7 @@ void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coi
myinfo->decryptstr = 0;
myinfo->dirty = 0;
}
printf("call walletiterate from initcheck.%p\n",myinfo->decryptstr);
//printf("call walletiterate from initcheck.%p\n",myinfo->decryptstr);
iguana_walletiterate(myinfo,coin,1,0,0,0,0);
}
@ -897,10 +917,6 @@ void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin)
memset(myinfo->myaddr.NXTADDR,0,sizeof(myinfo->myaddr.NXTADDR));
myinfo->myaddr.nxt64bits = 0;
myinfo->expiration = 0;
portable_mutex_lock(&myinfo->bu_mutex);
if ( myinfo->spends != 0 )
free(myinfo->spends), myinfo->numspends = 0;
portable_mutex_unlock(&myinfo->bu_mutex);
iguana_walletiterate(myinfo,coin,-2,0,0,0,0);
}
@ -934,13 +950,31 @@ int64_t oldiguana_waccountbalance(struct supernet_info *myinfo,struct iguana_inf
cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins)
{
int32_t i,j,n,numinputs; struct iguana_waddress *waddr; struct iguana_outpoint spentpt; struct iguana_waccount *wacct; char *addresses,*address,coinaddr[64]; cJSON *privkeys = cJSON_CreateArray();
int32_t i,j,n,numinputs,scriptlen; struct iguana_waddress *waddr; struct iguana_waccount *wacct; char *addresses,*address,*scripthexstr,coinaddr[64]; cJSON *scriptobj,*privkeys,*item; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
privkeys = cJSON_CreateArray();
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
addresses = calloc(numinputs,64);
for (i=n=0; i<numinputs; i++)
{
if ( (address= iguana_RTinputaddress(myinfo,coin,coinaddr,&spentpt,jitem(vins,i))) != 0 )
address = 0;
item = jitem(vins,i);
if ( (address= jstr(item,"address")) == 0 )
{
if ( (scripthexstr= jstr(item,"spendscript")) == 0 )
{
if ( (scriptobj= jobj(item,"scriptPubkey")) != 0 )
scripthexstr = jstr(scriptobj,"hex");
}
if ( scripthexstr != 0 )
{
scriptlen = (int32_t)strlen(scripthexstr) >> 1;
decode_hex(spendscript,scriptlen,scripthexstr);
address = iguana_scriptaddress(coin,coinaddr,spendscript,scriptlen);
}
}
//if ( (address= iguana_RTinputaddress(myinfo,coin,coinaddr,&spentpt,jitem(vins,i))) != 0 )
if ( address != 0 )
{
for (j=0; j<n; j++)
{
@ -949,7 +983,7 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin
}
if ( j == n )
strcpy(&addresses[64 * n++],address);
}
} else printf("cant get address from.(%s)\n",jprint(item,0));
}
for (i=0; i<n; i++)
{
@ -967,9 +1001,9 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin
int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,cJSON *txids,cJSON *vouts,cJSON *unspents,cJSON *spends,char *coinaddr,int32_t minconf,int32_t firstheight)
{
int64_t balance = 0; cJSON *unspentsjson,*balancejson,*item; int32_t i,n; char *balancestr;
if ( (balancestr= iguana_balance(IGUANA_CALLARGS,coin->symbol,coinaddr,-1,minconf)) != 0 )
if ( (balancestr= iguana_balance(IGUANA_CALLARGS,coin->symbol,coinaddr,1<<30,minconf)) != 0 )
{
//printf("balancestr.(%s) (%s)\n",balancestr,coinaddr);
//printf("balancestr.(%s) (%s) firstheight.%d\n",balancestr,coinaddr,firstheight);
if ( (balancejson= cJSON_Parse(balancestr)) != 0 )
{
balance = jdouble(balancejson,"balance") * SATOSHIDEN;
@ -984,9 +1018,9 @@ int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *
jaddibits256(txids,jbits256(item,"txid"));
if ( vouts != 0 )
jaddinum(vouts,jint(item,"vout"));
if ( unspents != 0 && jobj(item,"unspent") != 0 )
if ( unspents != 0 && jobj(item,"spent") == 0 && jobj(item,"dest") == 0 )
jaddi(unspents,jduplicate(item));
if ( spends != 0 && jobj(item,"spent") != 0 )
if ( spends != 0 && (jobj(item,"spent") != 0 || jobj(item,"dest") != 0) )
jaddi(spends,jduplicate(item));
}
}
@ -995,6 +1029,10 @@ int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *
}
free(balancestr);
}
//if ( spends != 0 )
// printf("SPENDS.(%s)\n",jprint(spends,0));
//if ( unspents != 0 )
// printf("UNSPENTS.(%s)\n",jprint(unspents,0));
return(balance);
}
@ -1031,7 +1069,7 @@ STRING_ARG(bitcoinrpc,validateaddress,address)
strcat(str,"88ac");
jaddstr(retjson,"scriptPubKey",str);
jadd(retjson,"isscript",(addrtype == coin->chain->p2shtype) ? jtrue() : jfalse());
if ( iguana_ismine(myinfo,coin,coinaddr,addrtype,pubkey,rmd160) > 0 )
if ( iguana_ismine(myinfo,coin,coinaddr,addrtype,pubkey,rmd160) != 0 )
{
init_hexbytes_noT(str,pubkey,bitcoin_pubkeylen(pubkey));
jaddstr(retjson,"pubkey",str);
@ -1051,12 +1089,18 @@ STRING_ARG(bitcoinrpc,validateaddress,address)
return(jprint(retjson,1));
}
ZERO_ARGS(bitcoinrpc,getinfo)
double _max100(double val)
{
cJSON *retjson;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
retjson = cJSON_CreateObject();
if ( val < 0. )
return(0.);
else if ( val > 100. )
return(100.);
else return(val);
}
cJSON *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
{
int32_t i; struct iguana_peer *addr; cJSON *array,*retjson = cJSON_CreateObject();
if ( coin != 0 )
{
jaddstr(retjson,"result","success");
@ -1065,10 +1109,10 @@ ZERO_ARGS(bitcoinrpc,getinfo)
jaddnum(retjson,"txfee",dstr(coin->txfee));
if ( coin->bundlescount > 1 )
{
jaddnum(retjson,"bundles",100. * (double)(coin->chain->bundlesize *iguana_emitfinished(coin,0))/(coin->longestchain+1));
jaddnum(retjson,"utxo",100. * (double)(coin->chain->bundlesize *iguana_utxofinished(coin))/(coin->longestchain+1));
jaddnum(retjson,"balances",100. * (double)(coin->chain->bundlesize *iguana_balancefinished(coin))/(coin->longestchain+1));
jaddnum(retjson,"validated",100. * (double)(coin->chain->bundlesize *iguana_validated(coin))/(coin->longestchain+1));
jaddnum(retjson,"bundles",_max100(100. * (double)(iguana_emitfinished(myinfo,coin,0))/(coin->longestchain/coin->chain->bundlesize)));
jaddnum(retjson,"utxo",_max100(100. * (double)(iguana_utxofinished(coin))/(coin->longestchain/coin->chain->bundlesize)));
jaddnum(retjson,"balances",_max100(100. * (double)(iguana_balancefinished(coin))/(coin->longestchain/coin->chain->bundlesize)));
jaddnum(retjson,"validated",_max100(100. * (double)(iguana_validated(coin))/(coin->longestchain/coin->chain->bundlesize)));
}
jaddnum(retjson,"firstRTheight",coin->firstRTheight);
jaddnum(retjson,"RTheight",coin->RTheight);
@ -1076,12 +1120,85 @@ ZERO_ARGS(bitcoinrpc,getinfo)
jaddnum(retjson,"longestchain",coin->longestchain);
jaddnum(retjson,"port",coin->chain->portp2p);
if ( coin->peers != 0 )
{
array = cJSON_CreateArray();
for (i=0; i<IGUANA_MAXPEERS; i++)
{
addr = &coin->peers->active[i];
if ( addr->usock >= 0 && addr->supernet != 0 && addr->ipaddr[0] != 0 )
jaddistr(array,addr->ipaddr);
}
jadd(retjson,"supernet",array);
jaddnum(retjson,"connections",coin->peers->numranked);
}
jaddnum(retjson,"difficulty",coin->blocks.hwmchain.PoW);
jaddstr(retjson,"status",coin->statusstr);
jaddstr(retjson,"coin",coin->symbol);
}
return(jprint(retjson,1));
return(retjson);
}
ZERO_ARGS(bitcoinrpc,getinfo)
{
struct basilisk_item Lptr,*ptr; int32_t i,j,m,n,longest; cJSON *valsobj,*getinfoobj=0,*array,*item,*fullnodes;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
return(jprint(iguana_getinfo(myinfo,coin),1));
else
{
valsobj = cJSON_CreateObject();
ptr = basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,0,1000,valsobj);
free_json(valsobj);
if ( ptr != 0 && ptr->retstr != 0 )
{
if ( (array= cJSON_Parse(ptr->retstr)) != 0 )
{
if ( is_cJSON_Array(array) != 0 )
{
getinfoobj = jduplicate(jitem(array,0));
longest = 0;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
jdelete(getinfoobj,"longestchain");
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( juint(item,"longestchain") > longest )
longest = juint(item,"longestchain");
if ( juint(item,"RTheight") > coin->RTheight )
{
coin->RTheight = juint(item,"RTheight");
coin->firstRTheight = juint(item,"firstRTheight");
printf("set RTheight.%d 1st %d\n",coin->RTheight,coin->firstRTheight);
}
if ( (fullnodes= jarray(&m,item,"supernet")) != 0 )
{
for (j=0; j<m; j++)
{
//fprintf(stderr,"[%s] ",jstri(fullnodes,j));
iguana_launchpeer(coin,jstri(fullnodes,j),1);
}
}
}
if ( jobj(getinfoobj,"longestchain") != 0 )
jdelete(getinfoobj,"longestchain");
jaddnum(getinfoobj,"longestchain",longest);
}
}
else
{
free(ptr->retstr);
return(jprint(array,1));
}
free_json(array);
}
free(ptr->retstr);
if ( getinfoobj != 0 )
return(jprint(getinfoobj,1));
}
}
return(clonestr("{\"error\":\"null basilisk_getinfo\"}"));
}
TWO_STRINGS(bitcoinrpc,setaccount,address,account)
@ -1123,13 +1240,32 @@ STRING_ARG(bitcoinrpc,getnewaddress,account)
struct iguana_waddress *iguana_getaccountaddress(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,char *coinaddr,char *account)
{
char *newstr,*retstr; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0;
char *newstr,*retstr; int32_t i,n,flag=0; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0; cJSON *unspents,*item;
coinaddr[0] = 0;
if ( (wacct= iguana_waccountfind(myinfo,account)) == 0 )
wacct = iguana_waccountcreate(myinfo,account);
if ( wacct != 0 )
{
if ( (waddr= wacct->current) == 0 || waddr->numunspents > 0 )
portable_mutex_lock(&myinfo->bu_mutex);
if ( myinfo->Cunspents != 0 && (unspents= jobj(myinfo->Cunspents,coin->symbol)) != 0 )
{
flag = 0;
if ( (n= cJSON_GetArraySize(unspents)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(unspents,i);
if ( jstr(item,"address") != 0 && strcmp(jstr(item,"address"),coinaddr) == 0 )
{
flag = 1;
printf("found unspent for.(%s)\n",coinaddr);
break;
}
}
}
}
portable_mutex_unlock(&myinfo->bu_mutex);
if ( flag != 0 || (waddr= wacct->current) == 0 )
{
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password)) != 0 )
{
@ -1185,8 +1321,12 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
return(clonestr("{\"error\":\"no remote\"}"));
if ( timeout <= 0 )
return(clonestr("{\"error\":\"timeout must be positive\"}"));
if ( password == 0 || password[0] == 0 )
{
if ( (password= jstr(json,"passphrase")) == 0 || password[0] == 0 )
return(clonestr("{\"error\":\"must have password field\"}"));
}
iguana_walletlock(myinfo,coin);
printf("timeout.%d\n",timeout);
myinfo->expiration = (uint32_t)time(NULL) + timeout;
strcpy(myinfo->secret,password);
strcpy(myinfo->password,password);
@ -1214,7 +1354,7 @@ THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile)
if ( permanentfile != 0 )
strcpy(myinfo->permanentfile,permanentfile);
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password);
myinfo->expiration = (uint32_t)time(NULL) + 3600*24;
//myinfo->expiration = (uint32_t)time(NULL) + 3600*24;
struct iguana_waddress waddr; struct iguana_waccount *wacct;
if ( (wacct= iguana_waccountcreate(myinfo,"default")) != 0 )
{
@ -1222,8 +1362,9 @@ THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile)
iguana_waddressadd(myinfo,coin,wacct,&waddr,0);
else printf("couldnt waddresscalc persistent\n");
} else printf("coildnt create default account\n");
iguana_walletinitcheck(myinfo,coin);
//iguana_walletinitcheck(myinfo,coin);
myinfo->dirty = (uint32_t)time(NULL);
myinfo->expiration = 0;
return(retstr);
}
@ -1288,28 +1429,32 @@ TWOSTRINGS_AND_INT(bitcoinrpc,importprivkey,wif,account,rescan)
}
}
privkey = iguana_str2priv(myinfo,coin,wif);
//char str2[65]; printf("wif.%s -> %s\n",wif,bits256_str(str2,privkey));
if ( bits256_nonz(privkey) == 0 )
return(clonestr("{\"error\":\"illegal privkey\"}"));
memset(&addr,0,sizeof(addr));
if ( iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,&addr,privkey) != 0 )
{
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,addr.coinaddr)) != 0 )
{
waddr = iguana_waccountswitch(myinfo,coin,account,addr.coinaddr,0);
//waddr = iguana_waccountswitch(myinfo,coin,account,addr.coinaddr,0);
waddr->privkey = privkey;
myinfo->dirty = 0;
return(clonestr("{\"result\":\"privkey already in wallet\"}"));
}
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
} else waddr = &addr;
myinfo->expiration++;
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password)) != 0 )
{
free(retstr);
retstr = myinfo->decryptstr, myinfo->decryptstr = 0;
if ( waddr == 0 )
waddr = &addr;
//printf("DECRYPT.(%s)\n",retstr);
iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,waddr,privkey);
iguana_waccountswitch(myinfo,coin,account,waddr->coinaddr,0);
waddr->privkey = privkey;
retjson = iguana_walletadd(myinfo,0,coin,retstr,account,waddr,0,0);
//printf("AFTERADD.(%s)\n",jprint(retjson,0));
if ( retstr != 0 )
scrubfree(retstr);
return(jprint(retjson,1));

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save