Merge branch 'dev' of https://github.com/jl777/komodo into dev

This commit is contained in:
Alrighttt
2018-06-25 10:45:04 -04:00
30 changed files with 352 additions and 229 deletions

2
src/ac/eql Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=EQL $1 $2 $3 $4 $5 $6

2
src/ac/glxt Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=GLXT $1 $2 $3 $4 $5 $6

View File

@@ -55,3 +55,6 @@ komodo_asset BNTN 500000000
komodo_asset CHAIN 999999
komodo_asset PRLPAY 500000000
komodo_asset DSEC 7000000
komodo_asset GLXT 100000000
komodo_asset EQL 500000000
komodo_asset ZILLA 11000000

View File

@@ -32,68 +32,9 @@ echo $pubkey
./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 &
./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 &
./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 &
#sleep $delay
./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 &
./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 &
./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 &
~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 &
#./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 &
#sleep $delay
#./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 &

View File

@@ -173,6 +173,8 @@ public:
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
// guarantees the first two characters, when base58 encoded, are "zc"
base58Prefixes[ZCPAYMENT_ADDRRESS] = {22,154};
// guarantees the first 4 characters, when base58 encoded, are "ZiVK"
base58Prefixes[ZCVIEWING_KEY] = {0xA8,0xAB,0xD3};
// guarantees the first two characters, when base58 encoded, are "SK"
base58Prefixes[ZCSPENDING_KEY] = {171,54};
@@ -467,6 +469,8 @@ public:
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
base58Prefixes[ZCPAYMENT_ADDRRESS] = {20,81};
// guarantees the first 4 characters, when base58 encoded, are "ZiVt"
base58Prefixes[ZCVIEWING_KEY] = {0xA8,0xAC,0x0C};
base58Prefixes[ZCSPENDING_KEY] = {177,235};
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));

View File

@@ -31,6 +31,8 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GLXT\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EQL\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZILLA\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}"

View File

@@ -28,3 +28,6 @@ echo bntn; fiat/bntn $1 $2 $3 $4
echo chain; fiat/chain $1 $2 $3 $4
echo prlpay; fiat/prlpay $1 $2 $3 $4
echo dsec; fiat/dsec $1 $2 $3 $4
echo glxt; fiat/glxt $1 $2 $3 $4
echo eql; fiat/eql $1 $2 $3 $4
echo zilla; fiat/zilla $1 $2 $3 $4

2
src/fiat/eql Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=EQL $1 $2 $3 $4 $5 $6

2
src/fiat/glxt Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=GLXT $1 $2 $3 $4 $5 $6

2
src/fiat/zilla Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=ZILLA $1 $2 $3 $4 $5 $6

View File

@@ -113,7 +113,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
if ( fread(&MoMdepth,1,sizeof(MoMdepth),fp) != sizeof(MoMdepth) )
errs++;
if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth);
printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff);
}
else
{
@@ -201,8 +201,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals);
//printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
} else printf("error loading pvals[%d]\n",numpvals);
}
else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
} // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
return(func);
} else return(-1);
}
@@ -259,7 +258,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long
if ( memread(&MoMdepth,sizeof(MoMdepth),filedata,&fpos,datalen) != sizeof(MoMdepth) )
errs++;
if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth);
printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff);
}
else
{
@@ -312,7 +311,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long
{
if ( memread(opret,olen,filedata,&fpos,datalen) != olen )
errs++;
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 )
if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 )
{
int32_t i; for (i=0; i<olen; i++)
printf("%02x",opret[i]);
@@ -342,8 +341,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long
komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals);
//printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
} else printf("error loading pvals[%d]\n",numpvals);
}
else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
} // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
*fposp = fpos;
return(func);
}
@@ -429,7 +427,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
errs++;
if ( fwrite(opretbuf,1,olen,fp) != olen )
errs++;
//printf("ht.%d R opret[%d] sp.%p\n",height,olen,sp);
printf("create ht.%d R opret[%d] sp.%p\n",height,olen,sp);
//komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout);
komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen);
}
@@ -482,7 +480,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
//printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs);
if ( sp != 0 )
{
if ( sp->MoMdepth > 0 && sp->MoM != zero )
if ( sp->MoMdepth != 0 && sp->MoM != zero )
fputc('M',fp);
else fputc('N',fp);
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
@@ -493,7 +491,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
errs++;
if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) )
errs++;
if ( sp->MoMdepth > 0 && sp->MoM != zero )
if ( sp->MoMdepth != 0 && sp->MoM != zero )
{
if ( fwrite(&sp->MoM,1,sizeof(sp->MoM),fp) != sizeof(sp->MoM) )
errs++;
@@ -600,14 +598,18 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
}
else
{
if ( scriptbuf[len] == 'K' )
{
fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value));
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0);
return(-1);
}
if ( strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
matched = 1;
}
offset = 32 * (1 + matched) + 4;
nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]);
if ( nameoffset == 2 )
nameoffset += 2;
else nameoffset++;
nameoffset++;
memset(&ccdata,0,sizeof(ccdata));
strncpy(ccdata.symbol,(char *)&scriptbuf[len+offset],sizeof(ccdata.symbol));
if ( j == 1 && opretlen >= len+offset-opoffset )
@@ -637,16 +639,18 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
ccdata.MoMdata.notarized_height = *notarizedheightp;
ccdata.MoMdata.height = height;
ccdata.MoMdata.txi = i;
//printf("nameoffset.%d len.%d + 36 %d vs opretlen.%d\n",nameoffset,len,len+36,opretlen);
//printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen);
if ( len+36-opoffset <= opretlen )
{
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(MoMdepth),(uint8_t *)&MoMdepth);
ccdata.MoMdata.MoM = MoM;
ccdata.MoMdata.MoMdepth = MoMdepth;
ccdata.MoMdata.MoMdepth = MoMdepth & 0xffff;
if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen )
{
len += iguana_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid);
//if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) )
// fprintf(stderr,"%s CCid mismatch %u != %u\n",ASSETCHAINS_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff));
ccdata.len = sizeof(ccdata.CCid);
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
@@ -672,7 +676,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
} else ccdata.len = MoMoMdata.len = 0;
}
}
if ( MoM == zero || MoMdepth > *notarizedheightp || MoMdepth < 0 )
if ( MoM == zero || (MoMdepth&0xffff) > *notarizedheightp || (MoMdepth&0xffff) < 0 )
{
memset(&MoM,0,sizeof(MoM));
MoMdepth = 0;
@@ -681,7 +685,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
{
komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata);
if ( matched != 0 )
printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth);
printf("[%s] matched.%d VALID (%s) MoM.%s [%d] CCid.%u\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff);
}
if ( MoMoMdata.pairs != 0 )
free(MoMoMdata.pairs);
@@ -695,7 +699,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
sp->NOTARIZED_HEIGHT = *notarizedheightp;
sp->NOTARIZED_HASH = srchash;
sp->NOTARIZED_DESTTXID = desttxid;
if ( MoM != zero && MoMdepth > 0 )
if ( MoM != zero && (MoMdepth&0xffff) > 0 )
{
sp->MoM = MoM;
sp->MoMdepth = MoMdepth;

View File

@@ -932,7 +932,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in
memset(MoMp,0,sizeof(*MoMp));
memset(kmdtxidp,0,sizeof(*kmdtxidp));
*notarized_heightp = 0;
if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht )
if ( depth != 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht )
{
*MoMp = MoM;
*notarized_heightp = notarized_ht;
@@ -1024,9 +1024,8 @@ int32_t komodo_isrealtime(int32_t *kmdheightp)
else return(0);
}
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag)
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag)
{
uint32_t cmptime = nTime;
if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 )
{
if ( txheight > 246748 )
@@ -1080,6 +1079,13 @@ uint64_t komodo_commission(const CBlock *pblock)
return(commission);
}
uint32_t komodo_segid32(char *coinaddr)
{
bits256 addrhash;
vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)coinaddr,(int32_t)strlen(coinaddr));
return(addrhash.uints[0]);
}
uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr)
{
CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN;
@@ -1087,10 +1093,14 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
if ( blocktime < prevtime+57 )
blocktime = prevtime+57;
if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 )
{
fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime);
return(0);
}
if ( (minage= nHeight*3) > 6000 )
minage = 6000;
if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 )
pindex = 0;
if ( (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 )
{
vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address));
segid = ((nHeight + addrhash.uints[0]) & 0x3f);
@@ -1102,8 +1112,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
for (iter=0; iter<3600; iter++)
{
diff = (iter + blocktime - txtime - minage);
if ( diff > 3600*24 )
break;
if ( iter > 0 )
diff += iter + segid*2;
//if ( diff > 3600*24 )
// break;
if ( blocktime+iter+segid*2 < txtime+minage )
continue;
coinage = (value * diff) * ((diff >> 16) + 1);
hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1));
if ( hashval <= bnTarget )
@@ -1137,8 +1151,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff);
}
}
if ( nHeight < 2 )
} //else fprintf(stderr,"skip PoS scan: diff %d blocktime %u > %u txtime+minage %u pindex.%p\n",(int32_t)(blocktime - (txtime+minage)),blocktime,txtime,minage,pindex);
if ( nHeight < 10 )
return(blocktime);
return(blocktime * winner);
}
@@ -1147,19 +1161,21 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
{
CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val;
*percPoSp = percPoS = 0;
if ( height < 3 )
if ( height <= 10 )
return(target);
sum = arith_uint256(0);
ave = sum;
for (i=n=0; i<100; i++)
{
ht = height - 100 + i;
if ( ht <= 1 )
continue;
if ( (pindex= komodo_chainactive(ht)) != 0 )
{
bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow);
bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT));
hashval = UintToArith256(pindex->GetBlockHash());
if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW
if ( hashval <= bnTarget ) // PoW is never as easy as PoS/16, some PoS will be counted as PoW
{
fprintf(stderr,"1");
sum += hashval;
@@ -1174,7 +1190,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
fprintf(stderr," %d, ",percPoS);
}
}
fprintf(stderr," -> %d%% percPoS ht.%d\n",percPoS,height);
if ( n < 100 )
percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100;
fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height);
*percPoSp = percPoS;
target = (target / arith_uint256(KOMODO_POWMINMULT));
if ( n > 0 )
@@ -1185,17 +1203,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
} else return(target);
if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget
{
bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((goalperc) * (goalperc));
/*if ( height > 1165 )
{
if ( height > 1180 )
{
if ( height > 1230 )
bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((goalperc) * (goalperc));
else bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc);
}
else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc));
} else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc);*/
bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc);
if ( 1 )
{
for (i=31; i>=24; i--)
@@ -1265,6 +1273,29 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
return(isPoS);
}
int64_t komodo_checkcommission(CBlock *pblock,int32_t height)
{
int64_t checktoshis=0; uint8_t *script;
if ( ASSETCHAINS_COMMISSION != 0 )
{
checktoshis = komodo_commission(pblock);
if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 )
return(-1);
else if ( checktoshis != 0 )
{
script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data();
if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 )
return(-1);
if ( pblock->vtx[0].vout[1].nValue != checktoshis )
{
fprintf(stderr,"ht.%d checktoshis %.8f vs actual vout[1] %.8f\n",height,dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue));
return(-1);
}
}
}
return(checktoshis);
}
int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
{
uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev;
@@ -1318,7 +1349,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
{
if ( slowflag != 0 )
bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED);
else bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound
else if ( height > 100 )
bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound
if ( bhash > bnTarget )
{
for (i=31; i>=16; i--)
@@ -1333,21 +1365,18 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
} else if ( is_PoSblock < 0 )
return(-1);
}
if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 )
if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
{
checktoshis = komodo_commission(pblock);
if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 )
return(-1);
else if ( checktoshis != 0 )
if ( height == 1 )
{
script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data();
script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data();
if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 )
return(-1);
if ( pblock->vtx[0].vout[1].nValue != checktoshis )
{
fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue));
}
else
{
if ( komodo_checkcommission(pblock,height) < 0 )
return(-1);
}
}
}
//fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed);

View File

@@ -45,6 +45,7 @@ bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth)
{
static uint256 zero; bits256 MoM,*tree; CBlockIndex *pindex; int32_t i;
MoMdepth &= 0xffff;
if ( MoMdepth >= height )
return(zero);
tree = (bits256 *)calloc(MoMdepth * 3,sizeof(*tree));

View File

@@ -653,7 +653,7 @@ void komodo_passport_iteration();
int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing
{
static uint256 array[64]; static int32_t numbanned,indallvouts;
int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,notmatched=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; CTransaction tx;
int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,notmatched=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,seed; int64_t checktoshis,values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; CTransaction tx;
activation = 235300;
if ( *(int32_t *)&array[0] == 0 )
numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array)));
@@ -743,8 +743,22 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
}
else
{
if ( overflow != 0 || total > 0 || strangeout != 0 )
checktoshis = 0;
if ( ASSETCHAINS_COMMISSION != 0 && height > 1 )
{
if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 )
{
fprintf(stderr,"ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout);
return(-1);
}
}
if ( height > 1 && checktoshis == 0 )
{
checktoshis = ((uint64_t)GetBlockSubsidy(height, Params().GetConsensus()) - block.vtx[0].vout[0].nValue);
}
if ( height >= 2 && (overflow != 0 || total > checktoshis || strangeout != 0) )
{
fprintf(stderr,"checkdeposit: ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout);
if ( strangeout != 0 )
fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched);
return(-1);

View File

@@ -64,7 +64,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp
if ( ptr != 0 )
{
duration = komodo_kvduration(ptr->flags);
//printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize);
fprintf(stderr,"duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize);
if ( current_height > (ptr->height + duration) )
{
HASH_DELETE(hh,KOMODO_KV,ptr);
@@ -88,7 +88,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp
if ( (retval= ptr->valuesize) > 0 )
memcpy(value,ptr->value,retval);
}
}
} else fprintf(stderr,"couldnt find (%s)\n",(char *)key);
portable_mutex_unlock(&KOMODO_KV_mutex);
if ( retval < 0 )
{
@@ -112,12 +112,12 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
{
static uint32_t counter;
if ( ++counter < 1 )
printf("komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen);
fprintf(stderr,"komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen);
return;
}
valueptr = &key[keylen];
fee = komodo_kvfee(flags,opretlen,keylen);
//printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
if ( value >= fee )
{
coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1);
@@ -142,7 +142,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
{
if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
{
printf("komodo_kvsigverify error [%d]\n",coresize-13);
fprintf(stderr,"komodo_kvsigverify error [%d]\n",coresize-13);
return;
}
}
@@ -151,6 +151,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
HASH_FIND(hh,KOMODO_KV,key,keylen,ptr);
if ( ptr != 0 )
{
fprintf(stderr,"(%s) already there\n",(char *)key);
//if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 )
{
tstr = (char *)"transfer:";
@@ -171,7 +172,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
memcpy(ptr->key,key,keylen);
newflag = 1;
HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr);
//printf("KV add.(%s) (%s)\n",ptr->key,valueptr);
fprintf(stderr,"KV add.(%s) (%s)\n",ptr->key,valueptr);
}
if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 )
{
@@ -193,7 +194,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
ptr->height = height;
ptr->flags = flags; // jl777 used to or in KVPROTECTED
portable_mutex_unlock(&KOMODO_KV_mutex);
} else fprintf(stderr,"size mismatch %d vs %d\n",opretlen,coresize);
} else fprintf(stderr,"KV update size mismatch %d vs %d\n",opretlen,coresize);
} else fprintf(stderr,"not enough fee\n");
}

View File

@@ -392,7 +392,7 @@ struct notarized_checkpoint *komodo_npptr(int32_t height)
for (i=sp->NUM_NPOINTS-1; i>=0; i--)
{
np = &sp->NPOINTS[i];
if ( np->MoMdepth > 0 && height > np->notarized_height-np->MoMdepth && height <= np->notarized_height )
if ( np->MoMdepth != 0 && height > np->notarized_height-(np->MoMdepth&0xffff) && height <= np->notarized_height )
return(np);
}
}
@@ -447,7 +447,7 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in
*MoMoMdepthp = np->MoMoMdepth;
*kmdstartip = np->kmdstarti;
*kmdendip = np->kmdendi;
return(np->MoMdepth);
return(np->MoMdepth & 0xffff);
}
*notarized_htp = *MoMoMoffsetp = *MoMoMdepthp = *kmdstartip = *kmdendip = 0;
memset(MoMp,0,sizeof(*MoMp));

View File

@@ -809,7 +809,7 @@ uint16_t komodo_calcport(char *name,uint64_t supply,uint64_t endsubsidy,uint64_t
decay = 0;
printf("decay cant be more than 100000000\n");
}
if ( endsubsidy != 0 || reward != 0 || halving != 0 || decay != 0 || commission != 0 || cc != 0 || staked != 0 )
if ( endsubsidy != 0 || reward != 0 || halving != 0 || decay != 0 || commission != 0 || cc != 0 || staked != 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
{
//printf("end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,(long long)commission);
extraptr = extrabuf;
@@ -826,7 +826,7 @@ uint16_t komodo_calcport(char *name,uint64_t supply,uint64_t endsubsidy,uint64_t
int main(int argc, char * argv[])
{
uint16_t rpcport; int32_t i,j,offset=0,num = 1; uint64_t supply=10,commission=0,endsubsidy,reward,halving,decay; uint8_t *allocated=0,staked=0; uint32_t cc = 1;
uint16_t rpcport; int32_t i,j,offset=0,jsonflag=0,num = 1; uint64_t supply=10,commission=0,endsubsidy,reward,halving,decay; uint8_t *allocated=0,staked=0; uint32_t cc = 3;
endsubsidy = reward = halving = decay = 0;
if ( argc < 2 )
{
@@ -835,9 +835,11 @@ int main(int argc, char * argv[])
printf("%s -gen num name supply endsubsidy reward halving decay\n",argv[0]);
return(-1);
}
if ( strcmp(argv[1],"-gen") == 0 )
if ( strncmp(argv[1],"-gen",3) == 0 )
{
num = atoi(argv[2]);
if ( strcmp(argv[1],"-genjson") == 0 )
jsonflag = 1;
offset = 2;
allocated = calloc(1,1 << 16);
}
@@ -852,7 +854,7 @@ int main(int argc, char * argv[])
if ( argc > offset + 6 )
decay = (long long)atof(argv[offset + 6]);
rpcport = 1 + komodo_calcport(argv[offset + 1],supply,endsubsidy,reward,halving,decay,commission,staked,cc);
printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n",argv[offset + 1],cc,(long long)supply,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport);
printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n[",argv[offset + 1],cc,(long long)supply,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport);
if ( allocated != 0 )
{
char name[64],newname[64];
@@ -868,7 +870,14 @@ int main(int argc, char * argv[])
rpcport = 1 + komodo_calcport(newname,supply+j,endsubsidy,reward,halving,decay,commission,staked,cc);
if ( allocated[rpcport] == 0 && allocated[rpcport-1] == 0 )
{
printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n",newname,cc,(long long)supply+j,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport);
if ( jsonflag == 0 )
{
printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n",newname,cc,(long long)supply+j,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport);
}
else
{
printf("{ \"assetname\": \"%s\", \"p2p\": %u, \"rpc\": %u, \"supply\": %llu, \"ac_cc\": %u, \"ac_reward\": %llu, \"notarize\": %s }%s ",newname,rpcport-1,rpcport,(long long)supply+j,cc,(long long)reward,i<64?"true":"false",i<num-1?",":"");
}
allocated[rpcport] = 1;
allocated[rpcport-1] = 1;
break;
@@ -878,5 +887,6 @@ int main(int argc, char * argv[])
}
free(allocated);
}
printf("]\n");
return(0);
}

View File

@@ -1559,7 +1559,7 @@ void komodo_args(char *argv0)
ASSETCHAINS_DECAY = 0;
printf("ASSETCHAINS_DECAY cant be more than 100000000\n");
}
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 && ASSETCHAINS_COMMISSION > 0 && ASSETCHAINS_COMMISSION <= 100000000 )
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 )
decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str());
else if ( ASSETCHAINS_COMMISSION != 0 )
{

View File

@@ -585,6 +585,15 @@ CBlockTreeDB *pblocktree = NULL;
#define KOMODO_ZCASH
#include "komodo.h"
int64_t komodo_snapshot()
{
int64_t total = -1;
if ( pblocktree != 0 )
total = pblocktree->Snapshot();
else fprintf(stderr,"null pblocktree start with -addressindex=true\n");
return(total);
}
//////////////////////////////////////////////////////////////////////////////
//
// mapOrphanTransactions
@@ -3779,7 +3788,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,
{
if (blockhdr.GetBlockTime() < GetAdjustedTime() + 600)
*futureblockp = 1;
LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime());
//LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime());
return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new");
}
}
@@ -4273,7 +4282,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
if ( checked != 0 && komodo_checkPOW(from_miner && ASSETCHAINS_STAKED == 0,pblock,height) < 0 )
{
checked = 0;
fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0);
//fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0);
}
if (!checked && futureblock == 0)
{
@@ -5147,10 +5156,11 @@ void static CheckBlockIndex()
// Build forward-pointing map of the entire block tree.
std::multimap<CBlockIndex*,CBlockIndex*> forward;
for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); it++) {
forward.insert(std::make_pair(it->second->pprev, it->second));
if ( it->second != 0 )
forward.insert(std::make_pair(it->second->pprev, it->second));
}
assert(forward.size() == mapBlockIndex.size());
if ( Params().NetworkIDString() != "regtest" )
assert(forward.size() == mapBlockIndex.size());
std::pair<std::multimap<CBlockIndex*,CBlockIndex*>::iterator,std::multimap<CBlockIndex*,CBlockIndex*>::iterator> rangeGenesis = forward.equal_range(NULL);
CBlockIndex *pindex = rangeGenesis.first->second;

View File

@@ -108,9 +108,12 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE;
extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern std::string NOTARY_PUBKEY;
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY;
void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len);
extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33];
uint32_t Mining_start,Mining_height;
int32_t My_notaryid = -1;
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize);
//uint64_t komodo_paxtotal();
@@ -123,10 +126,12 @@ uint64_t komodo_commission(const CBlock *block);
int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig);
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33);
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
{
uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params();
// Create new block
if ( gpucount < 0 )
gpucount = KOMODO_MAXGPUCOUNT;
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
if(!pblocktemplate.get())
{
@@ -409,19 +414,17 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
{
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr;
CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
//if ( blocktime > pindexPrev->GetMedianTimePast()+60 )
// blocktime = pindexPrev->GetMedianTimePast() + 60;
if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 )
{
CAmount txfees = 0;
if ( GetAdjustedTime() < blocktime-13 )
if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-13 )
return(0);
pblock->vtx.push_back(txStaked);
pblocktemplate->vTxFees.push_back(txfees);
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked));
nFees += txfees;
pblock->nTime = blocktime;
//printf("PoS ht.%d t%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime);
printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13)));
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
}
@@ -439,7 +442,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
pblock->vtx[0] = txNew;
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 )
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 )
{
int32_t i; uint8_t *ptr;
txNew.vout.resize(2);
@@ -471,18 +474,31 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
}
pblock->nSolution.clear();
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && My_notaryid >= 0 )
{
uint32_t r;
CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
if ( pblock->nTime < pindexPrev->nTime+65 )
pblock->nTime = pindexPrev->nTime + 65;
if ( pblock->nTime < pindexPrev->nTime+60 )
pblock->nTime = pindexPrev->nTime + 60;
if ( gpucount < 33 )
{
uint8_t tmpbuffer[40]; uint32_t r; int32_t n=0; uint256 randvals;
memcpy(&tmpbuffer[n],&My_notaryid,sizeof(My_notaryid)), n += sizeof(My_notaryid);
memcpy(&tmpbuffer[n],&Mining_height,sizeof(Mining_height)), n += sizeof(Mining_height);
memcpy(&tmpbuffer[n],&pblock->hashPrevBlock,sizeof(pblock->hashPrevBlock)), n += sizeof(pblock->hashPrevBlock);
vcalc_sha256(0,(uint8_t *)&randvals,tmpbuffer,n);
memcpy(&r,&randvals,sizeof(r));
pblock->nTime += (r % (33 - gpucount)*(33 - gpucount));
}
if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 )
{
CAmount txfees = 0;
CAmount txfees = 5000;
pblock->vtx.push_back(txNotary);
pblocktemplate->vTxFees.push_back(txfees);
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary));
nFees += txfees;
pblocktemplate->vTxFees[0] = -nFees;
//*(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees;
//fprintf(stderr,"added notaryvin\n");
}
else
@@ -582,10 +598,14 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
// Internal miner
//
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount)
{
CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i;
if ( USE_EXTERNAL_PUBKEY != 0 )
if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
{
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
}
else if ( USE_EXTERNAL_PUBKEY != 0 )
{
//fprintf(stderr,"use notary pubkey\n");
scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
@@ -605,7 +625,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
script[34] = OP_CHECKSIG;
//scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
}
return CreateNewBlock(scriptPubKey);
return CreateNewBlock(scriptPubKey,gpucount);
}
void komodo_broadcast(CBlock *pblock,int32_t limit)
@@ -712,7 +732,7 @@ void static BitcoinMiner()
unsigned int n = chainparams.EquihashN();
unsigned int k = chainparams.EquihashK();
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,notaryid = -1;
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 &&
{
sleep(1);
@@ -720,7 +740,8 @@ void static BitcoinMiner()
break;
}
komodo_chosennotary(&notaryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime());
if ( notaryid != My_notaryid )
My_notaryid = notaryid;
std::string solver;
//if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 )
solver = "tromp";
@@ -766,11 +787,6 @@ void static BitcoinMiner()
//fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL);
miningTimer.start();
}
/*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT )
{
fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight);
sleep(3);
}*/
//
// Create new block
//
@@ -787,7 +803,7 @@ void static BitcoinMiner()
sleep(3);
}
#ifdef ENABLE_WALLET
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey);
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1,gpucount);
#else
CBlockTemplate *ptr = CreateNewBlockWithKey();
#endif
@@ -830,7 +846,7 @@ void static BitcoinMiner()
//
// Search
//
uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime();
uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime();
savebits = pblock->nBits;
HASHTarget = arith_uint256().SetCompact(pblock->nBits);
roundrobin_delay = ROUNDROBIN_DELAY;
@@ -869,18 +885,8 @@ void static BitcoinMiner()
if ( mids[j] == -1 )
gpucount++;
}
if ( gpucount > j/2 )
{
double delta;
if ( notaryid < 0 )
i = (rand() % 64);
else i = ((Mining_height + notaryid) % 64);
delta = sqrt((double)gpucount - j/2) / 2.;
roundrobin_delay += ((delta * i) / 64) - delta;
//fprintf(stderr,"delta.%f %f %f\n",delta,(double)(gpucount - j/3) / 2,(delta * i) / 64);
}
if ( dispflag != 0 )
fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u %d\n",pindexPrev->nHeight,notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL),roundrobin_delay);
fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u\n",pindexPrev->nHeight,notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL));
}
for (j=0; j<65; j++)
if ( mids[j] == notaryid )
@@ -933,7 +939,7 @@ void static BitcoinMiner()
// (x_1, x_2, ...) = A(I, V, n, k)
LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString());
arith_uint256 hashTarget;
if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 )
if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 )
hashTarget = HASHTarget_POW;
else hashTarget = HASHTarget;
std::function<bool(std::vector<unsigned char>)> validBlock =
@@ -950,8 +956,6 @@ void static BitcoinMiner()
solutionTargetChecks.increment();
B = *pblock;
h = UintToArith256(B.GetHash());
if ( h > hashTarget )
return false;
/*for (z=31; z>=16; z--)
fprintf(stderr,"%02x",((uint8_t *)&h)[z]);
fprintf(stderr," mined ");
@@ -961,6 +965,8 @@ void static BitcoinMiner()
for (z=31; z>=16; z--)
fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]);
fprintf(stderr," POW\n");*/
if ( h > hashTarget )
return false;
if ( NOTARY_PUBKEY33[0] != 0 && B.nTime > GetAdjustedTime() )
{
fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime()));

View File

@@ -25,12 +25,13 @@ struct CBlockTemplate
std::vector<CAmount> vTxFees;
std::vector<int64_t> vTxSigOps;
};
#define KOMODO_MAXGPUCOUNT 65
/** Generate a new block, without valid proof-of-work */
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount);
#ifdef ENABLE_WALLET
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount);
#else
boost::optional<CScript> GetMinerScriptPubKey();
CBlockTemplate* CreateNewBlockWithKey();

View File

@@ -86,6 +86,8 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param
unsigned int n = params.EquihashN();
unsigned int k = params.EquihashK();
if ( Params().NetworkIDString() == "regtest" )
return(true);
// Hash state
crypto_generichash_blake2b_state state;
EhInitialiseState(n, k, state);

View File

@@ -32,6 +32,7 @@
using namespace std;
/**
* Return average network hashes per second based on the last 'lookup' blocks,
* or over the difficulty averaging window if 'lookup' is nonpositive.
@@ -214,7 +215,7 @@ UniValue generate(const UniValue& params, bool fHelp)
lastTime = GetTime();
#ifdef ENABLE_WALLET
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey,nHeight,KOMODO_MAXGPUCOUNT));
#else
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey());
#endif
@@ -639,7 +640,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
}
#ifdef ENABLE_WALLET
CReserveKey reservekey(pwalletMain);
pblocktemplate = CreateNewBlockWithKey(reservekey);
pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1,KOMODO_MAXGPUCOUNT);
#else
pblocktemplate = CreateNewBlockWithKey();
#endif
@@ -692,7 +693,8 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
// Correct this if GetBlockTemplate changes the order
// entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue));
//}
entry.push_back(Pair("coinbasevalue", 3*COIN));
CAmount nReward = GetBlockSubsidy(chainActive.Tip()->nHeight+1, Params().GetConsensus());
entry.push_back(Pair("coinbasevalue", nReward));
entry.push_back(Pair("required", true));
txCoinbase = entry;
} else

View File

@@ -52,6 +52,7 @@ int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp);
extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
uint32_t komodo_segid32(char *coinaddr);
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
#define KOMODO_VERSION "0.1.1"
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
@@ -326,7 +327,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp)
CScript scriptPubKey = GetScriptForDestination(dest);
ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
ret.push_back(Pair("segid", (int32_t)komodo_segid32((char *)params[0].get_str().c_str()) & 0x3f));
#ifdef ENABLE_WALLET
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
@@ -633,12 +634,12 @@ bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint16
uint160 hashBytes;
int type = 0;
if (!address.GetIndexKey(hashBytes, type)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid addresses");
}
addresses.push_back(std::make_pair(hashBytes, type));
}
} else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid addresse");
}
return true;
@@ -681,8 +682,8 @@ UniValue getaddressmempool(const UniValue& params, bool fHelp)
" }\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getaddressmempool", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
+ HelpExampleRpc("getaddressmempool", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
+ HelpExampleCli("getaddressmempool", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'")
+ HelpExampleRpc("getaddressmempool", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}")
);
std::vector<std::pair<uint160, int> > addresses;
@@ -752,8 +753,8 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
" }\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
+ HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
+ HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'")
+ HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}")
);
bool includeChainInfo = false;
@@ -839,8 +840,8 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
" }\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
+ HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
+ HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'")
+ HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}")
);
@@ -956,8 +957,8 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp)
" \"received\" (string) The total number of satoshis received (including change)\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
+ HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
+ HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'")
+ HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}")
);
std::vector<std::pair<uint160, int> > addresses;
@@ -992,6 +993,23 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp)
}
int32_t komodo_snapshot();
UniValue getsnapshot(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); int64_t total;
if ( fHelp || params.size() > 0 )
{
throw runtime_error(
"getsnapshot\n"
);
}
if ( (total= komodo_snapshot()) >= 0 )
result.push_back(Pair("total", (double)total/COIN));
else result.push_back(Pair("error", "no addressindex"));
return(result);
}
UniValue getaddresstxids(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
@@ -1014,8 +1032,8 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp)
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'")
+ HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}")
+ HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'")
+ HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}")
);
std::vector<std::pair<uint160, int> > addresses;

View File

@@ -345,6 +345,7 @@ static const CRPCCommand vRPCCommands[] =
{ "addressindex", "getaddressdeltas", &getaddressdeltas, false },
{ "addressindex", "getaddresstxids", &getaddresstxids, false },
{ "addressindex", "getaddressbalance", &getaddressbalance, false },
{ "addressindex", "getsnapshot", &getsnapshot, false },
/* Utility functions */
{ "util", "createmultisig", &createmultisig, true },

View File

@@ -177,6 +177,7 @@ extern UniValue getaddressmempool(const UniValue& params, bool fHelp);
extern UniValue getaddressutxos(const UniValue& params, bool fHelp);
extern UniValue getaddressdeltas(const UniValue& params, bool fHelp);
extern UniValue getaddresstxids(const UniValue& params, bool fHelp);
extern UniValue getsnapshot(const UniValue& params, bool fHelp);
extern UniValue getaddressbalance(const UniValue& params, bool fHelp);
extern UniValue getpeerinfo(const UniValue& params, bool fHelp);
extern UniValue ping(const UniValue& params, bool fHelp);

View File

@@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i)
{
// Simple block creation, nothing special yet:
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
pblock->nVersion = 4;
@@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
}
// Just to make sure we can still make simple blocks
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
// block sigops > limit: 1000 CHECKMULTISIG + 1
@@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
mempool.clear();
@@ -310,14 +310,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
mempool.clear();
// orphan in mempool
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
mempool.clear();
@@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = 49000LL;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
mempool.clear();
@@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = 0;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
mempool.clear();
@@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue -= 10000;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
mempool.clear();
@@ -378,17 +378,17 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].scriptPubKey = CScript() << OP_2;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
mempool.clear();
// subsidy changing
int nHeight = chainActive.Height();
chainActive.Tip()->nHeight = 209999;
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
chainActive.Tip()->nHeight = 210000;
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
chainActive.Tip()->nHeight = nHeight;
@@ -420,7 +420,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx2));
BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
// Neither tx should have made it into the template.
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1);
@@ -435,7 +435,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
//BOOST_CHECK(CheckFinalTx(tx));
//BOOST_CHECK(CheckFinalTx(tx2));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2);
delete pblocktemplate;

View File

@@ -396,6 +396,50 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type,
return true;
}
bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address);
int64_t CBlockTreeDB::Snapshot()
{
char chType; int64_t total = -1; std::string address;
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
pcursor->SeekToFirst();
fprintf(stderr,"pcursor iterate\n");
while (pcursor->Valid())
{
boost::this_thread::interruption_point();
try
{
leveldb::Slice slKey = pcursor->key();
CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION);
CAddressIndexKey indexKey;
ssKey >> chType;
ssKey >> indexKey;
fprintf(stderr,"chType.%d\n",chType);
if ( chType == DB_ADDRESSINDEX )
{
try {
leveldb::Slice slValue = pcursor->value();
CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION);
CAmount nValue;
ssValue >> nValue;
getAddressFromIndex(indexKey.type, indexKey.hashBytes, address);
fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN);
if ( total < 0 )
total = (int64_t)nValue;
else total += (int64_t)nValue;
//addressIndex.push_back(make_pair(indexKey, nValue));
pcursor->Next();
} catch (const std::exception& e) {
return error("failed to get address index value");
}
} else { break; }
} catch (const std::exception& e) {
break;
}
}
return(total);
}
bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey &timestampIndex) {
CLevelDBBatch batch;
batch.Write(make_pair(DB_TIMESTAMPINDEX, timestampIndex), 0);

View File

@@ -94,6 +94,7 @@ public:
bool ReadFlag(const std::string &name, bool &fValue);
bool LoadBlockIndexGuts();
bool blockOnchainActive(const uint256 &hash);
int64_t Snapshot();
};
#endif // BITCOIN_TXDB_H

View File

@@ -2696,29 +2696,35 @@ UniValue listunspent(const UniValue& params, bool fHelp)
uint64_t komodo_interestsum()
{
uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime;
vector<COutput> vecOutputs;
assert(pwalletMain != NULL);
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
BOOST_FOREACH(const COutput& out,vecOutputs)
#ifdef ENABLE_WALLET
if ( GetBoolArg("-disablewallet", false) == 0 )
{
CAmount nValue = out.tx->vout[out.i].nValue;
if ( out.tx->nLockTime != 0 && out.fSpendable != 0 )
uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime;
vector<COutput> vecOutputs;
assert(pwalletMain != NULL);
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
BOOST_FOREACH(const COutput& out,vecOutputs)
{
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *tipindex,*pindex = it->second;
if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 )
CAmount nValue = out.tx->vout[out.i].nValue;
if ( out.tx->nLockTime != 0 && out.fSpendable != 0 )
{
interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
//interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime);
sum += interest;
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *tipindex,*pindex = it->second;
if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 )
{
interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
//interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime);
sum += interest;
}
}
}
KOMODO_INTERESTSUM = sum;
KOMODO_WALLETBALANCE = pwalletMain->GetBalance();
return(sum);
}
KOMODO_INTERESTSUM = sum;
KOMODO_WALLETBALANCE = pwalletMain->GetBalance();
return(sum);
#endif
return(0);
}
UniValue fundrawtransaction(const UniValue& params, bool fHelp)
@@ -4519,7 +4525,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33)
txNew.vin.resize(1);
txNew.vout.resize(1);
txfee = utxovalue / 2;;
txfee = utxovalue / 2;
//for (i=0; i<32; i++)
// ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i];
txNew.vin[0].prevout.hash = utxotxid; //revtxid;
@@ -4546,7 +4552,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33)
int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig)
{
set<CBitcoinAddress> setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector<COutput> vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow;
set<CBitcoinAddress> setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector<COutput> vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow;
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
assert(pwalletMain != NULL);
LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -4558,14 +4564,23 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
BOOST_FOREACH(const COutput& out, vecOutputs)
{
if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth )
{
fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth);
continue;
}
if ( setAddress.size() )
{
CTxDestination address;
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
{
fprintf(stderr,"komodo_staked ExtractDestination error\n");
continue;
}
if (!setAddress.count(address))
{
fprintf(stderr,"komodo_staked setAddress.count error\n");
continue;
}
}
CAmount nValue = out.tx->vout[out.i].nValue;
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
@@ -4596,10 +4611,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str());
*utxovoutp = out.i;
*txtimep = (uint32_t)out.tx->nLockTime;
fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep);
//fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep);
}
}
}
} //else fprintf(stderr,"utxo not eligible\n");
} //else fprintf(stderr,"no tipindex\n");
}
if ( earliest != 0 )
{
@@ -4631,6 +4646,6 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
//fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep));
*blocktimep = earliest;
}
}
} else fprintf(stderr,"no earliest utxo for staking\n");
return(siglen);
}