Merge pull request #64 from jl777/acspeed

Acspeed
This commit is contained in:
jl777
2016-11-24 07:45:00 -03:00
committed by GitHub
13 changed files with 323 additions and 134 deletions

View File

@@ -1,33 +1,33 @@
#!/bin/bash
./komodo-cli paxdeposit $1 aud 0.01
./komodo-cli paxdeposit $1 bgn 0.01
./komodo-cli paxdeposit $1 cad 0.01
./komodo-cli paxdeposit $1 chf 0.01
./komodo-cli paxdeposit $1 cny 0.01
./komodo-cli paxdeposit $1 czk 0.01
./komodo-cli paxdeposit $1 dkk 0.01
./komodo-cli paxdeposit $1 eur 0.01
./komodo-cli paxdeposit $1 gbp 0.01
./komodo-cli paxdeposit $1 hkd 0.01
./komodo-cli paxdeposit $1 hrk 0.01
./komodo-cli paxdeposit $1 huf 0.01
./komodo-cli paxdeposit $1 idr 0.01
./komodo-cli paxdeposit $1 ils 0.01
./komodo-cli paxdeposit $1 inr 0.01
./komodo-cli paxdeposit $1 jpy 0.01
./komodo-cli paxdeposit $1 krw 0.01
./komodo-cli paxdeposit $1 mxn 0.01
./komodo-cli paxdeposit $1 myr 0.01
./komodo-cli paxdeposit $1 nok 0.01
./komodo-cli paxdeposit $1 nzd 0.01
./komodo-cli paxdeposit $1 php 0.01
./komodo-cli paxdeposit $1 pln 0.01
./komodo-cli paxdeposit $1 brl 0.01
./komodo-cli paxdeposit $1 ron 0.01
./komodo-cli paxdeposit $1 rub 0.01
./komodo-cli paxdeposit $1 sek 0.01
./komodo-cli paxdeposit $1 sgd 0.01
./komodo-cli paxdeposit $1 thb 0.01
./komodo-cli paxdeposit $1 try 0.01
./komodo-cli paxdeposit $1 usd 0.01
./komodo-cli paxdeposit $1 zar 0.01
./komodo-cli paxdeposit $1 0.01 aud
./komodo-cli paxdeposit $1 0.01 bgn
./komodo-cli paxdeposit $1 0.01 cad
./komodo-cli paxdeposit $1 0.01 chf
./komodo-cli paxdeposit $1 0.01 cny
./komodo-cli paxdeposit $1 0.01 czk
./komodo-cli paxdeposit $1 0.01 dkk
./komodo-cli paxdeposit $1 0.01 eur
./komodo-cli paxdeposit $1 0.01 gbp
./komodo-cli paxdeposit $1 0.01 hkd
./komodo-cli paxdeposit $1 0.01 hrk
./komodo-cli paxdeposit $1 0.01 huf
./komodo-cli paxdeposit $1 0.01 idr
./komodo-cli paxdeposit $1 0.01 ils
./komodo-cli paxdeposit $1 0.01 inr
./komodo-cli paxdeposit $1 0.01 jpy
./komodo-cli paxdeposit $1 0.01 krw
./komodo-cli paxdeposit $1 0.01 mxn
./komodo-cli paxdeposit $1 0.01 myr
./komodo-cli paxdeposit $1 0.01 nok
./komodo-cli paxdeposit $1 0.01 nzd
./komodo-cli paxdeposit $1 0.01 php
./komodo-cli paxdeposit $1 0.01 pln
./komodo-cli paxdeposit $1 0.01 brl
./komodo-cli paxdeposit $1 0.01 ron
./komodo-cli paxdeposit $1 0.01 rub
./komodo-cli paxdeposit $1 0.01 sek
./komodo-cli paxdeposit $1 0.01 sgd
./komodo-cli paxdeposit $1 0.01 thb
./komodo-cli paxdeposit $1 0.01 try
./komodo-cli paxdeposit $1 0.01 usd
./komodo-cli paxdeposit $1 0.01 zar

View File

@@ -17,9 +17,8 @@
#define H_KOMODO_H
// Todo:
// 1. error check fiat redeem amounts
// 2. net balance limiter
// 3. verify: reorgs
// 1. net balance limiter
// 2. verify: reorgs
// non komodod (non-hardfork) todo:
// a. automate notarization fee payouts
@@ -99,8 +98,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
errs++;
if ( fread(&notarized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) )
errs++;
//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 ( 0 && sp != 0 )
printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,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);
}
@@ -152,7 +151,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
{
if ( fread(opret,1,olen,fp) != olen )
errs++;
//if ( matched != 0 )
if ( 0 && matched != 0 )
{
int32_t i; for (i=0; i<olen; i++)
printf("%02x",opret[i]);
@@ -324,7 +323,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask)
{
static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16];
static uint256 zero; static FILE *signedfp;
int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16];
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
return(-1);
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
@@ -370,25 +370,43 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
else if ( opretlen == 0x4d )
{
opretlen = scriptbuf[len++];
opretlen = (opretlen << 8) + scriptbuf[len++];
opretlen += (scriptbuf[len++] << 8);
}
if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
{
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
{
printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
sp->NOTARIZED_HEIGHT = *notarizedheightp;
sp->NOTARIZED_HASH = kmdtxid;
sp->NOTARIZED_DESTTXID = desttxid;
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0);
len += 4;
if ( opretlen > len )//&& scriptbuf[len] == 'A' )
if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 )
printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len);
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len);
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j);
if ( signedfp == 0 )
{
char fname[512];
komodo_statefname(fname,(char *)"",(char *)"signedmasks");
if ( (signedfp= fopen(fname,"rb+")) == 0 )
signedfp = fopen(fname,"wb");
else fseek(signedfp,0,SEEK_END);
}
if ( signedfp != 0 )
{
fwrite(&height,1,sizeof(height),signedfp);
fwrite(&signedmask,1,sizeof(signedmask),signedfp);
fflush(signedfp);
}
if ( opretlen > len && scriptbuf[len] == 'A' )
{
printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len);
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j);
}
}
} else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
}
@@ -417,12 +435,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
return(notaryid);
}
int32_t komodo_isratify(int32_t isspecial,int32_t numvalid)
/*int32_t komodo_isratify(int32_t isspecial,int32_t numvalid)
{
if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY )
return(1);
else return(0);
}
}*/
// Special tx have vout[0] -> CRYPTO777
// with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify
@@ -492,9 +510,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
}
numvalid = bitweight(signedmask);
//if ( height == 79633 )
// notarized = 1;
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries>>1)) )
if ( height == 79633 )
notarized = 1;
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries>>1)) )
{
printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts);
notarized = 1;

View File

@@ -376,6 +376,8 @@ uint64_t komodo_seed(int32_t height)
{
uint256 hash; uint64_t seed = 0; CBlockIndex *pindex;
memset(&hash,0,sizeof(hash));
if ( height > 10 )
height -= 10;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
if ( (pindex= chainActive[height]) != 0 )
@@ -529,6 +531,18 @@ int8_t komodo_minerid(int32_t height)
return(-1);
}
int32_t komodo_minerids(uint8_t *minerids,int32_t height)
{
int32_t i,n=0;
for (i=0; i<1000; i++,n++)
{
if ( height-i <= 0 )
break;
minerids[i] = komodo_minerid(height - i);
}
return(n);
}
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
{
int32_t i,notaryid,minerid,limit;
@@ -560,7 +574,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
return(-1);
notarized_height = komodo_notarizeddata(pindex->nHeight,&notarized_hash,&notarized_desttxid);
*notarized_heightp = notarized_height;
if ( nHeight >= 79700 && notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
if ( notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
{
//printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str());
if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg

View File

@@ -15,18 +15,16 @@
// paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse
struct pax_transaction *komodo_paxfind(struct pax_transaction *space,uint256 txid,uint16_t vout)
struct pax_transaction *komodo_paxfind(uint256 txid,uint16_t vout)
{
struct pax_transaction *pax;
pthread_mutex_lock(&komodo_mutex);
HASH_FIND(hh,PAX,&txid,sizeof(txid),pax);
if ( pax != 0 )
memcpy(space,pax,sizeof(*pax));
pthread_mutex_unlock(&komodo_mutex);
return(pax);
}
struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *space,uint256 txid,uint16_t vout,int32_t mark)
struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout,int32_t mark)
{
struct pax_transaction *pax;
pthread_mutex_lock(&komodo_mutex);
@@ -45,15 +43,14 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp
//int32_t i; for (i=0; i<32; i++)
// printf("%02x",((uint8_t *)&txid)[i]);
//printf(" paxmark.ht %d vout%d\n",mark,vout);
memcpy(space,pax,sizeof(*pax));
}
pthread_mutex_unlock(&komodo_mutex);
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,char *source) // 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,int32_t approved) // assetchain context
{
struct pax_transaction *pax; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16];
struct pax_transaction *pax; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16],*s;
sp = komodo_stateptr(str,dest);
pthread_mutex_lock(&komodo_mutex);
HASH_FIND(hh,PAX,&txid,sizeof(txid),pax);
@@ -92,7 +89,12 @@ 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 %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()));
{
if ( (pax->approved= approved) != 0 )
s = (char *)"APPROVED";
else s = (char *)(ASSETCHAINS_SYMBOL[0]==0?"WITHDRAW":"DEPOSIT");
printf("[%s] addflag.%d ADD %s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,s,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);
}
@@ -106,45 +108,77 @@ 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];
if ( rwflag == 1 )
{
for (i=0; i<32; i++)
opretbuf[len++] = ((uint8_t *)&pax->txid)[i];
opretbuf[len++] = pax->vout & 0xff;
opretbuf[len++] = (pax->vout >> 8) & 0xff;
}
else
{
for (i=0; i<32; i++)
((uint8_t *)&pax->txid)[i] = opretbuf[len++];
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&pax->txid)[31-i]);
pax->vout = opretbuf[len++];
pax->vout += ((uint32_t)opretbuf[len++] << 8);
printf(" txid v.%d\n",pax->vout);
}
len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->komodoshis),&pax->komodoshis);
len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis);
len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->height),&pax->height);
len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight);
if ( rwflag != 0 )
{
memcpy(&opretbuf[len],pax->rmd160,20), len += 20;
for (i=0; i<4; i++)
opretbuf[len++] = pax->source[i];
}
else
{
memcpy(pax->rmd160,&opretbuf[len],20), len += 20;
for (i=0; i<4; i++)
pax->source[i] = opretbuf[len++];
}
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 komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo)
{
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];
struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[16];
incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4));
for (i=0; i<4; i++)
base[i] = opretbuf[opretlen-4+i];
//for (i=0; i<opretlen; i++)
// printf("%02x",opretbuf[i]);
//printf(" opretlen.%d vs %d incr.%d\n",opretlen,(int32_t)(2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4),incr);
if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 )
{
type = opretbuf[0];
opretbuf++, opretlen--;
incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4));
for (n=0; n<opretlen/incr; n++)
{
//printf(" komodo_issued_opreturn issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen);
if ( iskomodo != 0 )
{
memset(&p,0,sizeof(p));
len += komodo_rwapproval(0,&opretbuf[len],&p);
if ( values != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 )
if ( values != 0 && srcvalues != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 && rmd160s != 0 )
{
txids[n] = p.txid;
vouts[n] = p.vout;
values[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis;
srcvalues[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.fiatoshis : p.komodoshis;
kmdheights[n] = p.height;
otherheights[n] = p.otherheight;
memcpy(&rmd160s[n * 20],p.rmd160,20);
baseids[n] = komodo_baseid(p.symbol);
baseids[n] = komodo_baseid(p.source);
{
char coinaddr[64];
bitcoin_address(coinaddr,60,&rmd160s[n * 20],20);
printf(">>>>>>> %s: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",type=='A'?"approvedA":"issuedX",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),kmdheights[n],otherheights[n],coinaddr,dstr(values[n]));
}
}
printf(">>>>>>> iskomodo X: (%s) fiat %.8f kmdheight.%d other.%d\n",symbol,dstr(fiatoshis),height,otherheight);
}
else
{
@@ -156,6 +190,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t
vouts[n] = opretbuf[len++];
vouts[n] = (opretbuf[len++] << 8) | vouts[n];
}
//printf(" komodo_issued_opreturn issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen);
}
}
return(n);
@@ -163,7 +198,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t
uint64_t komodo_paxtotal()
{
struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; int32_t ht; uint64_t total = 0;
struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; int32_t ht; int64_t checktoshis; uint64_t seed,total = 0;
if ( komodo_isrealtime(&ht) == 0 )
return(0);
komodo_stateptr(symbol,dest);
@@ -176,7 +211,26 @@ uint64_t komodo_paxtotal()
{
if ( komodo_is_issuer() != 0 )
total += pax->fiatoshis;
else total += pax->komodoshis;
else if ( pax->approved != 0 )
{
if ( pax->validated != 0 )
total += pax->komodoshis;
else
{
seed = 0;
checktoshis = komodo_paxprice(&seed,pax->height,pax->source,(char *)"KMD",(uint64_t)pax->fiatoshis);
printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",pax->height,pax->symbol,(double)pax->fiatoshis/COIN,(double)pax->komodoshis/COIN,(double)checktoshis/COIN);
printf(" v%d %.8f k.%d ht.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight);
if ( seed != 0 )
{
if ( checktoshis >= pax->komodoshis )
{
total += pax->komodoshis;
pax->validated = pax->komodoshis;
} else pax->marked = pax->height;
}
}
}
}
}
}
@@ -198,11 +252,13 @@ int32_t komodo_pending_withdraws(char *opretstr)
if ( len == 0 )
opretbuf[len++] = 'A';
len += komodo_rwapproval(1,&opretbuf[len],pax);
printf("%s.(marked.%u approved.%d) %p\n",pax->source,pax->marked,pax->approved,pax);
}
}
if ( len > 0 )
init_hexbytes_noT(opretstr,opretbuf,len);
else opretstr[0] = 0;
printf("komodo_pending_withdraws len.%d PAXTOTAL %.8f\n",len,dstr(komodo_paxtotal()));
return(len);
}
@@ -222,7 +278,9 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
HASH_ITER(hh,PAX,pax,tmp)
{
//printf("pax.%s marked.%d %.8f -> %.8f\n",pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis));
if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 || (strcmp(symbol,"KMD") == 0 && pax->approved == 0) )
if ( strcmp(symbol,"KMD") == 0 && (pax->approved == 0 || pax->validated == 0) )
continue;
if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 )
continue;
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
printf("pax.%s marked.%d %.8f -> %.8f\n",ASSETCHAINS_SYMBOL,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis));
@@ -236,24 +294,27 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
memcpy(script,pax->rmd160,20), script += 20;
*script++ = 0x88;
*script++ = 0xac;
for (i=0; i<32; i++)
{
//printf("%02x",((uint8_t *)&pax->txid)[i]);
data[len++] = ((uint8_t *)&pax->txid)[i];
}
data[len++] = pax->vout & 0xff;
data[len++] = (pax->vout >> 8) & 0xff;
if ( tokomodo == 0 )
{
for (i=0; i<32; i++)
{
//printf("%02x",((uint8_t *)&pax->txid)[i]);
data[len++] = ((uint8_t *)&pax->txid)[i];
}
data[len++] = pax->vout & 0xff;
data[len++] = (pax->vout >> 8) & 0xff;
PENDING_KOMODO_TX += pax->fiatoshis;
}
else
{
//[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.10000000,"fiat":"EUR","kmdheight":57930,"height":153,"KMD":0.78329000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5","rmd160":"306c507eea639e7220b3069ed9f49f3bc97eaca1"}]
len += iguana_rwnum(1,&data[len],sizeof(pax->fiatoshis),&pax->fiatoshis);
len += komodo_rwapproval(1,&data[len],pax);
/*len += iguana_rwnum(1,&data[len],sizeof(pax->fiatoshis),&pax->fiatoshis);
len += iguana_rwnum(1,&data[len],sizeof(pax->height),&pax->height);
len += iguana_rwnum(1,&data[len],sizeof(pax->otherheight),&pax->otherheight);
for (i=0; pax->symbol[i]!=0&&i<3; i++) // must be 3 letter currency
data[len++] = pax->symbol[i];
data[len++] = 0;
data[len++] = 0;*/
PENDING_KOMODO_TX += pax->komodoshis;
printf(" vout.%u DEPOSIT %.8f <- pax.%s pending %.8f | ",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX));
}
@@ -281,9 +342,10 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing
{
int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; int64_t values[64]; struct pax_transaction *pax,space;
int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; int64_t values[64],srcvalues[64]; struct pax_transaction *pax;
memset(baseids,0xff,sizeof(baseids));
memset(values,0,sizeof(values));
memset(srcvalues,0,sizeof(srcvalues));
memset(rmd160s,0,sizeof(rmd160s));
memset(kmdheights,0,sizeof(kmdheights));
memset(otherheights,0,sizeof(otherheights));
@@ -307,30 +369,30 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
}
if ( script[offset] == opcode && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() )
{
if ( (num= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 )
if ( (num= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 )
{
for (i=1; i<n-1; i++)
{
if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 )
if ( (pax= komodo_paxfind(txids[i-1],vouts[i-1])) != 0 )
{
if ( ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) )
{
if ( pax->marked != 0 )
if ( pax->marked != 0 && height >= 80820 )
errs++;
else matched++;
if ( 0 && opcode == 'X' )
printf("errs.%d i.%d match %.8f == %.8f\n",errs,i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue));
komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height);
printf("errs.%d i.%d match %.8f == %.8f pax.%p\n",errs,i,dstr(pax != 0 ? pax->komodoshis:-1),dstr(block.vtx[0].vout[i].nValue),pax);
//komodo_paxmark(height,txids[i-1],vouts[i-1],height);
//if ( pax->marked == 0 )
// printf("unexpected unmarked %p\n",pax);
}
else
{
hash = block.GetHash();
if ( opcode == 'X' )
{
for (j=0; j<32; j++)
printf("%02x",((uint8_t *)&hash)[j]);
printf(" ht.%d blockhash X couldnt find vout.[%d]\n",height,i);
// validate amount! via fiat chain
printf("%02x",((uint8_t *)&txids[i-1])[j]);
printf(" cant paxfind X txid\n");
}
}
}
@@ -338,11 +400,10 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
{
if ( opcode == 'X' )
{
matched++;
hash = block.GetHash();
for (j=0; j<32; j++)
printf("%02x",((uint8_t *)&txids[i-1])[j]);
printf(" cant paxfind X txid\n");
// validate amount! via fiat chain
printf("%02x",((uint8_t *)&hash)[j]);
printf(" ht.%d blockhash X couldnt find vout.[%d]\n",height,i);
} else if ( opcode == 'I' )
matched++;
}
@@ -350,8 +411,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
if ( matched != num )
{
// can easily happen depending on order of loading
if ( height > 60000 )
printf("WARNING: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num);
if ( height > 60000 && opcode == 'X' )
{
printf("REJECT: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num);
return(-1);
}
}
}
//printf("opretlen.%d num.%d\n",opretlen,num);
@@ -361,20 +425,15 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
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;
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]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax;
const char *typestr = "unknown";
memset(baseids,0xff,sizeof(baseids));
memset(values,0,sizeof(values));
memset(srcvalues,0,sizeof(srcvalues));
memset(rmd160s,0,sizeof(rmd160s));
memset(kmdheights,0,sizeof(kmdheights));
memset(otherheights,0,sizeof(otherheights));
tokomodo = (komodo_is_issuer() == 0);
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
{
for (i=0; i<opretlen; i++)
printf("%02x",opretbuf[i]);
printf(" opret[%c] else path tokomodo.%d ht.%d\n",opretbuf[0],tokomodo,height);
}
if ( opretbuf[0] == 'D' )
{
if ( opretlen == 38 ) // any KMD tx
@@ -398,9 +457,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height);
if ( value >= checktoshis-(checktoshis >> 10) )
{
if ( komodo_paxfind(&space,txid,vout) == 0 )
if ( komodo_paxfind(txid,vout) == 0 )
{
komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD");
komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD",0);
} else printf("duplicate deposit\n");
}
}
@@ -418,50 +477,77 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
printf("%s.height.%d vs height.%d check %.8f/%.8f vs %.8f tokomodo.%d %d seed.%llx -> (%s)\n",ASSETCHAINS_SYMBOL,kmdheight,height,dstr(checktoshis),dstr(komodoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed,coinaddr);
if ( checktoshis <= komodoshis+(komodoshis >> 10) )
{
if ( (pax= komodo_paxfind(&space,txid,vout)) == 0 )
if ( (pax= komodo_paxfind(txid,vout)) == 0 )
{
printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height);
}
komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height,source);
komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height,source,0);
}
}
else if ( tokomodo != 0 && opretbuf[0] == 'A' )
{
printf("extra 'A' opret[%d]\n",opretlen);
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 )
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
for (i=0; i<opretlen; i++)
printf("%02x",opretbuf[i]);
printf(" opret[%c] else path tokomodo.%d ht.%d before %.8f\n",opretbuf[0],tokomodo,height,dstr(komodo_paxtotal()));
}
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 )
{
for (i=0; i<n; i++)
{
if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) == 0 && baseids[i] >= 0 )
if ( baseids[i] < 0 )
continue;
seed = 0;
checktoshis = komodo_paxprice(&seed,kmdheights[i],CURRENCIES[baseids[i]],(char *)"KMD",(uint64_t)srcvalues[i]);
printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",kmdheights[i],CURRENCIES[baseids[i]],(double)srcvalues[i]/COIN,(double)values[i]/COIN,(double)checktoshis/COIN);
for (j=0; j<32; j++)
printf("%02x",((uint8_t *)&txids[i])[j]);
printf(" v%d %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),kmdheights[i],otherheights[i],baseids[i]);
if ( (pax= komodo_paxfind(txids[i],vouts[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],CURRENCIES[baseids[i]]);
printf("i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i]));
} else printf("i.%d pax.%p baseids[] %d\n",i,pax,baseids[i]);
if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) != 0 )
komodo_gateway_deposit(coinaddr,values[i],CURRENCIES[baseids[i]],srcvalues[i],&rmd160s[i*20],txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]);
printf(" i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i]));
} else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]);
if ( (pax= komodo_paxfind(txids[i],vouts[i])) != 0 )
{
pax->approved = kmdheights[i];
printf("i.%d approved.%d\n",i,kmdheights[i]);
printf(" i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax);
}
}
}
printf("extra.[%d]\n",n);
printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal()));
}
else if ( tokomodo == 0 && opretbuf[0] == 'I' )
{
if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 )
{
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,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 )
{
for (i=0; i<n; i++)
{
bitcoin_address(coinaddr,60,&rmd160s[i*20],20);
if ( komodo_paxmark(height,&space,txids[i],vouts[i],height) == 0 && baseids[i] >= 0 )
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]]);
if ( komodo_paxmark(height,txids[i],vouts[i],height) == 0 && baseids[i] >= 0 )
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]],0);
}
}
}
}
else if ( opretbuf[0] == 'X' )
{
printf("got X opreturn height.%d\n",height);
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 )
{
for (i=0; i<n; i++)
{
bitcoin_address(coinaddr,60,&rmd160s[i*20],20);
printf("i.%d of %d: %.8f -> %s\n",i,n,dstr(values[i]),coinaddr);
if ( komodo_paxmark(height,txids[i],vouts[i],height) == 0 )
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,(char *)"KMD",0);
}
} else printf("komodo_issued_opreturn returned %d\n",n);
}
return(typestr);
}
@@ -480,7 +566,7 @@ void komodo_passport_iteration()
else refid = komodo_baseid(ASSETCHAINS_SYMBOL)+1; // illegal base -> baseid.-1 -> 0
//printf("PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid);
for (baseid=0; baseid<=32; baseid++)
{break;
{
sp = 0;
isrealtime = 0;
base = (char *)CURRENCIES[baseid];

View File

@@ -348,6 +348,8 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba
uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume)
{
int32_t baseid=-1,relid=-1,i; uint32_t *ptr;
if ( height > 10 )
height -= 10;
if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 )
{
for (i=NUM_PRICES-1; i>=0; i--)

View File

@@ -23,7 +23,7 @@
#endif*/
#define GENESIS_NBITS 0x1f00ffff
#define KOMODO_MINRATIFY 7
#define KOMODO_MINRATIFY ((height < 90000) ? 7 : 13)
#define KOMODO_MAXBLOCKS 5000000
#define KOMODO_EVENT_RATIFY 'P'
@@ -56,7 +56,7 @@ struct pax_transaction
{
UT_hash_handle hh;
uint256 txid;
uint64_t komodoshis,fiatoshis;
uint64_t komodoshis,fiatoshis,validated;
int32_t marked,height,otherheight,approved;
uint16_t vout;
char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],shortflag;

View File

@@ -1429,6 +1429,16 @@ void komodo_ports(uint16_t ports[MAX_CURRENCIES])
char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7778\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":1,\\\"VALIDATE\\\":1,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\"";
int32_t komodo_whoami(char *pubkeystr,int32_t height)
{
int32_t i,notaryid;
for (i=0; i<33; i++)
sprintf(&pubkeystr[i<<1],"%02x",NOTARY_PUBKEY33[i]);
pubkeystr[66] = 0;
komodo_chosennotary(&notaryid,height,NOTARY_PUBKEY33);
return(notaryid);
}
void komodo_args()
{
std::string name,addn; char *dirname,fname[512],magicstr[9]; uint8_t magic[4]; FILE *fp; int32_t i,len;

View File

@@ -99,7 +99,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
}
#define ASSETCHAINS_MINHEIGHT 100
#define ROUNDROBIN_DELAY 77
#define ROUNDROBIN_DELAY 59
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;
@@ -644,7 +644,10 @@ void static BitcoinMiner(CWallet *pwallet)
if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+ROUNDROBIN_DELAY )
{
//printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+ROUNDROBIN_DELAY-time(NULL)));
sleep(Mining_start+ROUNDROBIN_DELAY-time(NULL));
int32_t nseconds = Mining_start+ROUNDROBIN_DELAY-time(NULL);
if ( nseconds > 0 )
sleep(nseconds);
MilliSleep((rand() % 2000) + 1);
KOMODO_CHOSEN_ONE = 1;
}
// Found a solution

View File

@@ -387,6 +387,50 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n);
int32_t komodo_minerids(uint8_t *minerids,int32_t height);
Value minerids(const Array& params, bool fHelp)
{
Object ret; Array a; uint8_t minerids[1000],pubkeys[64][33]; int32_t i,j,n,numnotaries,tally[65];
if ( fHelp || params.size() != 1 )
throw runtime_error("minerids needs height\n");
LOCK(cs_main);
int32_t height = atoi(params[0].get_str().c_str());
if ( height <= 0 )
height = chainActive.Tip()->nHeight;
if ( (n= komodo_minerids(minerids,height)) > 0 )
{
memset(tally,0,sizeof(tally));
numnotaries = komodo_notaries(pubkeys,height);
if ( numnotaries > 0 )
{
for (i=0; i<n; i++)
{
if ( minerids[i] >= numnotaries )
tally[64]++;
else tally[minerids[i]]++;
}
for (i=0; i<64; i++)
{
Object item; std::string hex; char *hexstr;
hex.resize(66);
hexstr = (char *)hex.data();
for (j=0; j<33; j++)
sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]);
item.push_back(Pair("notaryid", i));
item.push_back(Pair("pubkey", hex));
item.push_back(Pair("blocks", tally[i]));
a.push_back(item);
}
Object item;
item.push_back(Pair("pubkey", (char *)"external miners"));
item.push_back(Pair("blocks", tally[64]));
a.push_back(item);
}
ret.push_back(Pair("mined", a));
} else ret.push_back(Pair("error", (char *)"couldnt extract minerids"));
return ret;
}
Value notaries(const Array& params, bool fHelp)
{

View File

@@ -108,8 +108,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "z_importkey", 1 },
{ "paxprice", 4 },
{ "paxprices", 3 },
{ "paxpending", 3 },
{ "paxpending", 0 },
{ "notaries", 1 },
{ "minerids", 1 },
};
class CRPCConvertTable

View File

@@ -42,6 +42,7 @@ using namespace std;
uint64_t komodo_interestsum();
int32_t komodo_longestchain();
int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp);
int32_t komodo_whoami(char *pubkeystr,int32_t height);
Value getinfo(const Array& params, bool fHelp)
{
@@ -120,6 +121,14 @@ Value getinfo(const Array& params, bool fHelp)
#endif
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
{
char pubkeystr[65]; int32_t notaryid;
if ( (notaryid= komodo_whoami(pubkeystr,longestchain)) >= 0 )
{
obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("pubkey", pubkeystr));
}
}
return obj;
}

View File

@@ -304,6 +304,7 @@ static const CRPCCommand vRPCCommands[] =
{ "blockchain", "paxpending", &paxpending, true },
{ "blockchain", "paxprices", &paxprices, true },
{ "blockchain", "notaries", &notaries, true },
{ "blockchain", "minerids", &minerids, true },
/* Mining */
{ "mining", "getblocktemplate", &getblocktemplate, true },

View File

@@ -244,6 +244,7 @@ extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp)
extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp);
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 minerids(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);