Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
8165889ffb
  1. 3
      crypto777/OS_portable.h
  2. 25
      crypto777/iguana_OS.c
  3. 6
      crypto777/iguana_utils.c
  4. 4
      iguana/SuperNET.c
  5. 3
      iguana/btcd
  6. 20
      iguana/confs/BTCD_hdrs.h
  7. 14
      iguana/exchanges/bitcoin.c
  8. 99
      iguana/iguana777.c
  9. 25
      iguana/iguana777.h
  10. 40
      iguana/iguana_blocks.c
  11. 87
      iguana/iguana_bundles.c
  12. 1
      iguana/iguana_chains.c
  13. 15
      iguana/iguana_init.c
  14. 6
      iguana/iguana_json.c
  15. 2
      iguana/iguana_msg.c
  16. 24
      iguana/iguana_peers.c
  17. 105
      iguana/iguana_ramchain.c
  18. 15
      iguana/iguana_recv.c
  19. 13
      iguana/iguana_rpc.c
  20. 175
      iguana/iguana_tx.c
  21. 87
      iguana/iguana_unspents.c
  22. 313
      iguana/main.c
  23. 97
      iguana/ramchain_api.c
  24. 4
      includes/iguana_apideclares.h

3
crypto777/OS_portable.h

@ -183,6 +183,7 @@ double OS_portable_milliseconds();
void OS_portable_randombytes(unsigned char *x,long xlen);
int32_t OS_portable_truncate(char *fname,long filesize);
char *OS_portable_path(char *str);
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);
@ -206,7 +207,7 @@ 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);
uint64_t OS_filesize(char *fname);
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);

25
crypto777/iguana_OS.c

@ -520,6 +520,29 @@ int32_t OS_removefile(char *fname,int32_t scrubflag)
return(0);
}
void OS_remove_directory(char *dirname)
{
FILE *fp; char buf[1024];
sprintf(buf,"%s/.tmpmarker",dirname);
if ( (fp= fopen(OS_compatible_path(buf),"rb")) != 0 )
OS_removefile(buf,0);
else fclose(fp);
sprintf(buf,"rmdir %s",dirname);
if ( system(buf) != 0 )
{
printf("error doing (%s)\n",buf);
sprintf(buf,"rm %s/*",dirname);
if ( system(buf) != 0 )
printf("error doing (%s)\n",buf);
else
{
sprintf(buf,"rmdir %s",dirname);
if ( system(buf) != 0 )
printf("second error doing (%s)\n",buf);
}
}
}
void OS_ensure_directory(char *dirname)
{
FILE *fp; int32_t retval; char fname[512];
@ -546,7 +569,7 @@ void OS_ensure_directory(char *dirname)
} else fclose(fp);//, printf("%s exists\n",fname);
}
uint64_t OS_filesize(char *fname)
int64_t OS_filesize(char *fname)
{
FILE *fp; uint64_t fsize = 0;
if ( (fp= fopen(fname,"rb")) != 0 )

6
crypto777/iguana_utils.c

@ -190,7 +190,7 @@ double dxblend(double *destp,double val,double decay)
return(slope);
}
queue_t TerminateQ; int32_t TerminateQ_queued;
int32_t TerminateQ_queued;
/*void iguana_terminator(void *arg)
{
struct iguana_thread *t; uint32_t lastdisp = 0; int32_t terminated = 0;
@ -233,7 +233,7 @@ void iguana_launcher(void *ptr)
queue_enqueue("TerminateQ",&TerminateQ,&t->DL,0);
}
void iguana_terminate(struct iguana_info *coin,struct iguana_thread *t)
void iguana_terminate(struct iguana_thread *t)
{
int32_t retval;
retval = pthread_join(t->handle,NULL);
@ -260,7 +260,7 @@ struct iguana_thread *iguana_launch(struct iguana_info *coin,char *name,iguana_f
{
if ( (rand() % 100000) == 0 && coin != 0 )
printf("terminated.%d launched.%d terminate.%p\n",coin->Terminated[t->type],coin->Launched[t->type],t);
iguana_terminate(coin,t);
iguana_terminate(t);
}
return(t);
}

4
iguana/SuperNET.c

@ -675,10 +675,10 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,ui
OS_randombytes((uint8_t *)&tag,sizeof(tag));
jadd64bits(json,"tag",tag);
}
printf("SuperNET_JSON.(%s) remote.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:"");
//printf("SuperNET_JSON.(%s) remote.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:"");
destflag = SuperNET_destination(myinfo,&destipbits,&category,&subhash,&maxdelay,json,remoteaddr);
//printf("destflag.%d\n",destflag);
if ( (hexmsg= jstr(json,"hexmsg")) == 0 && (message= jstr(json,"message")) == 0 )
if ( (hexmsg= jstr(json,"hexmsg")) == 0 && strcmp(method,"bitcoinrpc") != 0 && (message= jstr(json,"message")) == 0 )
{
jsonstr = jprint(json,0);
hexlen = (int32_t)strlen(jsonstr);

3
iguana/btcd

@ -1,4 +1,5 @@
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":100,\"VALIDATE\":1,\"validatedir\":\"/tmp\",\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":64,\"tmpdir\":\"/mnt/ramdisk\"}"
mkdir /tmp/BTCD
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":100,\"VALIDATE\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":614,\"endpend\":614,\"services\":129,\"maxpeers\":64}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"pausecoin\",\"coin\":\"BTC\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"coin\":\"BTCD\",\"ipaddr\":\"89.248.160.241\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"coin\":\"BTCD\",\"ipaddr\":\"89.248.160.244\"}"

20
iguana/confs/BTCD_hdrs.h

@ -2085,4 +2085,24 @@ char *BTCD_hdrs[][4] = {
{ "1041500", "fba66082cac0bd85aa39fe56c7e3f25b58098dcdf71ad064bc1293c6a5be326f", "9365e5fd1c055bf56fc73a599ccb8ad2d71c6c889da5d53a15ce287c9907efff", "130f197d253f4486061c8b344933d4e6b9888af946ebfe5bdfa0d66be7afaa75"},
{ "1042000", "f960f144c580e372fbb20aebc7c7693e1647dde35631165f03ceca0402fd5394", "f309ff65eddf5e85b4ea098a6d47a0cbcfcd553aca7e5092af04df2660216ecb", "d7fcea9da8cc94742d3a5e0b39100433fe0ace25f448153aa6fbe9af7aab2f21"},
{ "1042500", "bc1c318eb954e6ffd656b40aa2034aaa57510a47c70a26d4a64798b4242a96c3", "f49366d3c65adf67d855e79a8b5f321bd43e969beaf8da624aaa444153e34804", "1e1cab22f6b5519ae4265e0283f1079b2f209ce8c5288e9d2a247084e46a41ae"},
{ "1043000", "8e675a672f934f13443b463b09308f9857256bc5535c144411f5af2df9cc7ed1", "320a8ccb3a1d44f07f16bf989a3348b980b2502e9dadbc1f7467779384e49ddc", "e2fb1c4a95ba177748c3732b0420eab1881b51fe2874b73e589cc7a08d565065"},
{ "1043500", "cc6046ba969972c5af0389612e75d8b289c113b4900681a7b26a19ec120f95e8", "635b5848a1345f1cfe64bdd7d463d9cd09f9d075bfb2d04cfa805ece973dcdd3", "172d5cfd06424e6ecc06b0eaa4b441d4257c20ac8826f65b6cf20a2c57377b11"},
{ "1044000", "df415157f07298c695d76b1ef2bd2ba6c6459dda30b6aac026a8492240163319", "1430ac6d0d2753b35eed3cbc8885cebe65214a9179480748ae5c3857bcaa72fe", "2d4b8f1a666c3f94f22ba93d18eca27b596ca5e66cdc3e7385c68fa151feffd5"},
{ "1044500", "dcd1e4bf92385427fb83f6430ada423739f5e79b50d9d54d2da7682349099d4d", "a565daeed39c5a0623391382793c6436a274f39b859797088521d7ae5df1b7ce", "513aae8157476d212e99a19ca1c8e88008358b43434156e37053e69100e127bb"},
{ "1045000", "579743f2d5aa7780e4db1b3015190a235ba6d5f4e5ebae8d00142032a3db5ce3", "310cd0259443ed2aad00773a3fe718fe05e30fa6a79be5d48600bd0dff0ea09f", "b7ecada86be2ad137b8e1f896dc2673f40b1e834e09351d6d40de96f32494ebb"},
{ "1045500", "8a9aa0f90288d2ef021cd7bc0ff79e851b3027305f2ef6c90bcb67be1d2ca664", "01bc88af745ea0e33c5cf5d22cf1d6ca2cfba216e43b16fe090d7806b67da16d", "340015f88c93cf427fe0ecac9385c31f6be182d4f06007091144e44ac05624ae"},
{ "1046000", "c72ccab7669a1c77adb96eac880c3b8b5505f76f54875c9ce63e5ec0a4466e52", "c5f2bf64430c0a2cf5b0ebee135d44a84b63dc5161e5b6e3bf22994c6a2448bd", "1f87c9f3afa87d527a897813ed828532601560b0b67e75e1fd040af0df8c7b18"},
{ "1046500", "3573934e82012b7ba458286dc61fc094ebaea2e6a44b6f75c628c223610200e3", "0d902f09a9ca3b972e3820f74d83df311ba5b35e8c6fa1229ff8da974aec6e63", "f360249b4cdd69f59573d023c5faf8b0fc1e6a0f5f9967b96ac34659ee72ffef"},
{ "1047000", "9380a4a18403d26d8ed097c1ee3c8d9deb40423a40c75ab5990088c7e5c6be5c", "175b7c5aa160a7cc32bb88a1623cf5c740cd1963c2d52c2e108005e2c895a4b8", "dfe7420133a6092210dfecaa74b30f29f0c980f74fd6205c0ad325b69d5cfe94"},
{ "1047500", "b3eb44a8d8c32ff51230776ef692ae2df253ea590e3ce094021965a48b923a9c", "770af1fc30b4a95ac9afc82aef5959f9425d91fc27dea24aedc5f1d1bbbaae6d", "6f6dac8855fac467d526bf3b7fae68e33a594acffb42301e8cfbc7fe6838163d"},
{ "1048000", "47a84fcee4a633f734f7197155fab73b0d6066752fee07ba18a3f1b2d2aff2bf", "ad93d2d3692df1b72ab9a4a0a306962127780d114e8ba39a8e102568906b61df", "adaf5605fc79d9153a915d37541d51b61fb849c9f0bbcba5164bcc1e930c9aa6"},
{ "1048500", "d80b9eef45c8bcdcfe112f4f398aa4141888fb4bf69794b419757256f7b9bfb0", "c252f3198f625fe91d91dc5e3032446956d8de987b00d5d3ba008c3e092f6763", "8518048f6083c29fb1e001fbe778ed185b87a988dcbe0c61cfa868365939b562"},
{ "1049000", "be562935777742d22230f2b13f1d885fcd3f3966af8baaf182673075aede0a9a", "7a8940e33f897394ee39c5f9edf0b04d71f28a3e07a65011496024b64a91a70b", "a90c364c7302fafc86ce15d51b08167f9232c44e2a7744a7a674508a146bf7e2"},
{ "1049500", "450bc6a5f1b7d502c9a86ecb08ed3bf26c87149f6b6242deebf998ec1190dacb", "e496811cc6cab5c2b821d21ba29b71ca4256b228889e352e779a82aeea96df63", "64fd7f1d78833ec1260e9b39249e9957207845d99bab950ef921a3a5fafdda46"},
{ "1050000", "a835e80973ca0240c06703a30433a139d200453a7296c24a22b62792d17ff2a1", "44c9a74b2ad97727ae4f419a77804a88f9a3cb31bb3ae65e2b372040c1eb273e", "95c578d836ef48bd93f58757d6c3b093acaa373f9654410f85dae1aefdd5d3fc"},
{ "1050500", "631b74a56a6719158926aca09aa8ab8cd89b61e563a5b6386ec6de5e782e926a", "1e1c4fc04badc617cc382d6aadde8ae735277694e233a225634e2be077c97a2a", "fd4f6efdea193b035f4b5947404483b6930997bf8089d1661d9b9ef48c9887aa"},
{ "1051000", "1ec8fcfb9b6d6c602e2775686f04f1d39a768064ee6aeb65930bfee5b1a94e19", "4f2f38f9f74bfd1ea8daf0ac5ffa8afb485436d5e4b35fd0742c454439b21488", "f6311a3834e71c30635c01e0c45aacfcb2241780e3aa13f2c834a84f5afda969"},
{ "1051500", "73133e5c1408263f8053ed9a93ae7164dffc2381d3a7fa24cc78c29665b3bf39", "a47a6e2a98fef063017953ee09b4471622b986b7fe8dc6d52adda451db9c852e", "fb14519af510b672ace64d3d250549fad14d1ed623dd0544bc541b7e3710e38b"},
{ "1052000", "20e08cce79f51cc9e5b0dd212f6cc3a0ad742244e58ce252600d286fe2415cc3", "edcb3b3a1aff133bac74770612727bf2f15cfafab7c63dfbfe6f2378debda004", "d47a434a2ba0524ee99b5664f66792b81fc9134f5ceb00e69efdf9a46f8142f4"},
{ "1052500", "37e19650eba3eb3e2967c2585147cc37714d24ac681a8b78d11f946ceca3c083", "", ""},
};

14
iguana/exchanges/bitcoin.c

@ -165,10 +165,10 @@ int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr
}
else
{
int32_t i; char hexaddr[64];
char hexaddr[64];
btc_convaddr(hexaddr,coinaddr);
for (i=0; i<len; i++)
printf("%02x ",buf[i]);
//for (i=0; i<len; i++)
// printf("%02x ",buf[i]);
char str[65]; printf("\nhex.(%s) checkhash.(%s) len.%d mismatch %02x %02x %02x %02x vs %02x %02x %02x %02x (%s)\n",hexaddr,coinaddr,len,buf[len - 4]&0xff,buf[len - 3]&0xff,buf[len - 2]&0xff,buf[len - 1]&0xff,hash.bytes[31],hash.bytes[30],hash.bytes[29],hash.bytes[28],bits256_str(str,hash));
}
}
@ -1066,6 +1066,14 @@ cJSON *iguana_signtx(struct iguana_info *coin,bits256 *txidp,char **signedtxp,st
return(txobj);
}
int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin)
{
// multiple coins
// ro -> vouts collision, purgeable
//
return(0);
}
#ifdef testing
char *bitcoin_cltvtx(struct iguana_info *coin,char *changeaddr,char *senderaddr,char *senders_otheraddr,char *otheraddr,uint32_t locktime,uint64_t satoshis,bits256 txid,int32_t vout,uint64_t inputsatoshis,bits256 privkey)
{

99
iguana/iguana777.c

@ -53,7 +53,7 @@ struct iguana_info *iguana_coinadd(const char *symbol,cJSON *argjson)
{
if ( i >= sizeof(Hardcoded_coins)/sizeof(*Hardcoded_coins) )
break;
printf("Hardcoded_coins[i][0] %s vs.(%s)\n",Hardcoded_coins[i][0],symbol);
//printf("Hardcoded_coins[i][0] %s vs.(%s)\n",Hardcoded_coins[i][0],symbol);
//if ( symbol[0] == 0 )
// getchar();
if ( strcmp("endmarker",Hardcoded_coins[i][0]) == 0 || strcmp(symbol,Hardcoded_coins[i][0]) == 0 )
@ -74,7 +74,6 @@ struct iguana_info *iguana_coinadd(const char *symbol,cJSON *argjson)
coin->chain = iguana_chainfind((char *)symbol,argjson,1);
strcpy(coin->symbol,symbol);
iguana_initcoin(coin,argjson);
printf("coin.%s initialized\n",symbol);
}
return(coin);
}
@ -264,6 +263,8 @@ void iguana_emitQ(struct iguana_info *coin,struct iguana_bundle *bp)
void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit)
{
struct iguana_helper *ptr;
if ( bp->queued == 0 && bp->emitfinish <= 1 && iguana_bundleready(coin,bp,0) == bp->n )
printf("bundle.[%d] is ready\n",bp->hdrsi);
bp->queued = (uint32_t)time(NULL);
ptr = mycalloc('i',1,sizeof(*ptr));
ptr->allocsize = sizeof(*ptr);
@ -281,7 +282,7 @@ void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t ti
void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp)
{
struct iguana_helper *ptr;
if ( bp->validated == 0 )
if ( bp->validated <= 1 )
{
ptr = mycalloc('i',1,sizeof(*ptr));
ptr->allocsize = sizeof(*ptr);
@ -296,13 +297,18 @@ void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp)
}
}
int32_t iguana_emitfinished(struct iguana_info *coin)
int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete)
{
struct iguana_bundle *bp; int32_t i,n = 0;
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish > 1 )
n++;
if ( (bp= coin->bundles[i]) != 0 )
{
if ( bp->emitfinish > 1 )
n++;
else if ( bp->emitfinish == 0 && bp->queued == 0 )
iguana_bundleQ(coin,bp,1000);
}
}
return(n);
}
@ -340,6 +346,17 @@ int32_t iguana_balancefinished(struct iguana_info *coin)
return(n);
}
int32_t iguana_validated(struct iguana_info *coin)
{
struct iguana_bundle *bp; int32_t i,n = 0;
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) != 0 && bp->validated > 1 )
n++;
}
return(n);
}
int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convertflag)
{
int32_t hdrsi,retval,n,max,incr,num = 0; struct iguana_bundle *bp;
@ -394,15 +411,23 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
}
if ( convertflag != 0 || iguana_spendvectorsaves(coin) == 0 )
{
for (hdrsi=0; hdrsi<max; hdrsi++)
iguana_validateQ(coin,coin->bundles[hdrsi]);
if ( coin->origbalanceswritten <= 1 )
hdrsi = 0;
else hdrsi = coin->origbalanceswritten;
while ( (n= iguana_validated(coin)) < max )
{
sleep(3);
printf("validated.%d of %d\n",n,max);
}
for (; hdrsi<max; hdrsi++,coin->balanceswritten++)
iguana_balancegen(coin,0,coin->bundles[hdrsi],0,coin->chain->bundlesize-1);
if ( iguana_balanceflush(coin,max) > 0 )
printf("balanceswritten.%d flushed bp->hdrsi %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,bp->hdrsi,coin->longestchain/coin->chain->bundlesize);
} else printf("error saving spendvectors\n");
coin->spendvectorsaved = (uint32_t)time(NULL);
printf("UTXOGEN spendvectorsaved <- %u\n",coin->spendvectorsaved);
}
while ( coin->spendvectorsaved == 1 )
{
@ -416,7 +441,7 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
void iguana_helper(void *arg)
{
cJSON *argjson=0; int32_t iter,i,n,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0;
struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp;
struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; uint32_t starttime;
if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 )
helperid = juint(argjson,"helperid");
if ( IGUANA_NUMHELPERS < 2 )
@ -475,21 +500,28 @@ void iguana_helper(void *arg)
} else break;
}
}
/*if ( (type & (1 << 1)) != 0 )
//if ( (type & (1 << 1)) != 0 )
starttime = (uint32_t)time(NULL);
while ( time(NULL) < starttime+10 && (ptr= queue_dequeue(&validateQ,0)) != 0 )
{
n = queue_size(&validateQ);
for (iter=0; iter<n; iter++)
if ( (ptr= queue_dequeue(&validateQ,0)) != 0 )
if ( (bp= ptr->bp) != 0 && (coin= ptr->coin) != 0 && coin->active != 0 )
{
//printf("validate.[%d] %d vs %d\n",bp->hdrsi,coin->blocks.hwmchain.height/coin->chain->bundlesize,(coin->longestchain-1)/coin->chain->bundlesize);
if ( coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-1)/coin->chain->bundlesize )
flag += iguana_bundlevalidate(coin,bp,0);
else
{
if ( ptr->bp != 0 && (coin= ptr->coin) != 0 && coin->active != 0 )
flag += iguana_bundlevalidate(ptr->coin,ptr->bp);
else if ( coin->active != 0 )
printf("helper validate missing param? %p %p\n",ptr->coin,ptr->bp);
myfree(ptr,ptr->allocsize);
flag++;
usleep(10000);
iguana_validateQ(coin,bp);
continue;
}
}*/
if ( queue_size(&bundlesQ) > 1 )
}
else if ( coin->active != 0 )
printf("helper validate missing param? %p %p\n",ptr->coin,ptr->bp);
myfree(ptr,ptr->allocsize);
flag++;
}
if ( queue_size(&bundlesQ) > 1 || queue_size(&validateQ) > 0 )
allcurrent = 0;
if ( flag != 0 )
usleep(polltimeout * 100 + 1);
@ -513,8 +545,6 @@ void iguana_coinloop(void *arg)
coin = coins[0];
iguana_launchpeer(coin,"127.0.0.1");
memset(zero.bytes,0,sizeof(zero));
if ( (bp= iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1)) != 0 )
bp->bundleheight = 0;
while ( 1 )
{
flag = 0;
@ -540,6 +570,21 @@ void iguana_coinloop(void *arg)
coin->chain->minconfirms = coin->minconfirms;
coin->started = coin;
coin->startutc = (uint32_t)time(NULL);
if ( (bp= iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1)) != 0 )
bp->bundleheight = 0;
#ifdef __PNACL__
if ( strcmp(coin->symbol,"BTCD") == 0 )
{
int32_t j;
char *ipaddrs[] = { "5.9.102.210", "89.248.160.236", "89.248.160.237", "89.248.160.238", "89.248.160.239", "89.248.160.240", "89.248.160.241", "89.248.160.242", "89.248.160.243", "89.248.160.244", "89.248.160.245", "78.47.58.62" };
for (j=0; j<sizeof(ipaddrs)/sizeof(*ipaddrs); j++)
{
printf("%s ",ipaddrs[j]);
iguana_launchpeer(coin,ipaddrs[j]);
}
printf("possible peers\n");
}
#endif
}
now = (uint32_t)time(NULL);
coin->idletime = 0;
@ -614,7 +659,6 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
struct iguana_chain *iguana_createchain(cJSON *json);
struct iguana_info *coin; int32_t j,m,mult,maxval,mapflags; char dirname[512]; cJSON *peers;
mapflags = IGUANA_MAPRECVDATA | maphash*IGUANA_MAPTXIDITEMS | maphash*IGUANA_MAPPKITEMS | maphash*IGUANA_MAPBLOCKITEMS | maphash*IGUANA_MAPPEERITEMS;
printf("setcoin.%s\n",symbol);
coin = iguana_coinadd(symbol,json);
coin->launched = launched;
if ( (coin->MAXPEERS= maxpeers) <= 0 )
@ -626,7 +670,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
coin->myservices = services;
coin->initialheight = initialheight;
coin->mapflags = mapflags;
mult = (strcmp("BTC",coin->symbol) != 0) ? 32 : 1;
mult = (strcmp("BTC",coin->symbol) != 0) ? 4 : 1;
maxval = (strcmp("BTC",coin->symbol) != 0) ? IGUANA_MAXPENDBUNDLES : IGUANA_MAXPENDBUNDLES;
coin->MAXMEM = juint(json,"RAM");
if ( jobj(json,"prefetchlag") != 0 )
@ -667,6 +711,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
sprintf(dirname,"DB/ro/%s",symbol), OS_ensure_directory(dirname);
sprintf(dirname,"DB/ro"), OS_ensure_directory(dirname);
sprintf(dirname,"DB/%s",symbol), OS_ensure_directory(dirname);
sprintf(dirname,"DB/%s/validated",symbol), OS_ensure_directory(dirname);
sprintf(dirname,"DB/%s/accounts",symbol), OS_ensure_directory(dirname);
sprintf(dirname,"DB/%s/spends",symbol), OS_ensure_directory(dirname);
sprintf(dirname,"DB/%s/vouts",symbol), OS_ensure_directory(dirname);
@ -677,8 +722,12 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
printf("cant initialize chain.(%s)\n",jstr(json,0));
return(0);
} else iguana_chainparms(coin->chain,json);
coin->RELAYNODE = juint(json,"RELAY");
coin->VALIDATENODE = juint(json,"VALIDATE");
if ( jobj(json,"RELAY") != 0 )
coin->RELAYNODE = juint(json,"RELAY");
else coin->RELAYNODE = 1;
if ( jobj(json,"VALIDATE") != 0 )
coin->VALIDATENODE = juint(json,"VALIDATE");
else coin->VALIDATENODE = 1;
if ( jobj(json,"validatedir") != 0 )
safecopy(coin->VALIDATEDIR,jstr(json,"validatedir"),sizeof(coin->VALIDATEDIR));
else strcpy(coin->VALIDATEDIR,"purgeable");

25
iguana/iguana777.h

@ -44,8 +44,8 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t
#define IGUANA_MAXPENDHDRS 1
#define IGUANA_MAXPENDINGREQUESTS 3
#define IGUANA_PENDINGREQUESTS 256
#define IGUANA_MINPENDBUNDLES 2
#define IGUANA_MAXPENDBUNDLES 64
#define IGUANA_MINPENDBUNDLES 4
#define IGUANA_MAXPENDBUNDLES 16
#define IGUANA_RPCPORT 7778
#define IGUANA_MAXRAMCHAINSIZE ((uint64_t)1024L * 1024L * 1024L * 16)
@ -297,8 +297,6 @@ struct iguana_block
#define IGUANA_LHASH_UNSPENTS 2 //
#define IGUANA_LHASH_SPENDS 3 //
#define IGUANA_LHASH_PKHASHES 4 //
//#define IGUANA_LHASH_SPENTINDS 5
//#define IGUANA_LHASH_FIRSTSPENDS 5 //
#define IGUANA_LHASH_ACCOUNTS 5 //
#define IGUANA_LHASH_EXTERNALS 6 //
#define IGUANA_LHASH_KSPACE 7 //
@ -367,7 +365,7 @@ struct iguana_txblock
struct iguana_ramchaindata
{
bits256 sha256;
bits256 lhashes[IGUANA_NUMLHASHES],firsthash2,lasthash2;
bits256 lhashes[IGUANA_NUMLHASHES],firsthash2,prevhash2;
int64_t allocsize,Boffset,Toffset,Uoffset,Soffset,Poffset,Aoffset,Xoffset,TXoffset,PKoffset,Koffset;
int32_t numblocks,height,firsti,hdrsi,txsparsebits,pksparsebits;
uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,numtxsparse,numpksparse,scriptspace,stackspace;
@ -391,7 +389,7 @@ struct iguana_ramchain
char from_ro,from_roX,from_roA,from_roU;
struct iguana_account *A,*creditsA; struct iguana_spendvector *Xspendinds;
struct iguana_utxo *Uextras; uint8_t *txbits;
int16_t permutation[IGUANA_MAXBUNDLES];
//int16_t permutation[IGUANA_MAXBUNDLES];
//struct iguana_Uextra *U2,*roU2; struct iguana_pkextra *P2,*roP2;
};
@ -555,7 +553,8 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc
int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,char *hashstr);
int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n);
void iguana_blockunconv(struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count);
int32_t iguana_peerblockrequest(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2);
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_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin);
// ramchain
int64_t iguana_verifyaccount(struct iguana_info *coin,struct iguana_account *acct,uint32_t pkind);
@ -714,7 +713,7 @@ struct iguana_agent
};
int32_t iguana_txbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts);
void iguana_vinset(struct iguana_info *coin,int32_t height,struct iguana_msgvin *vin,struct iguana_txid *tx,int32_t i);
int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t height,struct iguana_msgvin *vin,struct iguana_txid *tx,int32_t i);
int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmstr,int32_t height,struct iguana_msgvout *vout,struct iguana_txid *tx,int32_t i);
//int32_t btc_convrmd160(char *coinaddr,uint8_t addrtype,uint8_t rmd160[20]);
struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_txid *tx,int32_t txidind);
@ -776,7 +775,7 @@ void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sle
int32_t iguana_rwvout(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvout *msg);
int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg);
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr);
int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts);
int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs);
cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid);
cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag);
//int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bits256 privkey);
@ -810,7 +809,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp);
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,int32_t starti,int32_t numblocks,int32_t convertflag);
int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight);
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp);
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag);
void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp);
struct iguana_bloominds iguana_calcbloom(bits256 hash2);
int32_t iguana_bloomfind(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit);
@ -865,7 +864,7 @@ struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight)
int32_t iguana_balancenormal(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight);
int32_t iguana_spendvectorsaves(struct iguana_info *coin);
int32_t iguana_convertfinished(struct iguana_info *coin);
int32_t iguana_emitfinished(struct iguana_info *coin);
int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete);
int32_t iguana_utxofinished(struct iguana_info *coin);
int32_t iguana_balancefinished(struct iguana_info *coin);
int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramchain);
@ -875,6 +874,10 @@ int32_t iguana_peerhdrrequest(struct iguana_info *coin,struct iguana_peer *addr,
int32_t iguana_peerinvdata(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max);
int32_t iguana_bundlefname(struct iguana_info *coin,struct iguana_bundle *bp,char *fname);
int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi);
int32_t iguana_voutsfname(struct iguana_info *coin,char *fname,int32_t slotid);
int32_t iguana_vinsfname(struct iguana_info *coin,char *fname,int32_t slotid);
bits256 iguana_merkle(struct iguana_info *coin,bits256 *tree,int32_t txn_count);
int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag);
extern int32_t HDRnet,netBLOCKS;

40
iguana/iguana_blocks.c

@ -15,6 +15,29 @@
#include "iguana777.h"
bits256 iguana_merkle(struct iguana_info *coin,bits256 *tree,int32_t txn_count)
{
int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2];
if ( txn_count == 1 )
return(tree[0]);
prev = 0;
while ( txn_count > 1 )
{
if ( (txn_count & 1) != 0 )
tree[prev + txn_count] = tree[prev + txn_count-1], txn_count++;
n += txn_count;
for (i=0; i<txn_count; i+=2)
{
iguana_rwbignum(1,serialized,sizeof(*tree),tree[prev + i].bytes);
iguana_rwbignum(1,&serialized[sizeof(*tree)],sizeof(*tree),tree[prev + i + 1].bytes);
tree[n + (i >> 1)] = bits256_doublesha256(0,serialized,sizeof(serialized));
}
prev = n;
txn_count >>= 1;
}
return(tree[n]);
}
#define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0)
void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct iguana_block *block)
@ -360,10 +383,10 @@ struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight)
{
hdrsi = (height / coin->chain->bundlesize);
bundlei = (height % coin->chain->bundlesize);
#ifndef __PNACL__
/*#ifndef __PNACL__
if ( (height % 10000) == 0 )
fprintf(stderr,".");
#endif
#endif*/
if ( (bp= coin->bundles[hdrsi]) == 0 )
{
printf("iguana_fastlink null bundle.[%d]\n",hdrsi);
@ -375,6 +398,11 @@ struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight)
printf("iguana_fastlink null block.[%d:%d]\n",hdrsi,bundlei);
break;
}
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);
}
bp->blocks[bundlei] = block;
coin->blocks.maxblocks = (block->height + 1);
if ( coin->blocks.maxblocks > coin->longestchain )
@ -387,11 +415,11 @@ struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight)
block->hh.prev = prev;
if ( prev != 0 )
prev->hh.next = block;
iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2);
iguana_hash2set(coin,"fastlink",bp,bundlei,block->RO.hash2);
//iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2);
prev = block;
prevPoW = block->PoW;
}
iguana_walkchain(coin,0);
return(block);
}
@ -500,8 +528,12 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
{
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]));
iguana_bundlepurgefiles(coin,bp);
iguana_bundleremove(coin,bp->hdrsi);
exit(-1);
//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);
}
if ( coin->started != 0 && (block->height % coin->chain->bundlesize) == coin->minconfirms )//&& (block->height > coin->longestchain-coin->chain->bundlesize*2 || ((block->height / coin->chain->bundlesize) % 10) == 9) )

87
iguana/iguana_bundles.c

@ -207,7 +207,8 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo
{
if ( bp->blocks[bundlei] != 0 && bp->blocks[bundlei] != block )
{
printf("bp->blocks[%d] mismatch %p != %p\n",bundlei,bp->blocks[bundlei],block);
printf("bp.[%d]->blocks[%d] mismatch %p != %p\n",bp->hdrsi,bundlei,bp->blocks[bundlei],block);
iguana_blockunmark(coin,block,bp,bundlei,1);
bp->blocks[bundlei] = 0;
return(-1);
}
@ -236,7 +237,14 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo
{
if ( (block->hdrsi != bp->hdrsi || block->bundlei != bundlei) && (block->hdrsi != 0 || block->bundlei != 0) )
{
char str[65]; printf("blockadd warning: %d[%d] <- %d[%d] %s\n",block->hdrsi,block->bundlei,bp->hdrsi,bundlei,bits256_str(str,hash2));
char str[65]; printf("blockadd warning: %d[%d] main.%d <- %d[%d] %s\n",block->hdrsi,block->bundlei,block->mainchain,bp->hdrsi,bundlei,bits256_str(str,hash2));
if ( block->mainchain != 0 )
{
memset(bp->hashes[bundlei].bytes,0,sizeof(bp->hashes[bundlei]));
if ( bp->speculative != 0 )
bp->speculative[bundlei] = bp->hashes[bundlei];
bp->blocks[bundlei] = 0;
}
err |= 2;
return(-1);
//exit(-1);
@ -405,7 +413,7 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl
void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
{
static const bits256 zero;
char fname[1024]; FILE *fp; int32_t hdrsi,m,j; uint32_t ipbits;
char fname[1024],dirname[1024]; FILE *fp; int32_t hdrsi,m,j; uint32_t ipbits;
if ( bp->purgetime == 0 && time(NULL) > bp->emitfinish+30 )
{
//printf("purged hdrsi.[%d] lag.%ld\n",bp->hdrsi,time(NULL) - bp->emitfinish);
@ -426,6 +434,8 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
else printf("error removing.(%s)\n",fname);
}
}
sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight);
OS_remove_directory(dirname);
bp->purgetime = (uint32_t)time(NULL);
}
}
@ -611,9 +621,46 @@ int32_t iguana_bundleissuemissing(struct iguana_info *coin,struct iguana_bundle
int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag)
{
int32_t i,ready,valid,checki,hdrsi; char fname[1024]; struct iguana_block *block; int32_t sum[0x100],counts[0x100]; static bits256 zero; FILE *fp;
static bits256 zero;
int32_t i,ready,valid,checki,hdrsi; char fname[1024]; struct iguana_block *block; int32_t sum[0x100],counts[0x100]; FILE *fp; struct iguana_blockRO *B; struct iguana_bundle *nextbp; void *ptr; long filesize; struct iguana_ramchain R; bits256 prevhash2;
memset(sum,0,sizeof(sum));
memset(counts,0,sizeof(counts));
if ( 0 && bp->queued == 0 )
{
for (i=ready=0; i<bp->n; i++)
if ( (block= bp->blocks[i]) == 0 )
break;
if ( i < bp->n )
{
if ( (nextbp= coin->bundles[bp->hdrsi+1]) != 0 && (block= nextbp->blocks[0]) != 0 )
{
prevhash2 = block->RO.prev_block;
for (i=bp->n-1; i>=0; i--)
{
char str[65]; printf("[%d:%d] %s\n",bp->hdrsi,i,bits256_str(str,prevhash2));
if ( bp->blocks[i] == 0 && bits256_nonz(prevhash2) != 0 )
{
bp->hashes[i] = prevhash2;
bp->blocks[i] = iguana_blockhashset("ready",coin,bp->bundleheight+i,prevhash2,1);
iguana_hash2set(coin,"ready",bp,i,prevhash2);
prevhash2 = zero;
if ( (ptr= iguana_bundlefile(coin,fname,&filesize,bp,i)) != 0 )
{
if ( iguana_mapchaininit(coin,&R,bp,i,block,ptr,filesize) > 0 )
{
B = (void *)(long)((long)R.H.data + R.H.data->Boffset);
prevhash2 = B[0].prev_block;
}
munmap(ptr,filesize);
}
}
if ( bits256_nonz(prevhash2) == 0 )
break;
}
printf("reverse linked to [%d:%d]\n",bp->hdrsi,i);
}
}
}
for (i=ready=0; i<bp->n; i++)
{
if ( (block= bp->blocks[i]) != 0 )
@ -627,11 +674,9 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
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 ( requiredflag != 0 )
{
printf(">>>>>>> block contents error at ht.%d [%d:%d]\n",bp->bundleheight+i,bp->hdrsi,i);
//char str[65]; patch.(%s) and reissue %s checki.%d vs %d\n",block->fpipbits,bp->bundleheight+i,bits256_str(str,block->RO.prev_block),fname,checki,i);
iguana_blockunmark(coin,block,bp,i,1);
}
//char str[65]; patch.(%s) and reissue %s checki.%d vs %d\n",block->fpipbits,bp->bundleheight+i,bits256_str(str,block->RO.prev_block),fname,checki,i);
iguana_blockunmark(coin,block,bp,i,1);
}
else
{
@ -649,12 +694,14 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
} else iguana_blockunmark(coin,block,bp,i,0);
}
}
else
else if ( bp->queued != 0 )
{
printf("error getting block (%d:%d) %p\n",bp->hdrsi,i,block);
return(-1);
}
}
//if ( ready == bp->n )
// ready = iguana_bundlevalidate(coin,bp);
return(ready);
}
@ -806,6 +853,7 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int
int32_t iguana_bundlefinalize(struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB)
{
int32_t i;
if ( iguana_bundleready(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);
@ -825,6 +873,12 @@ int32_t iguana_bundlefinalize(struct iguana_info *coin,struct iguana_bundle *bp,
bp->emitfinish = (uint32_t)time(NULL) + 1;
iguana_bundletweak(coin,bp);
coin->numemitted++;
for (i=0; i<bp->n; i++)
iguana_hash2set(coin,"bundlefinalize",bp,i,bp->hashes[i]);
/*if ( bp->hdrsi == 0 && iguana_peerblockrequest(coin,coin->blockspace,sizeof(coin->blockspace),0,bp->hashes[0],1) > 0 )
printf("GENESIS block validated\n");
else printf("GENESIS didnt validate bp.%p\n",bp);*/
iguana_bundlevalidate(coin,bp,1);
}
else
{
@ -863,7 +917,8 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
iguana_bundlecalcs(coin,bp,lag);
if ( bp->hdrsi == coin->bundlescount-1 )
iguana_autoextend(coin,bp);
//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);
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);//cbrt(bp->hdrsi - starti)/10;
if ( bp->hdrsi == coin->bundlescount-1 || (bp->numhashes < bp->n && bp->bundleheight < coin->longestchain-coin->chain->bundlesize) )
iguana_bundlehdr(coin,bp,starti);
@ -905,7 +960,9 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
printf("ITER.rt%d now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->isRT,(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 += 3;
//printf("done hdrs.%d\n",bp->hdrsi);
iguana_bundleQ(coin,bp,1000);
if ( bp->balancefinish <= 1 )
iguana_bundleQ(coin,bp,1000);
else bp->queued = 0;
return(retval);
}
@ -1061,7 +1118,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
numutxo++;
if ( bp->balancefinish > 1 )
numbalances++;
if ( bp->validated != 0 )
if ( bp->validated > 1 )
numv++;
if ( bp->emitfinish >= 1 )
{
@ -1071,13 +1128,13 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
{
numemit++;
//printf("finished.[%d]\n",bp->hdrsi);
if ( firstgap != 0 && bp->hdrsi > firstgap->hdrsi-3 )
if ( firstgap != 0 && bp->hdrsi > firstgap->hdrsi-3 && firstgap->validated > 1 )
iguana_bundlepurgefiles(coin,bp);
}
}
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,0) != bp->n) )
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) )
{
//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;
@ -1200,7 +1257,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
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 b.%d/%d v.%d/%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",coin->symbol,coin->RTheight,numutxo,numbalances,numconverted,numv,coin->pendbalances,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));
sprintf(str,"%s.RT%d u.%d b.%d/%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",coin->symbol,coin->RTheight,numutxo,numbalances,numconverted,numv,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));
if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize && numemit == coin->current->hdrsi && numutxo == coin->bundlescount-1 )
{
//printf("have all utxo, generate balances\n");

1
iguana/iguana_chains.c

@ -399,7 +399,6 @@ struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createfl
}
if ( strcmp(name,chain->symbol) == 0 )
{
printf("found.(%s)\n",name);
iguana_chaininit(chain,strcmp(chain->symbol,"BTC") == 0,argjson);
return(chain);
}

15
iguana/iguana_init.c

@ -18,6 +18,8 @@
void iguana_initQ(queue_t *Q,char *name)
{
char *tst,*str = "need to init each Q when single threaded";
memset(Q,0,sizeof(*Q));
strcpy(Q->name,name);
queue_enqueue(name,Q,queueitem(str),1);
if ( (tst= queue_dequeue(Q,1)) != 0 )
free_queueitem(tst);
@ -56,8 +58,6 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
sprintf(dirname,"tmp/%s",coin->symbol), OS_portable_path(dirname);
portable_mutex_init(&coin->peers_mutex);
portable_mutex_init(&coin->blocks_mutex);
//portable_mutex_init(&coin->scripts_mutex[0]);
//portable_mutex_init(&coin->scripts_mutex[1]);
iguana_meminit(&coin->blockMEM,"blockMEM",coin->blockspace,sizeof(coin->blockspace),0);
iguana_initQs(coin);
coin->bindsock = -1;
@ -65,14 +65,13 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
coin->startutc = (uint32_t)time(NULL);
while ( time(NULL) == coin->startutc )
usleep(1);
coin->startutc++;
printf("start.%u\n",coin->startutc);
coin->startmillis = OS_milliseconds(), coin->starttime = tai_now(coin->startmillis);
coin->avetime = 1 * 100;
//coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES;
for (i=0; i<IGUANA_MAXPEERS; i++)
coin->peers.active[i].usock = -1;
// validate blocks
//for (i=0; i<IGUANA_NUMAPPENDS; i++)
// vupdate_sha256(coin->latest.lhashes[i].bytes,&coin->latest.states[i],0,0);
}
bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
@ -99,14 +98,14 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
bits256_str(str,hash2);
printf("genesis.(%s) len.%d hash.%s\n",chain->genesis_hex,(int32_t)sizeof(msg.H),str);
iguana_blockconv(&block,&msg,hash2,0);
//coin->latest.dep.numtxids =
block.RO.txn_count = 1;
block.RO.numvouts = 1;
iguana_gotdata(coin,0,0);
if ( (ptr= iguana_blockhashset("genesis0",coin,0,hash2,1)) != 0 )
{
ptr->mainchain = 1;
iguana_blockcopy(coin,ptr,&block);
ptr->mainchain = 1;
ptr->height = 0;
coin->blocks.RO[0] = block.RO;
if ( (height= iguana_chainextend(coin,ptr)) == 0 )
{
@ -172,7 +171,7 @@ int32_t iguana_savehdrs(struct iguana_info *coin)
}
}
//printf("compare hdrs.txt %ld vs (%s) %ld\n",ftell(fp),fname,(long)OS_filesize(fname));
if ( ftell(fp) > OS_filesize(fname) )
if ( (long)ftell(fp) > OS_filesize(fname) )
{
printf("new hdrs.txt %ld vs (%s) %ld\n",ftell(fp),fname,(long)OS_filesize(fname));
fclose(fp);

6
iguana/iguana_json.c

@ -600,6 +600,11 @@ STRING_ARG(iguana,addcoin,newcoin)
symbol = coin->symbol;
if ( symbol != 0 )
{
//printf(">> addcoin.%s\n",symbol);
#ifdef __PNACL__
if ( strcmp(symbol,"BTC") == 0 )
return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}"));
#endif
if ( (retval= iguana_launchcoin(symbol,json)) > 0 )
{
if ( myinfo->rpcsymbol[0] == 0 )
@ -826,6 +831,7 @@ STRING_ARG(SuperNET,bitcoinrpc,setcoin)
{
strcpy(myinfo->rpcsymbol,setcoin);
touppercase(myinfo->rpcsymbol);
printf("bitcoinrpc.%s\n",myinfo->rpcsymbol);
iguana_launchcoin(myinfo->rpcsymbol,json);
return(clonestr("{\"result\":\"set bitcoin RPC coin\"}"));
} else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}"));

2
iguana/iguana_msg.c

@ -561,7 +561,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
for (i=0; i<n; i++)
{
len += iguana_rwbignum(0,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(bits256),hash2.bytes);
iguana_peerblockrequest(coin,addr,hash2);
iguana_peerblockrequest(coin,addr->blockspace,sizeof(addr->blockspace),addr,hash2,0);
if ( bits256_nonz(hash2) == 0 )
break;
}

24
iguana/iguana_peers.c

@ -736,7 +736,7 @@ void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA)
//printf("call rwIaddrInd\n");
if ( iguana_rwiAddrind(coin,1,iA,iA->hh.itemind) > 0 )
{
//printf("iA.%p iguana_startconnection.(%s) status.%d pending.%d\n",iA,addr->ipaddr,iA->status,addr->pending);
printf("iA.%p iguana_startconnection.(%s) status.%d pending.%d\n",iA,addr->ipaddr,iA->status,addr->pending);
iA->status = IGUANA_PEER_CONNECTING;
addr->pending = (uint32_t)time(NULL);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
@ -984,23 +984,41 @@ int64_t iguana_peerallocated(struct iguana_info *coin,struct iguana_peer *addr)
}
#endif
int32_t iguana_voutsfname(struct iguana_info *coin,char *fname,int32_t slotid)
{
sprintf(fname,"DB/%s/vouts/%04d.vouts",coin->symbol,slotid);
return((int32_t)strlen(fname));
}
int32_t iguana_vinsfname(struct iguana_info *coin,char *fname,int32_t slotid)
{
sprintf(fname,"%s/%s/%04d.vins",coin->VALIDATEDIR,coin->symbol,slotid);
return((int32_t)strlen(fname));
}
int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32_t slotid,uint64_t ipbits)
{
char fname[1024];
addr->ipbits = ipbits;
addr->addrind = slotid;
sprintf(fname,"DB/%s/vouts/%04d.vouts",coin->symbol,addr->addrind);
iguana_voutsfname(coin,fname,addr->addrind);
if ( (addr->voutsfp= fopen(fname,"rb+")) != 0 )
fseek(addr->voutsfp,0,SEEK_END);
else if ( (addr->voutsfp= fopen(fname,"wb+")) == 0 )
{
printf("cant create.(%s)\n",fname);
return(-1);
}
if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 )
{
sprintf(fname,"%s/%s/%04d.vins",coin->VALIDATEDIR,coin->symbol,addr->addrind);
iguana_vinsfname(coin,fname,addr->addrind);
if ( (addr->vinsfp= fopen(fname,"rb+")) != 0 )
fseek(addr->vinsfp,0,SEEK_END);
else if ( (addr->vinsfp= fopen(fname,"wb+")) == 0 )
{
printf("cant create.(%s)\n",fname);
return(-1);
}
}
return(0);
}

105
iguana/iguana_ramchain.c

@ -319,7 +319,7 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
u->fileid = (uint32_t)addr->addrind;
u->scriptpos = (uint32_t)ftell(addr->voutsfp);
if ( fwrite(script,1,scriptlen,addr->voutsfp) != scriptlen )
printf("error writing scriptlen.%d\n",scriptlen);
printf("error writing vout scriptlen.%d errno.%d\n",scriptlen,errno);
else addr->dirty[0]++;
}
else
@ -556,7 +556,7 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
s->fileid = (uint32_t)addr->addrind;
s->scriptpos = (uint32_t)ftell(addr->vinsfp);
if ( fwrite(vinscript,1,vinscriptlen,addr->vinsfp) != vinscriptlen )
printf("error writing vinscriptlen.%d\n",vinscriptlen);
printf("error writing vinscriptlen.%d errno.%d\n",vinscriptlen,errno);
else addr->dirty[1]++;
} else s->scriptpos = 0;
//else printf("spend256 scriptfpos.%d\n",s->scriptfpos);
@ -636,9 +636,9 @@ void *iguana_ramchain_offset(void *dest,uint8_t *lhash,FILE *fp,uint64_t fpos,vo
{
if ( (err= fwrite(srcptr,1,len,fp)) != len )
{
printf("iguana_ramchain_sizefunc: error.%ld writing len.%ld to fp.%p\n",err,(long)len,fp);
printf("iguana_ramchain_sizefunc: error.%ld writing len.%ld to fp.%p errno.%d\n",err,(long)len,fp,errno);
printf("probably out of disk space. please free up space\n");
fprintf(stderr,"iguana_ramchain_sizefunc: error.%ld writing len.%ld to fp.%p\n",err,(long)len,fp);
fprintf(stderr,"iguana_ramchain_sizefunc: error.%ld writing len.%ld to fp.%p errno.%d\n",err,(long)len,fp,errno);
fprintf(stderr,"probably out of disk space. please free up space\n");
sleep(3);
}
@ -1231,12 +1231,12 @@ int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi)
printf("delete bundle.[%d]\n",hdrsi);
iguana_ramchain_free(coin,&bp->ramchain,0);
if ( iguana_bundlefname(coin,bp,fname) == 0 )
{
printf("delete.(%s)\n",fname);
OS_removefile(fname,0);
}
sprintf(fname,"DB/%s/spends/%s.%d",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight);
OS_removefile(fname,0);
sprintf(fname,"DB/%s/spends/%s.%d",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight), OS_removefile(fname,0);
sprintf(fname,"DB/%s/accounts/debits.%d",coin->symbol,bp->bundleheight), OS_removefile(fname,0);
sprintf(fname,"DB/%s/accounts/lastspends.%d",coin->symbol,bp->bundleheight), OS_removefile(fname,0);
sprintf(fname,"DB/%s/validated/%d",coin->symbol,bp->bundleheight), OS_removefile(fname,0);
bp->utxofinish = bp->startutxo = bp->balancefinish = bp->validated = bp->emitfinish = bp->converted = 0;
return(0);
}
return(-1);
@ -1421,12 +1421,12 @@ struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname
return(0);
}
void iguana_ramchain_link(struct iguana_ramchain *ramchain,bits256 firsthash2,bits256 lasthash2,int32_t hdrsi,int32_t height,int32_t bundlei,int32_t numblocks,int32_t firsti,int32_t ROflag)
void iguana_ramchain_link(struct iguana_ramchain *ramchain,bits256 firsthash2,int32_t hdrsi,int32_t height,int32_t bundlei,int32_t numblocks,int32_t firsti,int32_t ROflag)
{
if ( ROflag == 0 )
{
ramchain->H.data->firsthash2 = firsthash2;
ramchain->H.data->lasthash2 = lasthash2;
//ramchain->H.data->lasthash2 = lasthash2;
ramchain->H.data->hdrsi = hdrsi;
ramchain->H.data->height = height;
ramchain->H.data->numblocks = numblocks;
@ -1435,7 +1435,7 @@ void iguana_ramchain_link(struct iguana_ramchain *ramchain,bits256 firsthash2,bi
ramchain->H.bundlei = bundlei;
ramchain->height = height;
ramchain->numblocks = numblocks;
ramchain->lasthash2 = lasthash2;
//ramchain->lasthash2 = lasthash2;
ramchain->H.txidind = ramchain->H.unspentind = ramchain->H.spendind = ramchain->pkind = firsti;
ramchain->externalind = 0;//ramchain->H.scriptoffset = ramchain->H.stacksize = 0;
}
@ -1709,31 +1709,6 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
return(0);
}
bits256 iguana_merkle(struct iguana_info *coin,bits256 *tree,struct iguana_msgtx *txarray,int32_t txn_count)
{
int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2];
if ( txn_count == 1 )
return(txarray[0].txid);
for (i=0; i<txn_count; i++)
tree[i] = txarray[i].txid;
prev = 0;
while ( txn_count > 1 )
{
if ( (txn_count & 1) != 0 )
tree[prev + txn_count] = tree[prev + txn_count-1], txn_count++;
n += txn_count;
for (i=0; i<txn_count; i+=2)
{
iguana_rwbignum(1,serialized,sizeof(*tree),tree[prev + i].bytes);
iguana_rwbignum(1,&serialized[sizeof(*tree)],sizeof(*tree),tree[prev + i + 1].bytes);
tree[n + (i >> 1)] = bits256_doublesha256(0,serialized,sizeof(serialized));
}
prev = n;
txn_count >>= 1;
}
return(tree[n]);
}
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)
{
int32_t verifyflag = 0; static uint64_t totalrecv;
@ -1756,8 +1731,11 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
msize = (int32_t)sizeof(bits256) * (txn_count+1) * 2;
if ( msize <= addr->TXDATA.totalsize )
{
bits256 *tree = addr->TXDATA.ptr;
iguana_memreset(&addr->TXDATA);
merkle_root = iguana_merkle(coin,addr->TXDATA.ptr,txarray,txn_count);
for (i=0; i<txn_count; i++)
tree[i] = txarray[i].txid;
merkle_root = iguana_merkle(coin,tree,txn_count);
if ( bits256_cmp(merkle_root,origtxdata->block.RO.merkle_root) != 0 )
{
char str[65],str2[65];
@ -1816,7 +1794,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
return(-1);
}
block->fpos = fpos = -1;
iguana_ramchain_link(ramchain,block->RO.hash2,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0);
iguana_ramchain_link(ramchain,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0);
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data);
//printf("Kspace.%p bp.[%d:%d] <- scriptspace.%d expanded.%d\n",Kspace,bp->hdrsi,bundlei,scriptspace,ramchain->expanded);
if ( T == 0 || U == 0 || S == 0 || B == 0 )
@ -1848,6 +1826,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
iguana_ramchain_addspend256(coin,addr,RAMCHAIN_ARG,tx->vins[j].prev_hash,tx->vins[j].prev_vout,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->vins[j].sequence,bp);//,bp->hdrsi,bundlei);
}
}
ramchain->H.data->prevhash2 = block->RO.prev_block;
ramchain->H.data->scriptspace = scriptspace = ramchain->H.scriptoffset;
ramchain->H.data->stackspace = stackspace = ramchain->H.stacksize;
iguana_ramchain_setsize(ramchain,ramchain->H.data,1);
@ -1883,7 +1862,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
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 )
{
//printf("mapped Soffset.%ld\n",(long)mapchain->data->Soffset);
iguana_ramchain_link(&R,block->RO.hash2,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
iguana_ramchain_link(&R,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
if ( 1 ) // unix issues?
{
if ( (err= iguana_ramchain_cmp(ramchain,mapchain,0)) != 0 )
@ -1895,7 +1874,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
iguana_ramchain_free(coin,mapchain,1);
memset(&R,0,sizeof(R));
R.H.data = (void *)(long)((long)ptr + fpos), R.filesize = fsize;
iguana_ramchain_link(&R,block->RO.hash2,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
iguana_ramchain_link(&R,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
}
}
if ( (err= iguana_ramchain_cmp(ramchain,&R,0)) != 0 )
@ -1970,13 +1949,16 @@ void iguana_ramchain_disp(struct iguana_ramchain *ramchain)
void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,struct iguana_bundle *bp,int32_t i,int32_t deletefile)
{
void *ptr; int32_t recvlen,hdrsi,checki; char fname[1024]; static const bits256 zero;
if ( bp != 0 )
if ( 0 && bp != 0 )
printf("UNMARK.[%d:%d]\n",bp->hdrsi,i);
block->queued = 0;
block->fpipbits = 0;
block->fpos = -1;
block->txvalid = 0;
block->issued = 0;
if ( block != 0 )
{
block->queued = 0;
block->fpipbits = 0;
block->fpos = -1;
block->txvalid = 0;
block->issued = 0;
}
if ( bp != 0 && i >= 0 && i < bp->n )
{
bp->issued[i] = 0;
@ -2109,10 +2091,10 @@ void iguana_bundlemapfree(struct iguana_info *coin,struct OS_memspace *mem,struc
int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,struct iguana_ramchain *newchain,struct OS_memspace *hashmem,int32_t cmpflag,struct iguana_bundle *bp)
{
static const bits256 zero;
bits256 firsthash2,lasthash2; int32_t err,bundlei,hdrsi,numblocks,firsti,height,retval= -1;
struct iguana_ramchain checkR,*mapchain; char fname[1024];
bits256 firsthash2; int32_t err,bundlei,hdrsi,numblocks,firsti,height,retval= -1;
struct iguana_ramchain checkR,*mapchain; char fname[1024]; struct iguana_block *block;
uint32_t scriptspace,scriptoffset,stacksize; uint8_t *destoffset,*srcoffset;
firsthash2 = ramchain->H.data->firsthash2, lasthash2 = ramchain->H.data->lasthash2;
firsthash2 = ramchain->H.data->firsthash2;//, lasthash2 = ramchain->H.data->lasthash2;
height = ramchain->height, firsti = ramchain->H.data->firsti, hdrsi = ramchain->H.hdrsi, numblocks = ramchain->numblocks;
destoffset = &Kspace[ramchain->H.scriptoffset];
srcoffset = &Kspace[ramchain->H.data->scriptspace - ramchain->H.stacksize];
@ -2126,6 +2108,8 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru
scriptoffset = ramchain->H.scriptoffset;
stacksize = ramchain->H.stacksize;
//ramchain->H.scriptoffset = scriptoffset;
if ( (block= bp->blocks[0]) != 0 )
ramchain->H.data->prevhash2 = block->RO.prev_block;
ramchain->H.data->scriptspace = scriptoffset;
ramchain->H.stacksize = ramchain->H.data->stackspace = stacksize;
iguana_ramchain_setsize(ramchain,ramchain->H.data,bp->n);
@ -2166,7 +2150,7 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru
iguana_memreset(hashmem);
if ( (mapchain= iguana_ramchain_map(coin,fname,bp,numblocks,&checkR,cmpflag==0?hashmem:0,0,firsthash2,zero,bundlei,0,0,1)) != 0 )
{
iguana_ramchain_link(mapchain,firsthash2,lasthash2,hdrsi,height,0,numblocks,firsti,1);
iguana_ramchain_link(mapchain,firsthash2,hdrsi,height,0,numblocks,firsti,1);
iguana_ramchain_extras(coin,mapchain,hashmem,0);
//printf("expSAVE: Koffset.%d scriptoffset.%d stacksize.%d allocsize.%d\n",(int32_t)mapchain->H.data->Koffset,mapchain->H.scriptoffset,mapchain->H.stacksize,(int32_t)mapchain->H.data->allocsize);
if ( (err= iguana_ramchain_iterate(coin,0,mapchain,bp,bundlei)) != 0 )
@ -2197,7 +2181,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
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 )
{
iguana_ramchain_link(mapchain,bp->hashes[0],bp->hashes[bp->n-1],bp->hdrsi,bp->bundleheight,0,bp->n,firsti,1);
iguana_ramchain_link(mapchain,bp->hashes[0],bp->hdrsi,bp->bundleheight,0,bp->n,firsti,1);
//char str[65]; printf("bp.%d: T.%d U.%d S.%d P%d X.%d MAPPED %s %p\n",bp->hdrsi,mapchain->H.data->numtxids,mapchain->H.data->numunspents,mapchain->H.data->numspends,mapchain->H.data->numpkinds,mapchain->H.data->numexternaltxids,mbstr(str,mapchain->H.data->allocsize),mapchain->H.data);
//ramcoder_test(mapchain->H.data,mapchain->H.data->allocsize);
B = (void *)(long)((long)mapchain->H.data + mapchain->H.data->Boffset);
@ -2214,8 +2198,9 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
block->fpipbits = (uint32_t)calc_ipbits("127.0.0.1");
block->RO = B[i];
//printf("%x ",(int32_t)B[i].hash2.ulongs[3]);
if ( bits256_nonz(bp->hashes[i]) == 0 )
bp->hashes[i] = B[i].hash2;
iguana_hash2set(coin,"bundleload",bp,i,block->RO.hash2);
//if ( bits256_nonz(bp->hashes[i]) == 0 )
// bp->hashes[i] = B[i].hash2;
if ( bp->bundleheight+i == coin->blocks.hwmchain.height+1 )
{
//printf("try extend.%d\n",bp->bundleheight+i);
@ -2290,7 +2275,7 @@ int64_t iguana_ramchainopen(struct iguana_info *coin,struct iguana_ramchain *ram
}
if ( iguana_ramchain_init(ramchain,mem,hashmem,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,1,numblocks) > 0 )
{
iguana_ramchain_link(ramchain,hash2,hash2,bundleheight/coin->chain->bundlesize,bundleheight,0,0,1,0);
iguana_ramchain_link(ramchain,hash2,bundleheight/coin->chain->bundlesize,bundleheight,0,0,1,0);
ramchain->expanded = 1;
ramchain->H.scriptoffset = 1;
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data);
@ -2324,7 +2309,7 @@ int32_t iguana_mapchaininit(struct iguana_info *coin,struct iguana_ramchain *map
char str[65],str2[65]; printf("iguana_bundlesaveHT.[%d:%d] hash2 mismatch %s vs %s\n",bp->hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str2,mapchain->H.data->firsthash2));
return(-1);
}
iguana_ramchain_link(mapchain,bp->hashes[bundlei],bp->hashes[bundlei],bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
iguana_ramchain_link(mapchain,bp->hashes[bundlei],bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
if ( bp->blocks[bundlei]->RO.txn_count == 0 )
bp->blocks[bundlei]->RO.txn_count = mapchain->H.data->numtxids - 1;
return(0);
@ -2418,7 +2403,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str
iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi);
return(-1);
}
iguana_ramchain_link(dest,bp->hashes[starti],bp->hashes[endi],bp->hdrsi,bp->bundleheight,0,bp->n,firsti,0);
iguana_ramchain_link(dest,bp->hashes[starti],bp->hdrsi,bp->bundleheight,0,bp->n,firsti,0);
dest->expanded = 1;
dest->H.scriptoffset = 1;
_iguana_ramchain_setptrs(RAMCHAIN_DESTPTRS,dest->H.data);
@ -2546,11 +2531,11 @@ int32_t iguana_bundlemergeHT(struct iguana_info *coin,struct OS_memspace *mem,st
memset(&_Bchain,0,sizeof(_Bchain)); B = &_Bchain;
if ( (A= iguana_ramchain_map(coin,fnameA,bp,bp->ramchain.numblocks,A,&HASHMEMA,0,bp->hashes[0],zero,0,0,1,1)) != 0 )
{
iguana_ramchain_link(A,bp->hashes[0],bp->ramchain.lasthash2,bp->hdrsi,bp->bundleheight,0,bp->ramchain.numblocks,firsti,1);
iguana_ramchain_link(A,bp->hashes[0],bp->hdrsi,bp->bundleheight,0,bp->ramchain.numblocks,firsti,1);
}
if ( (B= iguana_ramchain_map(coin,fnameB,bp,nextbp->ramchain.numblocks,B,&HASHMEMB,0,nextbp->hashes[0],zero,0,0,1,1)) != 0 )
{
iguana_ramchain_link(B,bp->hashes[0],nextbp->ramchain.lasthash2,nextbp->hdrsi,nextbp->bundleheight,0,nextbp->ramchain.numblocks,firsti,1);
iguana_ramchain_link(B,bp->hashes[0],nextbp->hdrsi,nextbp->bundleheight,0,nextbp->ramchain.numblocks,firsti,1);
}
if ( A == 0 || B == 0 || A->H.data == 0 || B->H.data == 0 || (A->H.data->allocsize + B->H.data->allocsize) > IGUANA_MAXRAMCHAINSIZE )
{
@ -2567,7 +2552,7 @@ int32_t iguana_bundlemergeHT(struct iguana_info *coin,struct OS_memspace *mem,st
return(-1);
}
depth++;
iguana_ramchain_link(dest,A->H.data->firsthash2,B->H.data->lasthash2,A->H.hdrsi,A->height,0,A->numblocks+B->numblocks,firsti,0);
iguana_ramchain_link(dest,A->H.data->firsthash2,A->H.hdrsi,A->height,0,A->numblocks+B->numblocks,firsti,0);
_iguana_ramchain_setptrs(RAMCHAIN_DESTPTRS,dest->H.data);
iguana_ramchain_extras(coin,dest,&HASHMEM,0);
dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti;

15
iguana/iguana_recv.c

@ -253,7 +253,7 @@ int8_t iguana_blockstatus(struct iguana_info *coin,struct iguana_block *block)
void iguana_bundletime(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,int32_t duplicateflag)
{
uint32_t starttime; int32_t duration;
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n && block != 0 )
{
starttime = block->issued;
if ( starttime == 0 || bp->issued[bundlei] > block->issued )
@ -380,7 +380,8 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
{
copyflag = 0;
speculative = 1;
iguana_bundletime(coin,bp,j,bp->blocks[j],0);
if ( bp->blocks[j] != 0 )
iguana_bundletime(coin,bp,j,bp->blocks[j],0);
break;
}
}
@ -808,6 +809,16 @@ void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp)
if ( bp->hdrsi == coin->bundlescount-1 && bits256_nonz(bp->nextbundlehash2) != 0 )
{
init_hexbytes_noT(hashstr,bp->nextbundlehash2.bytes,sizeof(bits256));
newbp = 0, bundlei = -2;
if ( iguana_bundlefind(coin,&newbp,&bundlei,bp->nextbundlehash2) != 0 )
{
if ( newbp->bundleheight != bp->bundleheight+bp->n )
{
printf("found spurious extra hash for [%d:%d]\n",bp->hdrsi,bp->n);
memset(&bp->nextbundlehash2,0,sizeof(bp->nextbundlehash2));
return;
}
}
newbp = iguana_bundlecreate(coin,&bundlei,bp->bundleheight+coin->chain->bundlesize,bp->nextbundlehash2,zero,1);
if ( newbp != 0 )
{

13
iguana/iguana_rpc.c

@ -231,7 +231,18 @@ static char *getblockcount(RPCARGS)
static char *getblock(RPCARGS)
{
return(sglue1(0,CALLGLUE,"bitcoinrpc","getblock","blockhash",params[0]));
cJSON *obj;
if ( params[1] == 0 )
params[1] = cJSON_CreateNumber(1);
else
{
obj = params[1];
if ( is_cJSON_False(params[1]) != 0 )
params[1] = cJSON_CreateNumber(0);
else params[1] = cJSON_CreateNumber(1);
free_json(obj);
}
return(sglue3(0,CALLGLUE,"bitcoinrpc","getblock","blockhash",params[0],"verbose",params[1],"remoteonly",params[2]));
}
static char *getblockhash(RPCARGS)

175
iguana/iguana_tx.c

@ -22,10 +22,10 @@
//struct iguana_spend { uint32_t spendtxidind; int16_t prevout; uint16_t tbd:14,external:1,diffsequence:1; } __attribute__((packed));
void iguana_vinset(struct iguana_info *coin,int32_t height,struct iguana_msgvin *vin,struct iguana_txid *tx,int32_t i)
int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t height,struct iguana_msgvin *vin,struct iguana_txid *tx,int32_t i)
{
struct iguana_spend *s,*S; uint32_t spendind,unspentind; struct iguana_bundle *bp;
struct iguana_ramchaindata *rdata; struct iguana_txid *T; bits256 *X;
struct iguana_spend *s,*S; uint32_t spendind,unspentind; bits256 *X; struct iguana_bundle *bp;
struct iguana_ramchaindata *rdata; struct iguana_txid *T; char fname[1024]; FILE *fp; int32_t err = 0;
memset(vin,0,sizeof(*vin));
if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 )
{
@ -34,20 +34,35 @@ void iguana_vinset(struct iguana_info *coin,int32_t height,struct iguana_msgvin
T = (void *)(long)((long)rdata + rdata->Toffset);
spendind = (tx->firstvin + i);
s = &S[spendind];
if ( s->sequenceid == 1 )
vin->sequence = 0xffffffff;
else if ( s->sequenceid == 2 )
vin->sequence = 0xfffffffe;
else vin->sequence = 0;
vin->sequence = s->sequenceid;
vin->prev_vout = s->prevout;
if ( s->scriptpos != 0 && s->scriptlen > 0 )
{
iguana_vinsfname(coin,fname,s->fileid);
if ( (fp= fopen(fname,"rb")) != 0 )
{
fseek(fp,s->scriptpos,SEEK_SET);
if ( fread(scriptspace,1,s->scriptlen,fp) != s->scriptlen )
err++;
fclose(fp);
} else err++;
if ( err != 0 )
printf("err.%d getting %d bytes from fileid.%d[%d] %s for s%d\n",err,s->scriptlen,s->scriptpos,s->fileid,fname,spendind);
}
vin->scriptlen = s->scriptlen;
vin->vinscript = scriptspace;
iguana_ramchain_spendtxid(coin,&unspentind,&vin->prev_hash,T,rdata->numtxids,X,rdata->numexternaltxids,s);
}
if ( err != 0 )
return(-err);
else return(vin->scriptlen);
}
int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmstr,int32_t height,struct iguana_msgvout *vout,struct iguana_txid *tx,int32_t i)
{
struct iguana_ramchaindata *rdata; uint32_t unspentind,scriptlen = 0; struct iguana_bundle *bp;
struct iguana_unspent *u,*U; char coinaddr[65]; struct iguana_pkhash *P,*p; struct vin_info V;
char fname[1024]; FILE *fp; int32_t err = 0;
memset(vout,0,sizeof(*vout));
if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 && i < tx->numvouts )
{
@ -60,11 +75,30 @@ int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmst
p = &P[u->pkind];
vout->value = u->value;
vout->pk_script = scriptspace;
memset(&V,0,sizeof(V));
scriptlen = iguana_scriptgen(coin,&V.M,&V.N,coinaddr,scriptspace,asmstr,p->rmd160,u->type,(const struct vin_info *)&V,i);
if ( u->scriptpos != 0 && u->scriptlen > 0 )
{
iguana_voutsfname(coin,fname,u->fileid);
if ( (fp= fopen(fname,"rb")) != 0 )
{
fseek(fp,u->scriptpos,SEEK_SET);
if ( fread(scriptspace,1,u->scriptlen,fp) != u->scriptlen )
err++;
else scriptlen = u->scriptlen;
fclose(fp);
} else err++;
if ( err != 0 )
printf("error.%d %d bytes from fileid.%d[%d] %s for u%d\n",err,u->scriptlen,u->fileid,u->scriptpos,fname,unspentind);
}
else
{
memset(&V,0,sizeof(V));
scriptlen = iguana_scriptgen(coin,&V.M,&V.N,coinaddr,scriptspace,asmstr,p->rmd160,u->type,(const struct vin_info *)&V,i);
}
}
vout->pk_scriptlen = scriptlen;
return(scriptlen);
if ( err != 0 )
return(-err);
else return(scriptlen);
}
struct iguana_txid *iguana_blocktx(struct iguana_info *coin,struct iguana_txid *tx,struct iguana_block *block,int32_t i)
@ -72,27 +106,27 @@ struct iguana_txid *iguana_blocktx(struct iguana_info *coin,struct iguana_txid *
struct iguana_bundle *bp; uint32_t txidind;
if ( i >= 0 && i < block->RO.txn_count )
{
if ( block->height >= 0 ) //
if ( block->height >= 0 )
{
if ( (bp= coin->bundles[block->hdrsi]) != 0 )
{
if ( (txidind= block->RO.firsttxidind) > 0 )//bp->firsttxidinds[block->bundlei]) > 0 )
if ( (txidind= block->RO.firsttxidind) > 0 )
{
if ( iguana_bundletx(coin,bp,block->bundlei,tx,txidind+i) == tx )
return(tx);
printf("error getting txidind.%d + i.%d from hdrsi.%d\n",txidind,i,block->hdrsi);
return(0);
} else printf("iguana_blocktx null txidind\n");
} else printf("iguana_blocktx no bp\n");
}
} 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("i.%d vs txn_count.%d\n",i,block->RO.txn_count);
return(0);
}
int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts)
int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs)
{
int32_t i,rwflag=1,len = 0; char asmstr[512],txidstr[65];
uint32_t numvins,numvouts; struct iguana_msgvin vin; struct iguana_msgvout vout; uint8_t space[8192];
uint32_t numvins,numvouts; struct iguana_msgvin vin; struct iguana_msgvout vout; uint8_t space[IGUANA_MAXSCRIPTSIZE];
len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->version),&tx->version);
if ( coin->chain->hastimestamp != 0 )
len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->timestamp),&tx->timestamp);
@ -101,8 +135,13 @@ 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,height,&vin,tx,i);
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 ( len > maxlen )
@ -123,30 +162,79 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
{
//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, probably due to running without stored sigs txid %s vs %s\n",rwflag,numvins,numvouts,bits256_str(str,*txidp),bits256_str(str2,tx->txid));
//char str[65],str2[65]; printf("\nrw.%d numvins.%d numvouts.%d error generating txbytes, probably due to running without stored sigs txid %s vs %s\n",rwflag,numvins,numvouts,bits256_str(str,*txidp),bits256_str(str2,tx->txid));
return(len);
}
return(len);
}
int32_t iguana_peerblockrequest(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2)
int32_t iguana_peerblockrequest(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_bundle *bp=0;
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n && (block= bp->blocks[bundlei]) != 0 && block->mainchain != 0 && block->height >= 0 )
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];
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n )
{
for (i=total=0; i<block->RO.txn_count; i++)
if ( (block= bp->blocks[bundlei]) != 0 )
{
if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
iguana_blockunconv(&msgB,block,1);
total = iguana_rwblock(1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{
printf("iguana_peerblockrequest: blockhash mismatch ht.%d\n",bp->bundleheight+bundlei);
return(-1);
}
for (i=0; i<block->RO.txn_count; i++)
{
if ( (len= iguana_ramtxbytes(coin,&addr->blockspace[sizeof(struct iguana_msghdr) + total],sizeof(addr->blockspace) - total,&checktxid,tx,block->height,0,0)) > 0 && bits256_cmp(checktxid,T.txid) == 0 )
total += len;
else break;
} else break;
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 )
total += len;
else
{
char str[65],str2[65];
printf("error getting txi.%d [%d:%d] cmp.%s %s\n",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);
break;
}
}
if ( i == block->RO.txn_count )
{
tmp = (long)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)];
tmp &= ~(sizeof(bits256) - 1);
tree = (void *)tmp;
for (i=0; i<block->RO.txn_count; i++)
{
if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
tree[i] = T.txid;
else break;
}
if ( i == block->RO.txn_count )
{
merkle_root = iguana_merkle(coin,tree,block->RO.txn_count);
if ( bits256_cmp(merkle_root,block->RO.merkle_root) == 0 )
{
if ( addr != 0 )
return(iguana_queue_send(coin,addr,0,blockspace,"block",total,0,0));
else
{
//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: 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);
}
if ( i == block->RO.txn_count )
return(iguana_queue_send(coin,addr,0,addr->blockspace,"block",total,0,0));
else printf("iguana_peerblockrequest: error getting tx.[%d] for ht.%d\n",i,bp->bundleheight+bundlei);
}
else
{
if ( block != 0 )
printf("iguana_peerblockrequest: block.%p ht.%d mainchain.%d [%d:%d]\n",block,block->height,block->mainchain,bp->hdrsi,bundlei);
else printf("iguana_peerblockrequest: block.%p [%d:%d]\n",block,bp->hdrsi,bundlei);
}
} else printf("iguana_peerblockrequest: cant find %s\n",bits256_str(str,hash2));
return(-1);
}
@ -197,14 +285,20 @@ int32_t iguana_peerinvdata(struct iguana_info *coin,struct iguana_peer *addr,uin
cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag)
{
char str[65],hexstr[1024]; int32_t i,len; struct iguana_txid *tx,T; struct iguana_msgblock msg;
bits256 hash2; uint8_t serialized[1024]; cJSON *array,*json = cJSON_CreateObject();
char str[65],hexstr[1024]; int32_t i,len,size; struct iguana_txid *tx,T; struct iguana_msgblock msg;
bits256 hash2,nexthash2; uint8_t serialized[1024]; cJSON *array,*json = cJSON_CreateObject();
jaddstr(json,"result","success");
jaddstr(json,"blockhash",bits256_str(str,block->RO.hash2));
jaddnum(json,"height",block->height);
//jaddnum(json,"ipbits",block->fpipbits);
jaddstr(json,"merkle_root",bits256_str(str,block->RO.merkle_root));
jaddstr(json,"prev_block",bits256_str(str,block->RO.prev_block));
jaddstr(json,"merkleroot",bits256_str(str,block->RO.merkle_root));
jaddstr(json,"previousblockhash",bits256_str(str,block->RO.prev_block));
if ( block->height > 0 )
{
nexthash2 = iguana_blockhash(coin,block->height+1);
if ( bits256_nonz(nexthash2) != 0 )
jaddstr(json,"nextblockhash",bits256_str(str,nexthash2));
}
jaddnum(json,"timestamp",block->RO.timestamp);
jaddstr(json,"utc",utc_str(str,block->RO.timestamp));
jaddnum(json,"nonce",block->RO.nonce);
@ -219,7 +313,7 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3
jaddnum(json,"valid",block->valid);
jaddnum(json,"txn_count",block->RO.txn_count);
jaddnum(json,"nBits",block->RO.bits);
jaddnum(json,"bits",block->RO.bits);
serialized[0] = ((uint8_t *)&block->RO.bits)[3];
serialized[1] = ((uint8_t *)&block->RO.bits)[2];
serialized[2] = ((uint8_t *)&block->RO.bits)[1];
@ -244,9 +338,12 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3
if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
jaddistr(array,bits256_str(str,tx->txid));
}
jadd(json,"txids",array);
jadd(json,"tx",array);
//printf("add txids[%d]\n",block->txn_count);
}
if ( (size= iguana_peerblockrequest(coin,coin->blockspace,sizeof(coin->blockspace),0,block->RO.hash2,0)) < 0 )
jaddstr(json,"error","couldnt generate raw bytes for block");
else jaddnum(json,"size",size);
return(json);
}

87
iguana/iguana_unspents.c

@ -237,10 +237,10 @@ int32_t iguana_spentflag(struct iguana_info *coin,int32_t *spentheightp,struct i
memset(&utxo,0,sizeof(utxo));
if ( spent_unspentind != 0 && spent_unspentind < numunspents )
{
if ( (hhutxo= iguana_hhutxofind(coin,ubuf,spent_hdrsi,spent_unspentind)) != 0 && hhutxo->u.spentflag != 0 )
utxo = hhutxo->u;
else if ( ramchain->Uextras != 0 )
if ( ramchain->Uextras != 0 )
utxo = ramchain->Uextras[spent_unspentind];
else if ( (hhutxo= iguana_hhutxofind(coin,ubuf,spent_hdrsi,spent_unspentind)) != 0 && hhutxo->u.spentflag != 0 )
utxo = hhutxo->u;
else
{
printf("null ramchain->Uextras unspentind.%u vs %u hdrs.%d\n",spent_unspentind,numunspents,spent_hdrsi);
@ -1098,7 +1098,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
S = (void *)(long)((long)rdata + rdata->Soffset);
B = (void *)(long)((long)rdata + rdata->Boffset);
T = (void *)(long)((long)rdata + rdata->Toffset);
if ( ramchain->Xspendinds == 0 )
if ( ramchain->Xspendinds == 0 && bp->hdrsi > 0 )
{
printf("iguana_balancegen.%d: no Xspendinds[%d]\n",bp->hdrsi,ramchain->numXspends);
return(-1);
@ -1310,8 +1310,6 @@ int32_t iguana_volatilesinit(struct iguana_info *coin)
iguana_bundlestats(coin,buf,IGUANA_DEFAULTLAG);
if ( (bp= coin->bundles[coin->balanceswritten-1]) != 0 && (block= iguana_blockfind("init",coin,bp->hashes[bp->n-1])) != 0 )
coin->blocks.hwmchain = *block;
//if ( (n= iguana_walkchain(coin,0)) > 0 )
// printf("iguana_walkchain n.%d vs hwmheight.%d\n",n,coin->blocks.hwmchain.height);
return(coin->balanceswritten);
}
@ -1344,7 +1342,10 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle)
if ( coin->balanceswritten > 1 )
{
for (i=0; i<coin->balanceswritten; i++)
{
//printf("%d ",i);
iguana_validateQ(coin,coin->bundles[i]);
}
}
printf("i.%d balanceswritten.%d\n",i,coin->balanceswritten);
if ( coin->balanceswritten < coin->bundlescount )
@ -1362,13 +1363,11 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle)
coin->origbalanceswritten = coin->balanceswritten;
iguana_volatilesinit(coin);
iguana_savehdrs(coin);
if ( 1 )
{
iguana_fastlink(coin,coin->balanceswritten * coin->chain->bundlesize - 1);
hash2 = iguana_blockhash(coin,coin->balanceswritten * coin->chain->bundlesize);
if ( bits256_nonz(hash2) != 0 && (block= iguana_blockfind("initfinal",coin,hash2)) != 0 )
_iguana_chainlink(coin,block);
}
iguana_fastlink(coin,coin->balanceswritten * coin->chain->bundlesize - 1);
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 )
_iguana_chainlink(coin,block);
}
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
@ -1754,7 +1753,7 @@ void iguana_RTspendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
iguana_convert(coin,bp,1);
printf("spendvectors converted to %d\n",coin->RTheight);
iguana_balancegen(coin,0,bp,coin->RTstarti,coin->RTheight-1);
printf("iguana_balancegen [%d] (%d to %d)\n",bp->hdrsi,coin->RTstarti,coin->RTheight-1);
printf("iguana_balancegen [%d] (%d to %d)\n",bp->hdrsi,coin->RTstarti,(coin->RTheight-1)%bp->n);
coin->RTstarti = (coin->RTheight % bp->n);
}
}
@ -1809,7 +1808,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
bundlei = (coin->RTheight % coin->chain->bundlesize);
block = iguana_bundleblock(coin,&hash2,bp,bundlei);
iguana_bundlehashadd(coin,bp,bundlei,block);
printf("RT.%d vs hwm.%d starti.%d bp->n %d block.%p/%p ramchain.%p\n",coin->RTheight,coin->blocks.hwmchain.height,coin->RTstarti,bp->n,block,bp->blocks[bundlei],dest->H.data);
//printf("RT.%d vs hwm.%d starti.%d bp->n %d block.%p/%p ramchain.%p\n",coin->RTheight,coin->blocks.hwmchain.height,coin->RTstarti,bp->n,block,bp->blocks[bundlei],dest->H.data);
if ( block != 0 && bits256_nonz(block->RO.prev_block) != 0 )
{
iguana_blocksetcounters(coin,block,dest);
@ -1866,14 +1865,62 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
return(flag);
}
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp)
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag)
{
if ( bp->validated <= 1 )
static int32_t totalerrs,totalvalidated;
FILE *fp; char fname[1024]; uint8_t *blockspace; int32_t i,max,len,errs = 0; int64_t total = 0;
if ( bp->validated <= 1 || forceflag != 0 )
{
sprintf(fname,"DB/%s/validated/%d",coin->symbol,bp->bundleheight);
if ( (fp= fopen(fname,"rb")) != 0 )
{
if ( forceflag == 0 )
{
if ( fread(&bp->validated,1,sizeof(bp->validated),fp) != sizeof(bp->validated) ||fread(&total,1,sizeof(total),fp) != sizeof(total) )
{
printf("error reading.(%s)\n",fname);
total = 0;
}
}
fclose(fp);
if ( forceflag != 0 )
OS_removefile(fname,1);
}
if ( forceflag != 0 || (total == 0 && bp->validated <= 1) )
{
max = sizeof(coin->blockspace);
blockspace = calloc(1,max);
for (i=0; i<bp->n; i++)
{
if ( (len= iguana_peerblockrequest(coin,blockspace,max,0,bp->hashes[i],1)) < 0 )
{
//printf("validate error.[%d:%d]\n",bp->hdrsi,i);
errs++;
//if ( deleteblock != 0 )
iguana_blockunmark(coin,bp->blocks[i],bp,i,1);
totalerrs++;
} else total += len, totalvalidated++;
}
free(blockspace);
bp->validated = (uint32_t)time(NULL);
printf("VALIDATED.[%d] errs.%d total.%lld %u | total errs.%d validated.%d\n",bp->bundleheight,errs,(long long)total,bp->validated,totalerrs,totalvalidated);
}
if ( errs == 0 && fp == 0 )
{
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(&bp->validated,1,sizeof(bp->validated),fp) != sizeof(bp->validated) || fwrite(&total,1,sizeof(total),fp) != sizeof(total) )
printf("error saving.(%s) total.%lld\n",fname,(long long)total);
fclose(fp);
}
}
}
if ( errs != 0 )
{
bp->validated = (uint32_t)time(NULL);
//printf("VALIDATE.%d %u\n",bp->bundleheight,bp->validated);
//printf("would have removed.[%d]\n",bp->hdrsi);
iguana_bundleremove(coin,bp->hdrsi);
}
return(0);
return(bp->n - errs);
}
#include "../includes/iguana_apidefs.h"

313
iguana/main.c

@ -59,9 +59,9 @@ int32_t Showmode,Autofold,PANGEA_MAXTHREADS = 1;
struct category_info *Categories;
struct iguana_info *Coins[IGUANA_MAXCOINS];
char Userhome[512],GLOBALTMPDIR[512] = "tmp";
int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel;
int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel,BIGENDIAN;
uint32_t prices777_NXTBLOCK,MAX_DEPTH = 100;
queue_t helperQ,jsonQ,finishedQ,bundlesQ,validateQ,emitQ;//,TerminateQ;
queue_t helperQ,jsonQ,finishedQ,bundlesQ,validateQ,emitQ,TerminateQ;
struct supernet_info MYINFO,**MYINFOS;
static int32_t initflag;
int32_t HDRnet,netBLOCKS;
@ -69,8 +69,12 @@ cJSON *API_json;
#ifdef __linux__
int32_t IGUANA_NUMHELPERS = 8;
#else
#ifdef __PNACL__
int32_t IGUANA_NUMHELPERS = 1;
#else
int32_t IGUANA_NUMHELPERS = 4;
#endif
#endif
struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char **retjsonstrp; char remoteaddr[64]; uint16_t port; char jsonstr[]; };
uint16_t SuperNET_API2num(char *agent,char *method)
@ -190,18 +194,18 @@ char *iguana_JSON(char *jsonstr,uint16_t port)
char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remoteaddr,uint16_t port)
{
cJSON *json; char *agent,*method,*retstr = 0;
char str[65]; printf("SuperNET_jsonstr %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey));
//char str[65]; printf("SuperNET_jsonstr %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey));
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
method = jstr(json,"method");
if ( method != 0 && is_bitcoinrpc(myinfo,method,remoteaddr) >= 0 )
retstr = iguana_bitcoinRPC(myinfo,method,json,remoteaddr,port);
else if ( (agent= jstr(json,"agent")) != 0 && method != 0 )
if ( (agent= jstr(json,"agent")) != 0 && method != 0 )
retstr = SuperNET_parser(myinfo,agent,method,json,remoteaddr);
else if ( method != 0 && is_bitcoinrpc(myinfo,method,remoteaddr) >= 0 )
retstr = iguana_bitcoinRPC(myinfo,method,json,remoteaddr,port);
else retstr = clonestr("{\"error\":\"need both agent and method\"}");
free_json(json);
} else retstr = clonestr("{\"error\":\"couldnt parse SuperNET_JSON\"}");
printf("SuperNET_jsonstr ret.(%s)\n",retstr);
//printf("SuperNET_jsonstr ret.(%s)\n",retstr);
return(retstr);
}
@ -262,7 +266,7 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t
char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port)
{
cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr,*method,*retjsonstr,*retstr = 0;
char str[65]; printf("processJSON %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey));
//char str[65]; printf("processJSON %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey));
if ( json != 0 )
{
if ( (tag= j64bits(json,"tag")) == 0 )
@ -279,7 +283,7 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote
return(clonestr("{\"result\":\"processed remote DHT\"}"));
}
jsonstr = jprint(json,0);
printf("RPC? (%s)\n",jsonstr);
//printf("RPC? (%s)\n",jsonstr);
if ( remoteaddr == 0 || jstr(json,"immediate") != 0 )
retjsonstr = SuperNET_jsonstr(myinfo,jsonstr,remoteaddr,port);
else retjsonstr = iguana_blockingjsonstr(myinfo,jsonstr,tag,timeout,remoteaddr,port);
@ -293,7 +297,7 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote
jadd64bits(retjson,"tag",tag);
}
retstr = jprint(retjson,1);
printf("retstr.(%s) retjsonstr.%p retjson.%p\n",retstr,retjsonstr,retjson);
//printf("retstr.(%s) retjsonstr.%p retjson.%p\n",retstr,retjsonstr,retjson);
free(retjsonstr);//,strlen(retjsonstr)+1);
} else retstr = retjsonstr;
}
@ -301,7 +305,7 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote
} else retstr = clonestr("{\"error\":\"cant parse JSON\"}");
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"null return\"}");
printf("processJSON.(%s)\n",retstr);
//printf("processJSON.(%s)\n",retstr);
return(retstr);
}
@ -351,6 +355,21 @@ void sigalarm_func() { printf("\nSIGALRM\n"); signal(SIGALRM,sigalarm_func); }
void sigcontinue_func() { printf("\nSIGCONT\n"); signal(SIGCONT,sigcontinue_func); }
#endif
void iguana_signalsinit()
{
#ifndef _WIN32
signal(SIGABRT,sigabort_func);
signal(SIGINT,sigint_func);
signal(SIGILL,sigillegal_func);
signal(SIGHUP,sighangup_func);
//signal(SIGKILL,sigkill_func);
signal(SIGQUIT,sigquit_func);
signal(SIGCHLD,sigchild_func);
signal(SIGALRM,sigalarm_func);
signal(SIGCONT,sigcontinue_func);
#endif
}
// mksquashfs DB/BTC BTC.squash -b 1048576 -> 19GB?
// mksquashfs DB/BTC BTC.lzo -comp lzo -b 1048576 -> takes a really long time -> 20GB
// mksquashfs DB/BTC BTC.xz -b 1048576 -comp xz -Xdict-size 512K -> takes a long time -> 16GB
@ -393,17 +412,24 @@ void mainloop(struct supernet_info *myinfo)
{
isRT *= coin->isRT;
numpeers += coin->peers.numranked;
if ( time(NULL) > coin->startutc+10 && coin->spendvectorsaved == 0 && coin->blocks.hwmchain.height >= coin->longestchain-3 )
if ( time(NULL) > coin->startutc+10 && coin->spendvectorsaved == 0 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->minconfirms)/coin->chain->bundlesize )
{
n = coin->bundlescount-1;
if ( iguana_emitfinished(coin) >= n )
if ( iguana_emitfinished(coin,1) >= n )
{
for (j=0; j<n; j++)
iguana_alloctxbits(coin,&coin->bundles[j]->ramchain);
if ( iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n )
{
coin->spendvectorsaved = 1;
else coin->spendvectorsaved = (uint32_t)time(NULL);
}
printf("start UTXOGEN\n");
}
else
{
coin->spendvectorsaved = (uint32_t)time(NULL);
printf("already done UTXOGEN (%d %d) (%d %d)\n",iguana_utxofinished(coin),n,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 )
{
@ -1082,67 +1108,69 @@ int maingen(int argc, char** argv)
return 0;
}
void iguana_main(void *arg)
void iguana_appletests(struct supernet_info *myinfo)
{
int32_t usessl = 0, ismainnet = 1; int32_t i; struct iguana_info *btcd=0; //*btc=0,
struct supernet_info *myinfo; char *helperargs,*coinargs,helperstr[512];
mycalloc(0,0,0);
myinfo = SuperNET_MYINFO(0);
FILE *fp; int32_t iter; void ztest(); ztest();
strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7876/nxt");
for (iter=0; iter<2; iter++)
char *str; struct iguana_info *btcd;
void ztest(); ztest();
//iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD
//iguana_chaingenesis(1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN
//char genesisblock[1024];
//iguana_chaingenesis(genesisblock,"sha256",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC
if ( 1 )
{
if ( (fp= fopen(iter == 0 ? "nxtpasswords" : "fimpasswords","rb")) != 0 )
btcd = iguana_coinadd("BTCD",0);
if ( btcd == 0 )
{
char line[4096],NXTaddr[64]; int32_t j; uint8_t pubkey[32];
while ( fgets(line,sizeof(line),fp) > 0 )
printf("error adding BTCD.%p\n",btcd);
exit(-1);
}
sleep(1);
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"VALIDATE\":1,\"prefetchlag\":13,\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":10}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":1024,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0,myinfo->rpcport)) != 0 )
{
j = (int32_t)strlen(line) - 1;
line[j] = 0;
calc_NXTaddr(NXTaddr,pubkey,(uint8_t *)line,j);
printf("FORGING %s (%s)\n",NXTaddr,issue_startForging(myinfo,line));
free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"bob\",\"password\":\"bob\",\"passphrase\":\"bob\"}"),0,myinfo->rpcport)) != 0 )
free(str);
}
}
fclose(fp);
}
strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7886/nxt");
sleep(1);
}
if ( usessl == 0 )
strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:");
else strcpy(myinfo->NXTAPIURL,"https://127.0.0.1:");
if ( ismainnet != 0 )
strcat(myinfo->NXTAPIURL,"7876/nxt");
else strcat(myinfo->NXTAPIURL,"6876/nxt");
if ( 0 )
{
#ifndef _WIN32
signal(SIGABRT,sigabort_func);
signal(SIGINT,sigint_func);
signal(SIGILL,sigillegal_func);
signal(SIGHUP,sighangup_func);
//signal(SIGKILL,sigkill_func);
signal(SIGQUIT,sigquit_func);
signal(SIGCHLD,sigchild_func);
signal(SIGALRM,sigalarm_func);
signal(SIGCONT,sigcontinue_func);
#endif
int32_t i,n; int64_t total; char *coinaddr; struct iguana_pkhash *P; struct iguana_info *coin; uint8_t rmd160[20],addrtype,pubkey33[33]; double startmillis;
coin = iguana_coinfind("BTCD");
if ( 1 && coin != 0 )
{
getchar();
for (i=0; i<coin->bundlescount; i++)
if ( coin->bundles[i] == 0 )
break;
coinaddr = "RUZ9AKxy6J2okcBd1PZm4YH6atmPwqV4bo";
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
P = calloc(coin->bundlescount,sizeof(*P));
memset(pubkey33,0,sizeof(pubkey33));
n = iguana_pkhasharray(coin,0,0,0,&total,P,coin->bundlescount,rmd160,coinaddr,pubkey33);
printf("%s has total outputs %.8f from %d bundles\n",coinaddr,dstr(total),n);
startmillis = OS_milliseconds();
for (i=0; i<1000; i++)
n = iguana_pkhasharray(coin,0,0,0,&total,P,coin->bundlescount,rmd160,coinaddr,pubkey33);
printf("%s has total outputs %.8f from %d bundles %.3f millis\n",coinaddr,dstr(total),n,OS_milliseconds()-startmillis);
getchar();
}
}
//iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD
//iguana_chaingenesis(1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN
//char genesisblock[1024];
//iguana_chaingenesis(genesisblock,"sha256",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC
}
iguana_initQ(&helperQ,"helperQ");
iguana_initQ(&jsonQ,"jsonQ");
iguana_initQ(&emitQ,"emitQ");
iguana_initQ(&finishedQ,"finishedQ");
iguana_initQ(&bundlesQ,"bundlesQ");
iguana_initQ(&validateQ,"validateQ");
myinfo->rpcport = IGUANA_RPCPORT;
strcpy(myinfo->rpcsymbol,"BTCD");
void iguana_commandline(struct supernet_info *myinfo,char *arg)
{
cJSON *argjson; char *coinargs;
if ( arg != 0 )
{
cJSON *argjson;
if ( (argjson= cJSON_Parse(arg)) != 0 )
{
IGUANA_NUMHELPERS = juint(argjson,"numhelpers");
@ -1161,17 +1189,38 @@ void iguana_main(void *arg)
printf("call argv JSON.(%s)\n",(char *)arg);
SuperNET_JSON(myinfo,argjson,0,myinfo->rpcport);
free_json(argjson);
if ( (coinargs= SuperNET_keysinit(myinfo,arg)) != 0 )
iguana_launch(0,"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
} else printf("error parsing.(%s)\n",(char *)arg);
}
}
void iguana_ensuredirs()
{
OS_ensure_directory("help");
OS_ensure_directory("confs");
OS_ensure_directory("DB"), OS_ensure_directory("DB/ECB");
OS_ensure_directory("DB");
OS_ensure_directory("DB/ECB");
OS_ensure_directory("tmp");
OS_ensure_directory("purgeable");
OS_ensure_directory("purgeable/BTC");
OS_ensure_directory("purgeable/BTCD");
OS_ensure_directory(GLOBALTMPDIR);
#ifndef __PNACL__
}
void iguana_Qinit()
{
iguana_initQ(&helperQ,"helperQ");
iguana_initQ(&jsonQ,"jsonQ");
iguana_initQ(&finishedQ,"finishedQ");
iguana_initQ(&bundlesQ,"bundlesQ");
iguana_initQ(&validateQ,"validateQ");
iguana_initQ(&emitQ,"emitQ");
iguana_initQ(&TerminateQ,"TerminateQ");
}
void iguana_helpinit(struct supernet_info *myinfo)
{
char *tmpstr;
if ( (tmpstr= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"help\"}"),0,myinfo->rpcport)) != 0 )
{
@ -1180,78 +1229,92 @@ void iguana_main(void *arg)
free(tmpstr);
}
printf("generated API_json\n");
#endif
if ( IGUANA_NUMHELPERS == 0 )
IGUANA_NUMHELPERS = 1;
iguana_initQ(&TerminateQ,"TerminateQ");
category_init(myinfo);
if ( (coinargs= SuperNET_keysinit(myinfo,arg)) != 0 )
{
//iguana_launch(btcd,"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
}
btcd = iguana_coinadd("BTCD",0);
iguana_coinadd("BTC",0);
#ifdef __APPLE__
if ( 1 )
}
void iguana_urlinit(struct supernet_info *myinfo,int32_t ismainnet,int32_t usessl)
{
int32_t iter,j; FILE *fp; char line[4096],NXTaddr[64]; uint8_t pubkey[32];
strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7876/nxt");
for (iter=0; iter<2; iter++)
{
char *str;
if ( btcd == 0 )
{
printf("error adding BTCD.%p\n",btcd);
exit(-1);
}
sleep(1);
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"VALIDATE\":1,\"prefetchlag\":13,\"startpend\":1,\"endpend\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
if ( (fp= fopen(iter == 0 ? "nxtpasswords" : "fimpasswords","rb")) != 0 )
{
free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":1024,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0,myinfo->rpcport)) != 0 )
while ( fgets(line,sizeof(line),fp) > 0 )
{
free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"bob\",\"password\":\"bob\",\"passphrase\":\"bob\"}"),0,myinfo->rpcport)) != 0 )
free(str);
}
j = (int32_t)strlen(line) - 1;
line[j] = 0;
calc_NXTaddr(NXTaddr,pubkey,(uint8_t *)line,j);
printf("FORGING %s (%s)\n",NXTaddr,issue_startForging(myinfo,line));
}
fclose(fp);
}
sleep(1);
}
if ( 0 )
{
int32_t i,n; int64_t total; char *coinaddr; struct iguana_pkhash *P; struct iguana_info *coin; uint8_t rmd160[20],addrtype,pubkey33[33]; double startmillis;
coin = iguana_coinfind("BTCD");
if ( 0 && coin != 0 )
{
getchar();
for (i=0; i<coin->bundlescount; i++)
if ( coin->bundles[i] == 0 )
break;
if ( i > 0 )
iguana_spentsfile(coin,i);
coinaddr = "RUZ9AKxy6J2okcBd1PZm4YH6atmPwqV4bo";
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
P = calloc(coin->bundlescount,sizeof(*P));
memset(pubkey33,0,sizeof(pubkey33));
n = iguana_pkhasharray(coin,0,0,0,&total,P,coin->bundlescount,rmd160,coinaddr,pubkey33);
printf("%s has total outputs %.8f from %d bundles\n",coinaddr,dstr(total),n);
startmillis = OS_milliseconds();
for (i=0; i<1000; i++)
n = iguana_pkhasharray(coin,0,0,0,&total,P,coin->bundlescount,rmd160,coinaddr,pubkey33);
printf("%s has total outputs %.8f from %d bundles %.3f millis\n",coinaddr,dstr(total),n,OS_milliseconds()-startmillis);
getchar();
}
strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7886/nxt");
}
#endif
if ( usessl == 0 )
strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:");
else strcpy(myinfo->NXTAPIURL,"https://127.0.0.1:");
if ( ismainnet != 0 )
strcat(myinfo->NXTAPIURL,"7876/nxt");
else strcat(myinfo->NXTAPIURL,"6876/nxt");
}
void iguana_launchdaemons(struct supernet_info *myinfo)
{
int32_t i; char *helperargs,helperstr[512];
if ( IGUANA_NUMHELPERS == 0 )
IGUANA_NUMHELPERS = 1;
for (i=0; i<IGUANA_NUMHELPERS; i++)
{
sprintf(helperstr,"{\"helperid\":%d}",i);
helperargs = clonestr(helperstr);
printf("launch[%d] of %d (%s)\n",i,IGUANA_NUMHELPERS,helperstr);
iguana_launch(btcd,"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD);
iguana_launch(0,"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD);
}
iguana_launch(btcd,"rpcloop",iguana_rpcloop,myinfo,IGUANA_PERMTHREAD);
iguana_launch(0,"rpcloop",iguana_rpcloop,myinfo,IGUANA_PERMTHREAD);
printf("launch mainloop\n");
mainloop(myinfo);
}
int32_t iguana_isbigendian()
{
int32_t i,littleendian,bigendian; uint64_t val = 0x0001020304050607;
for (i=bigendian=littleendian=0; i<sizeof(val); i++)
{
if ( ((uint8_t *)&val)[i] == i )
bigendian++;
else if ( ((uint8_t *)&val)[sizeof(val)-1-i] == i )
littleendian++;
}
if ( littleendian == sizeof(val) )
return(0);
else if ( bigendian == sizeof(val) )
return(1);
else return(-1);
}
void iguana_main(void *arg)
{
int32_t usessl = 0, ismainnet = 1; struct supernet_info *myinfo;
if ( (BIGENDIAN= iguana_isbigendian()) > 0 )
printf("BIGENDIAN\n");
else if ( BIGENDIAN == 0 )
printf("LITTLE ENDIAN\n");
else printf("ENDIAN ERROR\n");
mycalloc(0,0,0);
if ( 0 )
iguana_signalsinit();
iguana_ensuredirs();
iguana_Qinit();
myinfo = SuperNET_MYINFO(0);
myinfo->rpcport = IGUANA_RPCPORT;
strcpy(myinfo->rpcsymbol,"BTCD");
iguana_urlinit(myinfo,ismainnet,usessl);
category_init(myinfo);
iguana_helpinit(myinfo);
iguana_commandline(myinfo,arg);
#ifdef __APPLE__
iguana_appletests(myinfo);
#endif
iguana_launchdaemons(myinfo);
}

97
iguana/ramchain_api.c

@ -16,6 +16,56 @@
#include "iguana777.h"
#include "../includes/iguana_apidefs.h"
STRING_ARG(iguana,validate,activecoin)
{
int32_t i,total,validated; struct iguana_bundle *bp; cJSON *retjson;
if ( (coin= iguana_coinfind(activecoin)) != 0 )
{
for (i=total=validated=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 )
{
validated += iguana_bundlevalidate(coin,bp,1);
total += bp->n;
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","validation run");
jaddstr(retjson,"coin",coin->symbol);
jaddnum(retjson,"validated",validated);
jaddnum(retjson,"total",total);
jaddnum(retjson,"bundles",coin->bundlescount);
jaddnum(retjson,"accuracy",(double)validated/total);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no active coin\"}"));
}
STRING_ARG(iguana,removecoin,activecoin)
{
struct iguana_bundle *bp; int32_t i; char fname[1024];
if ( (coin= iguana_coinfind(activecoin)) != 0 )
{
coin->active = 0;
coin->started = 0;
for (i=0; i<IGUANA_MAXPEERS; i++)
{
sprintf(fname,"DB/%s/vouts/%04d.vouts",coin->symbol,i), OS_removefile(fname,0);
sprintf(fname,"purgeable/%s/%04d.vins",coin->symbol,i), OS_removefile(fname,0);
}
sprintf(fname,"DB/%s/vouts/*",coin->symbol), OS_removefile(fname,0);
sprintf(fname,"purgeable/%s/*",coin->symbol), OS_removefile(fname,0);
for (i=0; i<coin->bundlescount; i++)
{
sprintf(fname,"DB/%s/balancecrc.%d",coin->symbol,i), OS_removefile(fname,0);
if ( (bp= coin->bundles[i]) != 0 )
{
iguana_bundlepurgefiles(coin,bp);
iguana_bundleremove(coin,bp->hdrsi);
}
}
sprintf(fname,"DB/%s/*",coin->symbol), OS_removefile(fname,0);
}
return(clonestr("{\"error\":\"no active coin\"}"));
}
char *iguana_APIrequest(struct iguana_info *coin,bits256 blockhash,bits256 txid,int32_t seconds)
{
int32_t i,len; char *retstr = 0; uint8_t serialized[1024]; char str[65];
@ -49,44 +99,27 @@ INT_ARG(bitcoinrpc,getblockhash,height)
return(jprint(retjson,1));
}
HASH_AND_INT(bitcoinrpc,getblock,blockhash,remoteonly)
HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly)
{
char *blockstr; struct iguana_msgblock msg; struct iguana_block *block; cJSON *retjson; bits256 txid;
char *blockstr,*datastr; struct iguana_msgblock msg; struct iguana_block *block; cJSON *retjson; bits256 txid; int32_t len;
retjson = cJSON_CreateObject();
memset(&msg,0,sizeof(msg));
if ( remoteonly == 0 && (block= iguana_blockfind("getblockRPC",coin,blockhash)) != 0 )
{
return(jprint(iguana_blockjson(coin,block,1),1));
/* int32_t len,i; char str[65],hexstr[(sizeof(uint32_t)+sizeof(struct iguana_msgblock))*2+1],*blockstr;
uint8_t serialized[sizeof(uint32_t)+sizeof(struct iguana_msgblock)]; bits256 hash2,txid;
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;
msg.H.nonce = block->RO.nonce;
msg.txn_count = block->RO.txn_count;
jaddnum(retjson,"version",msg.H.version);
jaddnum(retjson,"timestamp",msg.H.timestamp);
jaddstr(retjson,"utc",utc_str(str,msg.H.timestamp));
serialized[0] = ((uint8_t *)&msg.H.bits)[3];
serialized[1] = ((uint8_t *)&msg.H.bits)[2];
serialized[2] = ((uint8_t *)&msg.H.bits)[1];
serialized[3] = ((uint8_t *)&msg.H.bits)[0];
init_hexbytes_noT(hexstr,serialized,sizeof(uint32_t));
jaddstr(retjson,"nBits",hexstr);
jaddnum(retjson,"nonce",msg.H.nonce);
jaddbits256(retjson,"merkle_root",msg.H.merkle_root);
jaddnum(retjson,"txn_count",msg.txn_count);
array = cJSON_CreateArray();
for (i=0; i<msg.txn_count; i++)
if ( verbose != 0 )
return(jprint(iguana_blockjson(coin,block,1),1));
else
{
if ( (len= iguana_peerblockrequest(coin,coin->blockspace,sizeof(coin->blockspace),0,blockhash,0)) > 0 )
{
datastr = malloc(len*2 + 1);
init_hexbytes_noT(datastr,coin->blockspace,len);
jaddstr(retjson,"result",datastr);
free(datastr);
return(jprint(retjson,1));
}
jaddstr(retjson,"error","error getting rawblock");
}
jadd(retjson,"txids",array);
len = iguana_rwblock(1,&hash2,serialized,&msg);
char str[65]; printf("timestamp.%u bits.%u nonce.%u v.%d (%s) len.%d (%ld %ld)\n",block->RO.timestamp,block->RO.bits,block->RO.nonce,block->RO.version,bits256_str(str,hash2),len,sizeof(serialized),sizeof(hexstr));
init_hexbytes_noT(hexstr,serialized,len);
jaddstr(retjson,"result",hexstr);*/
}
else if ( coin->APIblockstr != 0 )
jaddstr(retjson,"error","already have pending request");
@ -108,7 +141,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose)
if ( (tx= iguana_txidfind(coin,&height,&T,txid,coin->bundlescount-1)) != 0 )
{
retjson = cJSON_CreateObject();
if ( (len= iguana_ramtxbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0)) > 0 )
if ( (len= iguana_ramtxbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0,0)) > 0 )
{
txbytes = calloc(1,len*2+1);
init_hexbytes_noT(txbytes,coin->blockspace,len);

4
includes/iguana_apideclares.h

@ -27,7 +27,7 @@ STRING_AND_INT(iguana,bundleaddresses,base,height);
HASH_AND_STRING(bitcoinrpc,verifytx,txid,txbytes);
INT_ARG(bitcoinrpc,getblockhash,height);
HASH_AND_INT(bitcoinrpc,getblock,blockhash,remoteonly);
HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly);
HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose);
HASH_ARG(bitcoinrpc,gettransaction,txid);
STRING_ARG(bitcoinrpc,decoderawtransaction,rawtx);
@ -135,6 +135,8 @@ STRING_ARG(iguana,peers,activecoin);
STRING_AND_INT(iguana,maxpeers,activecoin,max);
STRING_ARG(iguana,getconnectioncount,activecoin);
STRING_ARG(iguana,addcoin,newcoin);
STRING_ARG(iguana,validate,activecoin);
STRING_ARG(iguana,removecoin,activecoin);
STRING_ARG(iguana,startcoin,activecoin);
STRING_ARG(iguana,pausecoin,activecoin);
STRING_ARG(iguana,stopcoin,activecoin);

Loading…
Cancel
Save