Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
61a45d091b
  1. 2
      crypto777/iguana_OS.c
  2. 20
      iguana/iguana777.c
  3. 18
      iguana/iguana777.h
  4. 2
      iguana/iguana_blocks.c
  5. 4
      iguana/iguana_bundles.c
  6. 94
      iguana/iguana_init.c
  7. 10
      iguana/iguana_json.c
  8. 4
      iguana/iguana_ramchain.c
  9. 14
      iguana/iguana_recv.c
  10. 159
      iguana/iguana_unspents.c
  11. 22
      iguana/iguana_wallet.c
  12. 13
      iguana/main.c
  13. 1
      includes/iguana_apideclares.h

2
crypto777/iguana_OS.c

@ -149,6 +149,8 @@ void _myfree(uint8_t type,int32_t origallocsize,void *origptr,int32_t allocsize)
else
{
printf("myfree size error %d vs %d at %p\n",allocsize,origallocsize,origptr);
static int32_t y,z;
printf("div by zero! %d\n",y/z);
getchar();
}
//portable_mutex_unlock(&MEMmutex);

20
iguana/iguana777.c

@ -433,14 +433,6 @@ void iguana_coinloop(void *arg)
printf("begin coinloop[%d]\n",n);
for (i=0; i<n; i++)
{
if ( (coin= coins[i]) != 0 && coin->started == 0 )
{
iguana_rwiAddrind(coin,0,0,0);
iguana_coinstart(coin,coin->initialheight,coin->mapflags);
printf("init.(%s) maxpeers.%d maxrecvcache.%s services.%llx MAXMEM.%s polltimeout.%d cache.%d pend.(%d -> %d)\n",coin->symbol,coin->MAXPEERS,mbstr(str,coin->MAXRECVCACHE),(long long)coin->myservices,mbstr(str,coin->MAXMEM),coin->polltimeout,coin->enableCACHE,coin->startPEND,coin->endPEND);
coin->started = coin;
coin->chain->minconfirms = coin->minconfirms;
}
}
coin = coins[0];
iguana_possible_peer(coin,"127.0.0.1");
@ -455,8 +447,17 @@ void iguana_coinloop(void *arg)
{
if ( (coin= coins[i]) != 0 )
{
if ( coin->started == 0 && coin->active != 0 )
{
iguana_rwiAddrind(coin,0,0,0);
iguana_coinstart(coin,coin->initialheight,coin->mapflags);
printf("init.(%s) maxpeers.%d maxrecvcache.%s services.%llx MAXMEM.%s polltimeout.%d cache.%d pend.(%d -> %d)\n",coin->symbol,coin->MAXPEERS,mbstr(str,coin->MAXRECVCACHE),(long long)coin->myservices,mbstr(str,coin->MAXMEM),coin->polltimeout,coin->enableCACHE,coin->startPEND,coin->endPEND);
coin->started = coin;
coin->chain->minconfirms = coin->minconfirms;
}
now = (uint32_t)time(NULL);
if ( coin->active != 0 )
coin->idletime = 0;
if ( coin->started != 0 && coin->active != 0 )
{
if ( coin->isRT == 0 && now > coin->startutc+77 && coin->numsaved >= (coin->longestchain/coin->chain->bundlesize)*coin->chain->bundlesize && coin->blocks.hwmchain.height >= coin->longestchain-30 )
{
@ -498,6 +499,7 @@ void iguana_coinloop(void *arg)
if ( coin->longestchain+10000 > coin->blocks.maxbits )
iguana_recvalloc(coin,coin->longestchain + 100000);
}
coin->idletime = (uint32_t)time(NULL);
}
}
if ( flag == 0 )

18
iguana/iguana777.h

@ -179,6 +179,8 @@ struct iguana_thread
void *arg;
};
struct iguana_blockreq { struct queueitem DL; bits256 hash2,*blockhashes; struct iguana_bundle *bp; int32_t n,height,bundlei; };
struct iguana_chain
{
//const int32_t chain_id;
@ -282,7 +284,7 @@ struct iguana_block
double PoW; // NOT consensus safe, for estimation purposes only
int32_t height; uint32_t fpipbits,numrequests,issued; long fpos;
uint16_t hdrsi,bundlei:11,mainchain:1,valid:1,queued:1,txvalid:1,newtx:1,peerid:8;
UT_hash_handle hh; bits256 *blockhashes; struct iguana_bundlereq *req;
UT_hash_handle hh; struct iguana_bundlereq *req; //bits256 *blockhashes;
};// __attribute__((packed));
@ -426,10 +428,10 @@ struct iguana_bloominds { uint16_t inds[8]; };
struct iguana_bundle
{
struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp;
struct iguana_bloom16 bloom; uint32_t rawscriptspace;
struct iguana_bloom16 bloom; //uint32_t rawscriptspace;
uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,utxofinish,balancefinish,validated,lastspeculative,dirty,nexttime,currenttime,lastprefetch;
int32_t numhashes,numrecv,numsaved,numcached,generrs,checkedtmp,currentflag;
int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec;
int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec,isRT;
double avetime,threshold,metric; uint64_t datasize,estsize;
struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE]; uint32_t issued[IGUANA_MAXBUNDLESIZE];
bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash,*speculative;
@ -461,8 +463,8 @@ struct iguana_info
uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime;
int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,estsize,activebundles;
int32_t MAXPEERS,MAXPENDING,MAXBUNDLES,active,closestbundle,numemitted,lastsweep,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,balanceswritten,RTheight; bits256 balancehash;
uint32_t lastsync,parsetime,numiAddrs,firstblock,lastpossible,bundlescount,savedblocks,backlog;
int32_t longestchain,badlongestchain,longestchain_strange;
uint32_t lastsync,parsetime,numiAddrs,lastpossible,bundlescount,savedblocks,backlog;
int32_t longestchain,badlongestchain,longestchain_strange,RTramchain_busy;
struct tai starttime; double startmillis;
struct iguana_chain *chain;
struct iguana_iAddr *iAddrs;
@ -473,12 +475,12 @@ struct iguana_info
queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ;
double parsemillis,avetime; uint32_t Launched[8],Terminated[8];
portable_mutex_t peers_mutex,blocks_mutex;
portable_mutex_t scripts_mutex[2]; FILE *scriptsfp[2]; void *scriptsptr[2]; long scriptsfilesize[2];
//portable_mutex_t scripts_mutex[2]; FILE *scriptsfp[2]; void *scriptsptr[2]; long scriptsfilesize[2];
//struct scriptinfo *scriptstable[2];
struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending;
struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem;
int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified;
uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis;
uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,idletime;
double backstopmillis; bits256 backstophash2; int64_t spaceused;
int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes; bits256 reqtxids[64];
void *launched,*started;
@ -818,6 +820,8 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei);
int32_t iguana_mapchaininit(struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize);
void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp);
void iguana_RTramchainfree(struct iguana_info *coin);
void iguana_coinpurge(struct iguana_info *coin);
extern int32_t HDRnet,netBLOCKS;

2
iguana/iguana_blocks.c

@ -66,7 +66,7 @@ struct iguana_block *iguana_blockhashset(struct iguana_info *coin,int32_t height
}
if ( createflag > 0 )
{
block = mycalloc('x',1,sizeof(*block));
block = calloc(1,sizeof(*block));
block->RO.hash2 = hash2;
block->hh.itemind = height, block->height = -1;
HASH_ADD(hh,coin->blocks.hash,RO.hash2,sizeof(hash2),block);

4
iguana/iguana_bundles.c

@ -365,7 +365,7 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl
return(0);
}
void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp)
void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
{
static bits256 zero;
char fname[1024]; int32_t hdrsi,m,j; uint32_t ipbits;
@ -1029,7 +1029,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
done++;
numemit++;
if ( firstgap != 0 && bp->hdrsi > firstgap->hdrsi-3 )
iguana_bundlepurge(coin,bp);
iguana_bundlepurgefiles(coin,bp);
}
else
{

94
iguana/iguana_init.c

@ -56,8 +56,8 @@ 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]);
//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;
@ -322,6 +322,89 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
}
}
void iguana_ramchainpurge(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain)
{
}
void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp)
{
static bits256 zero;
if ( bp->speculative != 0 )
myfree(bp->speculative,sizeof(*bp->speculative) * bp->numspec);
bp->numspec = 0;
bp->speculative = 0;
memset(bp->hashes,0,sizeof(bp->hashes));
memset(bp->issued,0,sizeof(bp->issued));
bp->prevbundlehash2 = bp->nextbundlehash2 = bp->allhash = zero;
iguana_ramchain_free(coin,&bp->ramchain,1);
}
void iguana_blockpurge(struct iguana_info *coin,struct iguana_block *block)
{
if ( block->req != 0 )
{
printf("purge req inside block\n");
myfree(block->req,block->req->allocsize);
}
free(block);
}
void iguana_blockspurge(struct iguana_info *coin)
{
struct iguana_block *block,*tmp;
if ( coin->blocks.hash != 0 )
{
HASH_ITER(hh,coin->blocks.hash,block,tmp)
{
HASH_DEL(coin->blocks.hash,block);
iguana_blockpurge(coin,block);
}
coin->blocks.hash = 0;
}
if ( coin->blocks.RO != 0 )
{
myfree(coin->blocks.RO,coin->blocks.maxbits * sizeof(*coin->blocks.RO));
coin->blocks.RO = 0;
}
coin->blocks.maxbits = coin->blocks.maxblocks = coin->blocks.initblocks = coin->blocks.hashblocks = coin->blocks.issuedblocks = coin->blocks.recvblocks = coin->blocks.emitblocks = coin->blocks.parsedblocks = coin->blocks.dirty = 0;
memset(&coin->blocks.hwmchain,0,sizeof(coin->blocks.hwmchain));
}
void iguana_coinpurge(struct iguana_info *coin)
{
int32_t i; struct iguana_bundle *bp; char *hashstr; struct iguana_bundlereq *req; struct iguana_blockreq *breq;
coin->started = 0; coin->active = 0;
while ( (hashstr= queue_dequeue(&coin->hdrsQ,1)) != 0 )
free_queueitem(hashstr);
while ( (breq= queue_dequeue(&coin->blocksQ,0)) != 0 )
myfree(breq,sizeof(*breq));
while ( (breq= queue_dequeue(&coin->priorityQ,0)) != 0 )
myfree(breq,sizeof(*breq));
while ( (req= queue_dequeue(&coin->cacheQ,0)) != 0 )
myfree(req,req->allocsize);
while ( (req= queue_dequeue(&coin->recvQ,0)) != 0 )
{
if ( req->blocks != 0 )
myfree(req->blocks,sizeof(*req->blocks) * req->n), req->blocks = 0;
if ( req->hashes != 0 )
myfree(req->hashes,sizeof(*req->hashes) * req->n), req->hashes = 0;
myfree(req,req->allocsize);
}
while ( coin->idletime == 0 )
{
printf("coinpurge.%s waiting for idle %lu\n",coin->symbol,time(NULL));
sleep(1);
}
iguana_RTramchainfree(coin);
coin->bundlescount = 0;
for (i=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 )
iguana_bundlepurge(coin,bp);
coin->current = coin->lastpending = 0;
memset(coin->bundles,0,sizeof(coin->bundles));
iguana_blockspurge(coin);
}
struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags)
{
FILE *fp; char fname[512],*symbol; int32_t iter;
@ -331,8 +414,9 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
initialheight = coin->chain->bundlesize*10;
iguana_recvalloc(coin,initialheight);
coin->longestchain = 1;
memset(&coin->blocks.hwmchain,0,sizeof(coin->blocks.hwmchain));
coin->blocks.hwmchain.height = 0;
if ( (coin->myservices & NODE_NETWORK) != 0 )
if ( (coin->myservices & NODE_NETWORK) != 0 && coin->peers.acceptloop == 0 )
{
printf("MYSERVICES.%llx\n",(long long)coin->myservices);
coin->peers.acceptloop = malloc(sizeof(pthread_t));
@ -343,7 +427,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
printf("error launching accept thread for port.%u\n",coin->chain->portp2p);
}
}
coin->firstblock = coin->blocks.parsedblocks + 1;
//coin->firstblock = coin->blocks.parsedblocks + 1;
iguana_genesis(coin,coin->chain);
for (iter=0; iter<2; iter++)
{
@ -360,6 +444,6 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
#ifndef IGUANA_DEDICATED_THREADS
coin->peers.peersloop = iguana_launch("peersloop",iguana_peersloop,coin,IGUANA_PERMTHREAD);
#endif
printf("started.%s\n",coin->symbol);
printf("started.%s %p active.%d\n",coin->symbol,coin->started,coin->active);
return(coin);
}

10
iguana/iguana_json.c

@ -621,6 +621,16 @@ STRING_ARG(iguana,startcoin,activecoin)
} else return(clonestr("{\"error\":\"startcoin needs coin\"}"));
}
STRING_ARG(iguana,stopcoin,activecoin)
{
if ( coin != 0 )
{
coin->active = 0;
iguana_coinpurge(coin);
return(clonestr("{\"result\":\"coin stopped\"}"));
} else return(clonestr("{\"error\":\"stopcoin needs coin\"}"));
}
STRING_ARG(iguana,pausecoin,activecoin)
{
if ( coin != 0 )

4
iguana/iguana_ramchain.c

@ -2004,7 +2004,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
bp->numtxids += ramchain->H.data->numtxids;
bp->numunspents += ramchain->H.data->numunspents;
bp->numspends += ramchain->H.data->numspends;
bp->rawscriptspace += ramchain->H.data->scriptspace;
//bp->rawscriptspace += ramchain->H.data->scriptspace;
}
iguana_ramchain_free(coin,&R,1);
}
@ -2013,7 +2013,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
bp->numtxids += ramchain->H.data->numtxids;
bp->numunspents += ramchain->H.data->numunspents;
bp->numspends += ramchain->H.data->numspends;
bp->rawscriptspace += ramchain->H.data->scriptspace;
//bp->rawscriptspace += ramchain->H.data->scriptspace;
}
if ( fpos >= 0 )
block->fpos = fpos, block->fpipbits = (uint32_t)addr->ipbits;

14
iguana/iguana_recv.c

@ -484,8 +484,8 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
}
prevbp = 0, prevbundlei = -2;
iguana_bundlefind(coin,&prevbp,&prevbundlei,prevhash2);
if ( 0 && block->blockhashes != 0 )
fprintf(stderr,"has blockhashes bp.%p[%d] prevbp.%p[%d]\n",bp,bundlei,prevbp,prevbundlei);
//if ( 0 && block->blockhashes != 0 )
// fprintf(stderr,"has blockhashes bp.%p[%d] prevbp.%p[%d]\n",bp,bundlei,prevbp,prevbundlei);
if ( prevbp != 0 && prevbundlei >= 0 && (prevblock= iguana_blockfind(coin,prevhash2)) != 0 )
{
if ( prevbundlei < coin->chain->bundlesize )
@ -816,7 +816,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
if ( (prev= iguana_blockfind(coin,block->RO.prev_block)) == 0 )
prev = iguana_blockhashset(coin,-1,block->RO.prev_block,1);
width = sqrt(coin->chain->bundlesize);
while ( prev != 0 && width-- > 0 )
while ( coin->active != 0 && prev != 0 && width-- > 0 )
{
if ( prev->mainchain != 0 )
break;
@ -961,7 +961,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}*/
lflag = 1;
while ( lflag != 0 )
while ( coin->active != 0 && lflag != 0 )
{
lflag = 0;
hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize;
@ -1085,7 +1085,7 @@ int32_t iguana_processrecvQ(struct iguana_info *coin,int32_t *newhwmp) // single
{
int32_t flag = 0; struct iguana_bundlereq *req;
*newhwmp = 0;
while ( (req= queue_dequeue(&coin->recvQ,0)) != 0 )
while ( coin->active != 0 && (req= queue_dequeue(&coin->recvQ,0)) != 0 )
{
//fprintf(stderr,"%s recvQ.%p type.%c n.%d\n",req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n);
if ( req->type == 'B' ) // one block with all txdata
@ -1140,7 +1140,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
int32_t i,lag,n = 0; struct iguana_bundle *bp; char hashstr[65];
if ( queue_size(&coin->hdrsQ) == 0 )
{
//if ( iguana_needhdrs(coin) > 0 )
if ( coin->active != 0 )
{
for (i=0; i<coin->bundlescount; i++)
{
@ -1177,8 +1177,6 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
return(n);
}
struct iguana_blockreq { struct queueitem DL; bits256 hash2,*blockhashes; struct iguana_bundle *bp; int32_t n,height,bundlei; };
int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t priority)
{
queue_t *Q; char *str; int32_t n,height = -1; struct iguana_blockreq *req; struct iguana_block *block = 0;

159
iguana/iguana_unspents.c

@ -121,59 +121,6 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
return(-1);
}
struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_ramchain **ramchainp,int64_t *balancep,uint32_t *lastunspentindp,struct iguana_pkhash *p,uint8_t rmd160[20],int32_t firsti,int32_t endi)
{
uint8_t *PKbits; struct iguana_pkhash *P; uint32_t pkind,i; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_account *ACCTS;
*balancep = 0;
*ramchainp = 0;
*lastunspentindp = 0;
for (i=firsti; i<coin->bundlescount&&i<=endi; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
{
ramchain = &bp->ramchain;
if ( ramchain->H.data != 0 )
{
PKbits = (void *)(long)((long)ramchain->H.data + ramchain->H.data->PKoffset);
P = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Poffset);
ACCTS = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Aoffset);
if ( (pkind= iguana_sparseaddpk(PKbits,ramchain->H.data->pksparsebits,ramchain->H.data->numpksparse,rmd160,P,0)) > 0 && pkind < ramchain->H.data->numpkinds )
{
*ramchainp = ramchain;
*balancep = ACCTS[pkind].total;
*lastunspentindp = ACCTS[pkind].lastunspentind;
*p = P[pkind];
return(p);
} //else printf("not found pkind.%d vs num.%d\n",pkind,ramchain->H.data->numpkinds);
} else printf("%s.[%d] error null ramchain->H.data\n",coin->symbol,i);
}
}
return(0);
}
char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi)
{
uint8_t *PKbits; struct iguana_pkhash *P; uint32_t pkind; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; cJSON *retjson; char rmdstr[41];
if ( (bp= coin->bundles[hdrsi]) != 0 )
{
ramchain = &bp->ramchain;
if ( ramchain->H.data != 0 )
{
retjson = cJSON_CreateArray();
PKbits = (void *)(long)((long)ramchain->H.data + ramchain->H.data->PKoffset);
P = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Poffset);
for (pkind=0; pkind<ramchain->H.data->numpkinds; pkind++,P++)
{
init_hexbytes_noT(rmdstr,P->rmd160,20);
jaddistr(retjson,rmdstr);
}
return(jprint(retjson,1));
}
//iguana_bundleQ(coin,bp,bp->n);
return(clonestr("{\"error\":\"no bundle data\"}"));
} return(clonestr("{\"error\":\"no bundle\"}"));
}
struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spend_hdrsi,struct iguana_spend *s)
{
int32_t prev_vout,height,hdrsi; uint32_t sequenceid,unspentind; char str[65];
@ -249,10 +196,78 @@ cJSON *iguana_unspentjson(struct iguana_info *coin,int32_t hdrsi,uint32_t unspen
return(item);
}
struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_ramchain **ramchainp,int64_t *balancep,uint32_t *lastunspentindp,struct iguana_pkhash *p,uint8_t rmd160[20],int32_t firsti,int32_t endi)
{
uint8_t *PKbits; struct iguana_pkhash *P; uint32_t pkind,i; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_account *ACCTS;
*balancep = 0;
*ramchainp = 0;
*lastunspentindp = 0;
for (i=firsti; i<coin->bundlescount&&i<=endi; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
{
if ( bp->isRT != 0 && coin->RTramchain_busy != 0 )
{
printf("iguana_pkhashfind: unexpected access when RTramchain_busy\n");
return(0);
}
ramchain = (bp->isRT != 0) ? &bp->ramchain : &coin->RTramchain;
if ( ramchain->H.data != 0 )
{
PKbits = (void *)(long)((long)ramchain->H.data + ramchain->H.data->PKoffset);
P = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Poffset);
ACCTS = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Aoffset);
if ( (pkind= iguana_sparseaddpk(PKbits,ramchain->H.data->pksparsebits,ramchain->H.data->numpksparse,rmd160,P,0)) > 0 && pkind < ramchain->H.data->numpkinds )
{
*ramchainp = ramchain;
*balancep = ACCTS[pkind].total;
*lastunspentindp = ACCTS[pkind].lastunspentind;
*p = P[pkind];
return(p);
} //else printf("not found pkind.%d vs num.%d\n",pkind,ramchain->H.data->numpkinds);
} else printf("%s.[%d] error null ramchain->H.data\n",coin->symbol,i);
}
}
return(0);
}
char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi)
{
uint8_t *PKbits; struct iguana_pkhash *P; uint32_t pkind; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; cJSON *retjson; char rmdstr[41];
if ( (bp= coin->bundles[hdrsi]) != 0 )
{
if ( bp->isRT != 0 && coin->RTramchain_busy != 0 )
{
printf("iguana_bundleaddrs: unexpected access when RTramchain_busy\n");
return(0);
}
ramchain = (bp->isRT != 0) ? &bp->ramchain : &coin->RTramchain;
if ( ramchain->H.data != 0 )
{
retjson = cJSON_CreateArray();
PKbits = (void *)(long)((long)ramchain->H.data + ramchain->H.data->PKoffset);
P = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Poffset);
for (pkind=0; pkind<ramchain->H.data->numpkinds; pkind++,P++)
{
init_hexbytes_noT(rmdstr,P->rmd160,20);
jaddistr(retjson,rmdstr);
}
return(jprint(retjson,1));
}
//iguana_bundleQ(coin,bp,bp->n);
return(clonestr("{\"error\":\"no bundle data\"}"));
} return(clonestr("{\"error\":\"no bundle\"}"));
}
int64_t iguana_pkhashbalance(struct iguana_info *coin,cJSON *array,int64_t *spentp,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi)
{
struct iguana_unspent *U; uint32_t unspentind; int64_t balance = 0; struct iguana_txid *T;
*spentp = *nump = 0;
if ( ramchain == &coin->RTramchain && coin->RTramchain_busy != 0 )
{
printf("iguana_pkhashbalance: unexpected access when RTramchain_busy\n");
return(0);
}
if ( ramchain->Uextras == 0 )
{
printf("iguana_pkhashbalance: unexpected null spents\n");
@ -279,6 +294,11 @@ int64_t iguana_pkhashbalance(struct iguana_info *coin,cJSON *array,int64_t *spen
int32_t iguana_pkhasharray(struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33)
{
int32_t i,n,m; int64_t spent,balance,netbalance,total; uint32_t lastunspentind; struct iguana_ramchain *ramchain;
if ( coin->RTramchain_busy != 0 )
{
printf("iguana_pkhasharray: unexpected access when RTramchain_busy\n");
return(-1);
}
for (total=i=n=0; i<max && i<coin->bundlescount; i++)
{
if ( iguana_pkhashfind(coin,&ramchain,&balance,&lastunspentind,&P[n],rmd160,i,i) != 0 )
@ -304,6 +324,11 @@ int32_t iguana_pkhasharray(struct iguana_info *coin,cJSON *array,int32_t minconf
void iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds)
{
int64_t total,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,flag = 0; char coinaddr[64];
if ( coin->RTramchain_busy != 0 )
{
printf("iguana_pkhasharray: unexpected access when RTramchain_busy\n");
return;
}
if ( rmdarray == 0 )
rmdarray = iguana_walletrmds(myinfo,coin,&numrmds), flag++;
addrtypes = &rmdarray[numrmds * 20], pubkeys = &rmdarray[numrmds * 21];
@ -321,27 +346,6 @@ void iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON
free(rmdarray);
}
uint8_t *iguana_rmdarray(struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti)
{
int32_t i,n,j=0; char *coinaddr; uint8_t *addrtypes,*rmdarray = 0;
*numrmdsp = 0;
if ( array != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
*numrmdsp = n - firsti;
rmdarray = calloc(1,(n-firsti) * 21);
addrtypes = &rmdarray[(n-firsti) * 20];
for (i=firsti; i<n; i++)
{
if ( (coinaddr= jstr(jitem(array,i),0)) != 0 )
{
bitcoin_addr2rmd160(&addrtypes[j],&rmdarray[20 * j],coinaddr);
j++;
}
}
}
return(rmdarray);
}
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
{
static uint64_t total,emitted;
@ -1120,9 +1124,10 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t pu
printf("error mapping bundle.[%d]\n",hdrsi);
}
char str[65]; printf("BALANCES WRITTEN for %d bundles %s\n",coin->balanceswritten,bits256_str(str,coin->balancehash));
exit(-1);
coin->balanceswritten = iguana_volatileinit(coin);
iguana_RTramchainfree(coin);
iguana_coinpurge(coin);
//exit(-1);
//coin->balanceswritten = iguana_volatileinit(coin);
//iguana_RTramchainfree(coin);
return(coin->balanceswritten);
}

22
iguana/iguana_wallet.c

@ -15,6 +15,28 @@
#include "iguana777.h"
uint8_t *iguana_rmdarray(struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti)
{
int32_t i,n,j=0; char *coinaddr; uint8_t *addrtypes,*rmdarray = 0;
*numrmdsp = 0;
if ( array != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
*numrmdsp = n - firsti;
rmdarray = calloc(1,(n-firsti) * 21);
addrtypes = &rmdarray[(n-firsti) * 20];
for (i=firsti; i<n; i++)
{
if ( (coinaddr= jstr(jitem(array,i),0)) != 0 )
{
bitcoin_addr2rmd160(&addrtypes[j],&rmdarray[20 * j],coinaddr);
j++;
}
}
}
return(rmdarray);
}
struct iguana_waccount *iguana_waccountcreate(struct iguana_info *coin,char *account)
{
struct iguana_waccount *waddr; int32_t len = (int32_t)strlen(account)+1;

13
iguana/main.c

@ -353,18 +353,27 @@ void mainloop(struct supernet_info *myinfo)
if ( 1 )
{
for (i=0; i<IGUANA_MAXCOINS; i++)
if ( (coin= Coins[i]) != 0 && coin->active != 0 && (bp= coin->current) != 0 )
if ( (coin= Coins[i]) != 0 && (bp= coin->current) != 0 )
{
if ( coin->started != 0 )
if ( coin->active != 0 && coin->started != 0 )
{
coin->RTramchain_busy = 1;
iguana_realtime_update(coin);
if ( (ptr= queue_dequeue(&balancesQ,0)) != 0 )
{
flag++;
if ( ptr->coin != 0 && (bp= ptr->bp) != 0 )
{
iguana_balancecalc(ptr->coin,bp,bp->bundleheight,bp->bundleheight+bp->n-1);
if ( coin->active == 0 )
{
printf("detected autopurge after account filecreation. restarting.%s\n",coin->symbol);
coin->active = 1;
}
}
myfree(ptr,ptr->allocsize);
}
coin->RTramchain_busy = (coin->RTgenesis == 0 || queue_size(&balancesQ) != 0);
}
}
}

1
includes/iguana_apideclares.h

@ -137,6 +137,7 @@ STRING_ARG(iguana,getconnectioncount,activecoin);
STRING_ARG(iguana,addcoin,newcoin);
STRING_ARG(iguana,startcoin,activecoin);
STRING_ARG(iguana,pausecoin,activecoin);
STRING_ARG(iguana,stopcoin,activecoin);
TWO_STRINGS(iguana,addnode,activecoin,ipaddr);
TWO_STRINGS(iguana,persistent,activecoin,ipaddr);
TWO_STRINGS(iguana,removenode,activecoin,ipaddr);

Loading…
Cancel
Save