diff --git a/src/komodo.h b/src/komodo.h index 0821259ea..967386695 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,7 +99,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; - //printf("%s load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,notarized_height,notarized_hash.ToString().c_str()); + if ( 0 && sp != 0 ) + printf("%s %p %p[%d] load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,sp,sp->NPOINTS,sp->NUM_NPOINTS,symbol,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } @@ -151,11 +152,13 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char { if ( fread(opret,1,olen,fp) != olen ) errs++; - //if ( matched != 0 ) global shared state -> global PAX - int32_t i; for (i=0; i global PAX } else printf("illegal olen.%u\n",olen); } else if ( func == 'D' ) @@ -295,17 +298,19 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar else if ( height != 0 ) { //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); - fputc('N',fp); - if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) - errs++; - if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) ) - errs++; - if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) ) - errs++; - if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) - errs++; - komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT); - //komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); + if ( sp != 0 ) + { + fputc('N',fp); + if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) + errs++; + if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) ) + errs++; + if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) ) + errs++; + if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) + errs++; + komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT); + } } fflush(fp); } @@ -452,15 +457,15 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0); } komodo_currentheight_set(chainActive.Tip()->nHeight); - /*if ( komodo_is_issuer() != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) + while ( KOMODO_PASSPORT_INITDONE == 0 ) { - fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL)); - sleep(30); + fprintf(stderr,"komodo_connect.(%s) waiting for KOMODO_PASSPORT_INITDONE.%u\n",ASSETCHAINS_SYMBOL,KOMODO_PASSPORT_INITDONE); + sleep(3); } - }*/ - KOMODO_INITDONE = (uint32_t)time(NULL); + } + //KOMODO_INITDONE = (uint32_t)time(NULL); if ( pindex != 0 ) { height = pindex->nHeight; @@ -545,7 +550,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( pindex->nHeight == hwmheight ) komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0); } else printf("komodo_connectblock: unexpected null pindex\n"); - KOMODO_INITDONE = (uint32_t)time(NULL); + //KOMODO_INITDONE = (uint32_t)time(NULL); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a49f1a068..6878114b6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -346,6 +346,45 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) return(retstr2); } +uint256 komodo_getblockhash(int32_t height) +{ + uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32]; + memset(&hash,0,sizeof(hash)); + sprintf(params,"[%d]",height); + if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 ) + { + if ( (result= cJSON_Parse(jsonstr)) != 0 ) + { + if ( (hexstr= jstr(result,(char *)"result")) != 0 ) + { + if ( is_hexstr(hexstr,0) == 64 ) + { + decode_hex(revbuf,32,hexstr); + for (i=0; i<32; i++) + ((uint8_t *)&hash)[i] = revbuf[31-i]; + } + } + free_json(result); + } + printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash); + free(jsonstr); + } + return(hash); +} + +uint64_t komodo_seed(int32_t height) +{ + uint256 hash; uint64_t seed = 0; CBlockIndex *pindex; + memset(&hash,0,sizeof(hash)); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + if ( (pindex= chainActive[height]) != 0 ) + hash = pindex->GetBlockHash(); + } else hash = komodo_getblockhash(height); + seed = arith_uint256(hash.GetHex()).GetLow64(); + return(seed); +} + uint32_t komodo_txtime(uint256 hash) { CTransaction tx; @@ -362,17 +401,6 @@ uint32_t komodo_txtime(uint256 hash) return(0); } -uint64_t komodo_seed(int32_t height) -{ - uint256 hash; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; - if ( pindex != 0 ) - { - hash = pindex->GetBlockHash(); - seed = arith_uint256(hash.GetHex()).GetLow64(); - } - return(seed); -} - void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { char symbol[16],dest[16]; struct komodo_state *sp; @@ -510,7 +538,10 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) for (i=1; i<64; i++) { if ( komodo_minerid(height-i) == notaryid ) + { + //fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d\n",height,notaryid,i); return(-1); + } } return(1); } diff --git a/src/komodo_events.h b/src/komodo_events.h index d7411737f..0a5034a73 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -18,16 +18,21 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { - struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); - ep = (struct komodo_event *)calloc(1,len); - ep->len = len; - ep->height = height; - ep->type = type; - strcpy(ep->symbol,symbol); - if ( datalen != 0 ) - memcpy(ep->space,data,datalen); - sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events)); - sp->Komodo_events[sp->Komodo_numevents++] = ep; + struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); + if ( sp != 0 ) + { + portable_mutex_lock(&komodo_mutex); + ep = (struct komodo_event *)calloc(1,len); + ep->len = len; + ep->height = height; + ep->type = type; + strcpy(ep->symbol,symbol); + if ( datalen != 0 ) + memcpy(ep->space,data,datalen); + sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events)); + sp->Komodo_events[sp->Komodo_numevents++] = ep; + portable_mutex_unlock(&komodo_mutex); + } return(ep); } @@ -79,7 +84,7 @@ void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t heigh O.oplen = (int32_t)(opretlen + sizeof(O)); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen); if ( sp != 0 ) - komodo_opreturn(height,value,buf,opretlen,txid,vout); + komodo_opreturn(height,value,buf,opretlen,txid,vout,symbol); } void komodo_event_undo(struct komodo_state *sp,struct komodo_event *ep) @@ -122,13 +127,16 @@ void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height) void komodo_setkmdheight(struct komodo_state *sp,int32_t kmdheight,uint32_t timestamp) { - if ( kmdheight > sp->SAVEDHEIGHT ) + if ( sp != 0 ) { - sp->SAVEDHEIGHT = kmdheight; - sp->SAVEDTIMESTAMP = timestamp; + if ( kmdheight > sp->SAVEDHEIGHT ) + { + sp->SAVEDHEIGHT = kmdheight; + sp->SAVEDTIMESTAMP = timestamp; + } + if ( kmdheight > sp->CURRENT_HEIGHT ) + sp->CURRENT_HEIGHT = kmdheight; } - if ( kmdheight > sp->CURRENT_HEIGHT ) - sp->CURRENT_HEIGHT = kmdheight; } void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight,uint32_t timestamp) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 494fc43f0..1cc0bb9cb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -51,7 +51,7 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp return(pax); } -void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight) // assetchain context +void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight,char *source) // assetchain context { struct pax_transaction *pax; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16]; sp = komodo_stateptr(str,dest); @@ -79,6 +79,8 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t pax->komodoshis = value; if ( symbol != 0 ) strcpy(pax->symbol,symbol); + if ( source != 0 ) + strcpy(pax->source,source); if ( fiatoshis != 0 ) pax->fiatoshis = fiatoshis; if ( rmd160 != 0 ) @@ -90,7 +92,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t if ( pax->marked == 0 ) { if ( addflag != 0 ) - printf("[%s] addflag.%d ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,symbol,dstr(fiatoshis),coinaddr,height,otherheight,dstr(komodo_paxtotal())); + printf("[%s] addflag.%d ADD %s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,ASSETCHAINS_SYMBOL[0]==0?"WITHDRAW":"DEPOSIT",symbol,dstr(ASSETCHAINS_SYMBOL[0]==0?pax->komodoshis:pax->fiatoshis),pax->coinaddr,pax->height,pax->otherheight,dstr(komodo_paxtotal())); } //else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height,otherheight); } @@ -101,44 +103,59 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t } } +int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transaction *pax) +{ + int32_t i,len = 0; + for (i=0; i<32; i++) + opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; + opretbuf[len++] = pax->vout & 0xff; + opretbuf[len++] = (pax->vout >> 8) & 0xff; + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->komodoshis); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->height),&pax->height); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); + memcpy(&opretbuf[len],pax->rmd160,20), len += 20; + for (i=0; i<4; i++) + opretbuf[len++] = pax->source[i]; + return(len); +} + int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { - int32_t i,n=0,j,len,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; + struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { opretbuf++, opretlen--; - incr = 34 + (iskomodo * (sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); - for (n=len=0; n>>>>>> iskomodo X: (%s) fiat %.8f kmdheight.%d other.%d\n",symbol,dstr(fiatoshis),height,otherheight); } + else + { + for (j=0; j<32; j++) + { + ((uint8_t *)&txids[n])[j] = opretbuf[len++]; + //printf("%02x",((uint8_t *)&txids[n])[j]); + } + vouts[n] = opretbuf[len++]; + vouts[n] = (opretbuf[len++] << 8) | vouts[n]; + } } } return(n); @@ -163,18 +180,25 @@ uint64_t komodo_paxtotal() return(total); } -int32_t komodo_withdraws_pending(char *opretbuf) +int32_t komodo_pending_withdraws(char *opretstr) { - struct pax_transaction *pax,*tmp; int32_t ht,len=0; uint64_t total = 0; + struct pax_transaction *pax,*tmp; uint8_t opretbuf[10000]; int32_t ht,len=0; uint64_t total = 0; if ( komodo_isrealtime(&ht) == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) return(0); HASH_ITER(hh,PAX,pax,tmp) { + //printf("pax %s marked.%u approved.%u\n",pax->symbol,pax->marked,pax->approved); if ( pax->marked == 0 && strcmp((char *)"KMD",pax->symbol) == 0 && pax->approved == 0 ) { // add 'A' opreturn entry + if ( len == 0 ) + opretbuf[len++] = 'A'; + len += komodo_rwapproval(1,&opretbuf[len],pax); } } + if ( len > 0 ) + init_hexbytes_noT(opretstr,opretbuf,len); + else opretstr[0] = 0; return(len); } @@ -331,7 +355,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } -const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) +const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64]; struct pax_transaction *pax; const char *typestr = "unknown"; @@ -372,7 +396,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( komodo_paxfind(&space,txid,vout) == 0 ) { - komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height); + komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD"); } else printf("duplicate deposit\n"); } } @@ -394,24 +418,22 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height); } - else - { - printf(" %.8f -> %s withdraw already there\n",dstr(value),coinaddr); - komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height); - } + komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height,source); } } else if ( tokomodo != 0 && opretbuf[0] == 'A' ) { - if ( (n= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 ) + if ( (n= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 ) { for (i=0; i= 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); - komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i]); - } else pax->approved = kmdheights[i]; + komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]]); + } + if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) != 0 ) + pax->approved = kmdheights[i]; } } } @@ -424,8 +446,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i= 0 ) + komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]]); } } } @@ -437,6 +459,11 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; FILE *fp; int32_t baseid,isrealtime,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3]; cJSON *infoobj,*result; uint64_t RTmask = 0; + while ( KOMODO_INITDONE == 0 ) + { + fprintf(stderr,"PASSPORT iteration waiting for KOMODO_INITDONE\n"); + sleep(3); + } refsp = komodo_stateptr(symbol,dest); if ( ASSETCHAINS_SYMBOL[0] == 0 ) refid = 33; @@ -454,10 +481,10 @@ void komodo_passport_iteration() //port = komodo_port(base,10,&magic) + 1; if ( (fp= fopen(fname,"rb")) != 0 && (sp= komodo_stateptrget(symbol)) != 0 ) { - //printf("refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base); fseek(fp,0,SEEK_END); if ( ftell(fp) > lastpos[baseid] ) { + //printf("passport refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base); fseek(fp,lastpos[baseid],SEEK_SET); while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; @@ -506,5 +533,6 @@ void komodo_passport_iteration() refsp->RTbufs[0][2] = 0; } refsp->RTmask = RTmask; + KOMODO_PASSPORT_INITDONE = 1; } diff --git a/src/komodo_globals.h b/src/komodo_globals.h index a4ab49acf..a17c29964 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -36,7 +36,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = 100; -int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES; +int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 5cea65f95..cbfca6563 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -168,6 +168,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight); return; } + portable_mutex_lock(&komodo_mutex); sp->NPOINTS = (struct notarized_checkpoint *)realloc(sp->NPOINTS,(sp->NUM_NPOINTS+1) * sizeof(*sp->NPOINTS)); np = &sp->NPOINTS[sp->NUM_NPOINTS++]; memset(np,0,sizeof(*np)); @@ -175,6 +176,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height; sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash; sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; + portable_mutex_unlock(&komodo_mutex); } //struct komodo_state *komodo_stateptr(char *symbol,char *dest); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index a4af4b5aa..77f7c5f1f 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -285,10 +285,12 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); BTCUSD = ((double)btcusd / (1000000000. / 1000.)); CNYUSD = ((double)cnyusd / 1000000000.); + portable_mutex_lock(&komodo_mutex); PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36); PVALS[36 * NUM_PRICES] = height; memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35); NUM_PRICES++; + portable_mutex_unlock(&komodo_mutex); if ( 0 ) printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d (%llu %llu %llu)\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES,(long long)kmdbtc,(long long)btcusd,(long long)cnyusd); } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index f62e5de1a..b7d776702 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -16,11 +16,11 @@ #include "uthash.h" #include "utlist.h" -#ifdef WIN32 +/*#ifdef WIN32 #define PACKED #else #define PACKED __attribute__((packed)) -#endif +#endif*/ #define GENESIS_NBITS 0x1f00ffff #define KOMODO_MINRATIFY 7 @@ -50,7 +50,7 @@ struct komodo_event uint8_t type,reorged; char symbol[16]; uint8_t space[]; -} PACKED; +}; struct pax_transaction { @@ -59,7 +59,7 @@ struct pax_transaction uint64_t komodoshis,fiatoshis; int32_t marked,height,otherheight,approved; uint16_t vout; - char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; + char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],shortflag; }; //struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; }; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d77d8ed72..399fc4c69 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1456,7 +1456,6 @@ void komodo_args() int32_t komodo_baseid(char *origbase); extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); - //if ( komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 ) COINBASE_MATURITY = 1; } ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); diff --git a/src/miner.cpp b/src/miner.cpp index 7fe6dd34b..fffbee299 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -99,7 +99,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, } #define ASSETCHAINS_MINHEIGHT 100 -#define ROUNDROBIN_DELAY 61 +#define ROUNDROBIN_DELAY 77 extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE; extern char ASSETCHAINS_SYMBOL[16]; extern std::string NOTARY_PUBKEY; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 007600a91..8bfb19629 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -436,6 +436,20 @@ Value notaries(const Array& params, bool fHelp) return ret; } +int32_t komodo_pending_withdraws(char *opretstr); + +Value paxpending(const Array& params, bool fHelp) +{ + Object ret; char opretbuf[10000*2]; int32_t opretlen; + if ( fHelp || params.size() != 0 ) + throw runtime_error("paxpending needs no args\n"); + LOCK(cs_main); + if ( (opretlen= komodo_pending_withdraws(opretbuf)) > 0 ) + ret.push_back(Pair("withdraws", opretbuf)); + else ret.push_back(Pair("withdraws", (char *)"")); + return ret; +} + Value paxprice(const Array& params, bool fHelp) { if ( fHelp || params.size() < 3 || params.size() > 4 ) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 30142ee82..adf10ccb7 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -108,6 +108,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "z_importkey", 1 }, { "paxprice", 4 }, { "paxprices", 3 }, + { "paxpending", 3 }, { "notaries", 1 }, }; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index e8a9958ce..4f04bdcc1 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -301,6 +301,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true }, { "blockchain", "verifychain", &verifychain, true }, { "blockchain", "paxprice", &paxprice, true }, + { "blockchain", "paxpending", &paxpending, true }, { "blockchain", "paxprices", &paxprices, true }, { "blockchain", "notaries", ¬aries, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 765e27747..77a4818bb 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -245,6 +245,7 @@ extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value paxpending(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxwithdraw(const json_spirit::Array& params, bool fHelp);