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

merge
This commit is contained in:
blackjok3r
2018-11-29 23:22:32 +08:00
566 changed files with 42751 additions and 10240 deletions

View File

@@ -15,18 +15,16 @@
// komodo functions that interact with bitcoind C++
#ifdef _WIN32
#include <curl/curl.h>
#include <curl/easy.h>
#else
#include <curl/curl.h>
#include <curl/easy.h>
#endif
#include "primitives/nonce.h"
#include "consensus/params.h"
#include "komodo_defs.h"
#include "script/standard.h"
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp);
unsigned int lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus::Params& params);
//#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7776",0,0,(char *)(cmdstr))
@@ -557,7 +555,7 @@ uint64_t komodo_seed(int32_t height)
return(seed);
}
uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr)
uint32_t komodo_txtime(uint64_t *valuep,uint256 hash, int32_t n, char *destaddr)
{
CTxDestination address; CTransaction tx; uint256 hashBlock;
*valuep = 0;
@@ -580,6 +578,12 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr)
return(tx.nLockTime);
}
CBlockIndex *komodo_getblockindex(uint256 hash)
{
BlockMap::const_iterator it = mapBlockIndex.find(hash);
return((it != mapBlockIndex.end()) ? it->second : NULL);
}
uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr)
{
CTxDestination address; CBlockIndex *pindex; CTransaction tx; uint256 hashBlock; uint32_t txtime = 0;
@@ -593,7 +597,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr)
//fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
return(0);
}
if ( (pindex= mapBlockIndex[hashBlock]) != 0 )
if ( (pindex= komodo_getblockindex(hashBlock)) != 0 )
txtime = pindex->nTime;
else txtime = tx.nLockTime;
//fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
@@ -633,13 +637,13 @@ int32_t komodo_isPoS(CBlock *pblock)
void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
{
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
//fprintf(stderr,"disconnect ht.%d\n",pindex->nHeight);
komodo_init(pindex->nHeight);
//fprintf(stderr,"disconnect ht.%d\n",pindex->GetHeight());
komodo_init(pindex->GetHeight());
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
{
//sp->rewinding = pindex->nHeight;
//fprintf(stderr,"-%d ",pindex->nHeight);
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->nHeight,ASSETCHAINS_SYMBOL);
//sp->rewinding = pindex->GetHeight();
//fprintf(stderr,"-%d ",pindex->GetHeight());
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->GetHeight(),ASSETCHAINS_SYMBOL);
}
int32_t komodo_is_notarytx(const CTransaction& tx)
@@ -647,11 +651,7 @@ int32_t komodo_is_notarytx(const CTransaction& tx)
uint8_t *ptr; static uint8_t crypto777[33];
if ( tx.vout.size() > 0 )
{
#ifdef KOMODO_ZCASH
ptr = (uint8_t *)tx.vout[0].scriptPubKey.data();
#else
ptr = (uint8_t *)&tx.vout[0].scriptPubKey[0];
#endif
if ( ptr != 0 )
{
if ( crypto777[0] == 0 )
@@ -669,20 +669,17 @@ int32_t komodo_is_notarytx(const CTransaction& tx)
int32_t komodo_block2height(CBlock *block)
{
static uint32_t match,mismatch;
int32_t i,n,height2=-1,height = 0; uint8_t *ptr; CBlockIndex *pindex;
if ( (pindex= mapBlockIndex[block->GetHash()]) != 0 )
int32_t i,n,height2=-1,height = 0; uint8_t *ptr; CBlockIndex *pindex = NULL;
BlockMap::const_iterator it = mapBlockIndex.find(block->GetHash());
if ( it != mapBlockIndex.end() && (pindex = it->second) != 0 )
{
height2 = (int32_t)pindex->nHeight;
height2 = (int32_t)pindex->GetHeight();
if ( height2 >= 0 )
return(height2);
}
if ( block != 0 && block->vtx[0].vin.size() > 0 )
if ( pindex && block != 0 && block->vtx[0].vin.size() > 0 )
{
#ifdef KOMODO_ZCASH
ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data();
#else
ptr = (uint8_t *)&block->vtx[0].vin[0].scriptSig[0];
#endif
if ( ptr != 0 && block->vtx[0].vin[0].scriptSig.size() > 5 )
{
//for (i=0; i<6; i++)
@@ -716,18 +713,19 @@ int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block)
else memset(pubkey33,0,33);
if ( block->vtx[0].vout.size() > 0 )
{
#ifdef KOMODO_ZCASH
uint8_t *ptr = (uint8_t *)block->vtx[0].vout[0].scriptPubKey.data();
#else
uint8_t *ptr = (uint8_t *)&block->vtx[0].vout[0].scriptPubKey[0];
#endif
//komodo_init(0);
n = block->vtx[0].vout[0].scriptPubKey.size();
if ( n == 35 )
txnouttype whichType;
vector<vector<unsigned char>> vch = vector<vector<unsigned char>>();
if (Solver(block->vtx[0].vout[0].scriptPubKey, whichType, vch) && whichType == TX_PUBKEY)
{
memcpy(pubkey33,ptr+1,33);
return(1);
CPubKey pubKey(vch[0]);
if (pubKey.IsValid())
{
memcpy(pubkey33,vch[0].data(),33);
return true;
}
else memset(pubkey33,0,33);
}
else memset(pubkey33,0,33);
}
return(0);
}
@@ -758,11 +756,11 @@ uint32_t komodo_chainactive_timestamp()
CBlockIndex *komodo_chainactive(int32_t height)
{
if ( chainActive.Tip() != 0 )
if ( chainActive.LastTip() != 0 )
{
if ( height <= chainActive.LastTip()->nHeight )
if ( height <= chainActive.LastTip()->GetHeight() )
return(chainActive[height]);
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->nHeight);
// else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->GetHeight());
}
//fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height);
return(0);
@@ -782,7 +780,7 @@ uint32_t komodo_heightstamp(int32_t height)
int32_t i,num; uint8_t pubkeys[64][33]; CBlock block;
if ( pindex->didinit != 0 )
return;
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->nHeight,pindex->notaryid,height);
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->GetHeight(),pindex->notaryid,height);
if ( pindex->didinit == 0 )
{
pindex->notaryid = -1;
@@ -794,12 +792,12 @@ uint32_t komodo_heightstamp(int32_t height)
komodo_block2pubkey33(pindex->pubkey33,&block);
//for (i=0; i<33; i++)
// fprintf(stderr,"%02x",pindex->pubkey33[i]);
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->nHeight,height);
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->GetHeight(),height);
//if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
// pindex->didinit = (KOMODO_LOADINGBLOCKS == 0);
} // else fprintf(stderr,"error loading block at %d/%d",pindex->nHeight,height);
} // else fprintf(stderr,"error loading block at %d/%d",pindex->GetHeight(),height);
}
if ( pindex->didinit != 0 && pindex->nHeight >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
if ( pindex->didinit != 0 && pindex->GetHeight() >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->GetHeight(),(uint32_t)pindex->nTime)) > 0 )
{
for (i=0; i<num; i++)
{
@@ -813,7 +811,7 @@ uint32_t komodo_heightstamp(int32_t height)
{
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pindex->pubkey33[i]);
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->nHeight,height);
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->GetHeight(),height);
}
}
}*/
@@ -996,12 +994,13 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex;
if ( (pindex= chainActive.LastTip()) == 0 )
return(-1);
notarized_height = komodo_notarizeddata(pindex->nHeight,&notarized_hash,&notarized_desttxid);
notarized_height = komodo_notarizeddata(pindex->GetHeight(),&notarized_hash,&notarized_desttxid);
*notarized_heightp = notarized_height;
if ( notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
BlockMap::const_iterator it;
if ( notarized_height >= 0 && notarized_height <= pindex->GetHeight() && (it = mapBlockIndex.find(notarized_hash)) != mapBlockIndex.end() && (notary = it->second) != NULL )
{
//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
//printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->GetHeight(),notarized_height,notarized_hash.ToString().c_str());
if ( notary->GetHeight() == notarized_height ) // if notarized_hash not in chain, reorg
{
if ( nHeight < notarized_height )
{
@@ -1013,10 +1012,10 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
fprintf(stderr,"[%s] nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height);
return(-1);
}
} //else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
} //else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->GetHeight());
}
//else if ( notarized_height > 0 && notarized_height != 73880 && notarized_height >= 170000 )
// fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->nHeight);
// fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->GetHeight());
return(0);
}
@@ -1031,10 +1030,10 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_
uint32_t locktime = 0;
if ( n < tx.vout.size() )
{
if ( (pindex= mapBlockIndex[hashBlock]) != 0 )
if ( (pindex= komodo_getblockindex(hashBlock)) != 0 )
{
*valuep = tx.vout[n].nValue;
*txheightp = pindex->nHeight;
*txheightp = pindex->GetHeight();
*txheighttimep = pindex->nTime;
if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 )
*tiptimep = (uint32_t)tipindex->nTime;
@@ -1063,13 +1062,21 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256
return(0);
}
int32_t komodo_nextheight()
{
CBlockIndex *pindex; int32_t ht,longest = komodo_longestchain();
if ( (pindex= chainActive.LastTip()) != 0 && (ht= pindex->GetHeight()) >= longest )
return(ht+1);
else return(longest + 1);
}
int32_t komodo_isrealtime(int32_t *kmdheightp)
{
struct komodo_state *sp; CBlockIndex *pindex;
if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 )
*kmdheightp = sp->CURRENT_HEIGHT;
else *kmdheightp = 0;
if ( (pindex= chainActive.LastTip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() )
if ( (pindex= chainActive.LastTip()) != 0 && pindex->GetHeight() >= (int32_t)komodo_longestchain() )
return(1);
else return(0);
}
@@ -1397,7 +1404,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress;
if ( ASSETCHAINS_STAKED == 100 && height <= 10 )
return(1);
pindex = mapBlockIndex[pblock->GetHash()];
BlockMap::const_iterator it = mapBlockIndex.find(pblock->GetHash());
pindex = it != mapBlockIndex.end() ? it->second : NULL;
if ( pindex != 0 && pindex->segid >= -1 )
{
if ( pindex->segid == -1 )
@@ -1407,11 +1415,10 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
txn_count = pblock->vtx.size();
if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 )
{
if ( prevtime == 0 )
{
if ( (previndex= mapBlockIndex[pblock->hashPrevBlock]) != 0 )
prevtime = (uint32_t)previndex->nTime;
}
it = mapBlockIndex.find(pblock->hashPrevBlock);
if ( it != mapBlockIndex.end() && (previndex = it->second) != NULL )
prevtime = (uint32_t)previndex->nTime;
txid = pblock->vtx[txn_count-1].vin[0].prevout.hash;
vout = pblock->vtx[txn_count-1].vin[0].prevout.n;
if ( prevtime != 0 )
@@ -1472,6 +1479,185 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
return(isPoS != 0);
}
bool GetStakeParams(const CTransaction &stakeTx, CStakeParams &stakeParams);
bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating);
// for now, we will ignore slowFlag in the interest of keeping success/fail simpler for security purposes
bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
{
CBlockIndex *pastBlockIndex;
uint256 txid, blkHash;
int32_t txn_count;
uint32_t voutNum;
CAmount value;
bool isPOS = false;
CTxDestination voutaddress, destaddress, cbaddress;
arith_uint256 target, hash;
CTransaction tx;
if (!pblock->IsVerusPOSBlock())
{
printf("%s, height %d not POS block\n", pblock->nNonce.GetHex().c_str(), height);
//pblock->nNonce.SetPOSTarget(pblock->nNonce.GetPOSTarget());
//printf("%s after setting POS target\n", pblock->nNonce.GetHex().c_str());
return false;
}
char voutaddr[64], destaddr[64], cbaddr[64];
txn_count = pblock->vtx.size();
if ( txn_count > 1 )
{
target.SetCompact(pblock->GetVerusPOSTarget());
txid = pblock->vtx[txn_count-1].vin[0].prevout.hash;
voutNum = pblock->vtx[txn_count-1].vin[0].prevout.n;
value = pblock->vtx[txn_count-1].vout[0].nValue;
{
bool validHash = (value != 0);
bool enablePOSNonce = CPOSNonce::NewPOSActive(height);
uint256 rawHash;
arith_uint256 posHash;
if (validHash && enablePOSNonce)
{
validHash = pblock->GetRawVerusPOSHash(rawHash, height);
posHash = UintToArith256(rawHash) / value;
if (!validHash || posHash > target)
{
validHash = false;
printf("ERROR: invalid nonce value for PoS block\nnNonce: %s\nrawHash: %s\nposHash: %s\nvalue: %lu\n",
pblock->nNonce.GetHex().c_str(), rawHash.GetHex().c_str(), posHash.GetHex().c_str(), value);
}
}
if (validHash)
{
if (slowflag == 0)
{
isPOS = true;
}
else if (!(pastBlockIndex = komodo_chainactive(height - 100)))
{
fprintf(stderr,"ERROR: chain not fully loaded or invalid PoS block %s - no past block found\n",blkHash.ToString().c_str());
}
else
#ifndef KOMODO_ZCASH
if (!GetTransaction(txid, tx, Params().GetConsensus(), blkHash, true))
#else
if (!GetTransaction(txid, tx, blkHash, true))
#endif
{
fprintf(stderr,"ERROR: invalid PoS block %s - no source transaction\n",blkHash.ToString().c_str());
}
else
{
CBlockHeader bh = pastBlockIndex->GetBlockHeader();
uint256 pastHash = bh.GetVerusEntropyHash(height - 100);
// if height is over when Nonce is required to be the new format, we check that the new format is correct
// if over when we have the new POS hash function, we validate that as well
// they are 100 blocks apart
CPOSNonce nonce = pblock->nNonce;
//printf("before nNonce: %s, height: %d\n", pblock->nNonce.GetHex().c_str(), height);
//validHash = pblock->GetRawVerusPOSHash(rawHash, height);
//hash = UintToArith256(rawHash) / tx.vout[voutNum].nValue;
//printf("Raw POShash: %s\n", hash.GetHex().c_str());
hash = UintToArith256(tx.GetVerusPOSHash(&nonce, voutNum, height, pastHash));
//printf("after nNonce: %s, height: %d\n", nonce.GetHex().c_str(), height);
//printf("POShash: %s\n\n", hash.GetHex().c_str());
if (posHash == hash && hash <= target)
{
BlockMap::const_iterator it = mapBlockIndex.find(blkHash);
if ((it == mapBlockIndex.end()) ||
!(pastBlockIndex = it->second) ||
(height - pastBlockIndex->GetHeight()) < VERUS_MIN_STAKEAGE)
{
fprintf(stderr,"ERROR: invalid PoS block %s - stake source too new or not found\n",blkHash.ToString().c_str());
}
else
{
// make sure we have the right target
CBlockIndex *previndex;
it = mapBlockIndex.find(pblock->hashPrevBlock);
if (it == mapBlockIndex.end() || !(previndex = it->second))
{
fprintf(stderr,"ERROR: invalid PoS block %s - no prev block found\n",blkHash.ToString().c_str());
}
else
{
arith_uint256 cTarget;
uint32_t nBits = lwmaGetNextPOSRequired(previndex, Params().GetConsensus());
cTarget.SetCompact(nBits);
bool nonceOK = true;
// check to see how many fail
//if (nonce != pblock->nNonce)
// printf("Mismatched nNonce: %s\nblkHash: %s, height: %d\n", nonce.GetHex().c_str(), pblock->GetHash().GetHex().c_str(), height);
if (CPOSNonce::NewNonceActive(height) && !nonce.CheckPOSEntropy(pastHash, txid, voutNum))
{
fprintf(stderr,"ERROR: invalid PoS block %s - nonce entropy corrupted or forged\n",blkHash.ToString().c_str());
nonceOK = false;
}
else
{
if (cTarget != target)
{
fprintf(stderr,"ERROR: invalid PoS block %s - invalid diff target\n",blkHash.ToString().c_str());
nonceOK = false;
}
}
if ( nonceOK && ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey, voutaddress) &&
ExtractDestination(tx.vout[voutNum].scriptPubKey, destaddress) )
{
strcpy(voutaddr, CBitcoinAddress(voutaddress).ToString().c_str());
strcpy(destaddr, CBitcoinAddress(destaddress).ToString().c_str());
if ( !strcmp(destaddr,voutaddr) )
{
isPOS = true;
CTransaction &cbtx = pblock->vtx[0];
for (int i = 0; i < cbtx.vout.size(); i++)
{
if (CScriptExt::ExtractVoutDestination(cbtx, i, cbaddress))
{
strcpy(cbaddr, CBitcoinAddress(cbaddress).ToString().c_str());
if (!strcmp(destaddr,cbaddr))
continue;
}
else
{
if (cbtx.vout[i].scriptPubKey.IsOpReturn())
continue;
isPOS = false;
break;
}
}
}
else
{
fprintf(stderr,"ERROR: invalid PoS block %s - invalid stake or coinbase destination\n",blkHash.ToString().c_str());
}
}
}
}
}
else
{
printf("ERROR: malformed nonce value for PoS block\nnNonce: %s\nrawHash: %s\nposHash: %s\nvalue: %lu\n",
pblock->nNonce.GetHex().c_str(), rawHash.GetHex().c_str(), posHash.GetHex().c_str(), value);
}
}
}
}
}
return(isPOS);
}
int64_t komodo_checkcommission(CBlock *pblock,int32_t height)
{
int64_t checktoshis=0; uint8_t *script,scripthex[8192]; int32_t scriptlen,matched = 0;
@@ -1483,7 +1669,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height)
return(-1);
else*/ if ( checktoshis != 0 )
{
script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data();
script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0];
scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size();
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 )
{
@@ -1540,11 +1726,20 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
fprintf(stderr,"height.%d slowflag.%d possible.%d cmp.%d\n",height,slowflag,possible,bhash > bnTarget);
return(0);
}
if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 )
height = pprev->nHeight + 1;
BlockMap::const_iterator it = mapBlockIndex.find(pblock->hashPrevBlock);
if ( it != mapBlockIndex.end() && (pprev= it->second) != 0 )
height = pprev->GetHeight() + 1;
if ( height == 0 )
return(0);
}
if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget )
{
// if proof of stake is active, check if this is a valid PoS block before we fail
if (verusCheckPOSBlock(slowflag, pblock, height))
{
return(0);
}
}
if ( (ASSETCHAINS_SYMBOL[0] != 0 || height > 792000) && bhash > bnTarget )
{
failed = 1;
@@ -1614,7 +1809,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
}
else
{
script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data();
script = (uint8_t *)&pblock->vtx[0].vout[0].scriptPubKey[0];
if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 )
return(-1);
}
@@ -1638,7 +1833,6 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock)
for (i=0; i<n; i++)
{
CTransaction vintx,&tx = pblock->vtx[i];
zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn());
if ( (m= tx.vin.size()) > 0 )
{
for (j=0; j<m; j++)
@@ -1663,13 +1857,19 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock)
voutsum += tx.vout[j].nValue;
else printf("skip %.8f -> %s\n",dstr(tx.vout[j].nValue),CBitcoinAddress(address).ToString().c_str());
}
script = (uint8_t *)tx.vout[j].scriptPubKey.data();
script = (uint8_t *)&tx.vout[j].scriptPubKey[0];
if ( script == 0 || script[0] != 0x6a )
{
if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 )
voutsum += tx.vout[j].nValue;
}
}
BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit)
{
zfunds -= joinsplit.vpub_new;
zfunds += joinsplit.vpub_old;
}
zfunds -= tx.valueBalance;
}
*zfundsp = zfunds;
if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) // 15 times
@@ -1686,21 +1886,21 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height)
*zfundsp = 0;
if ( (pindex= komodo_chainactive(height)) != 0 )
{
while ( pindex != 0 && pindex->nHeight > 0 )
while ( pindex != 0 && pindex->GetHeight() > 0 )
{
if ( pindex->newcoins == 0 && pindex->zfunds == 0 )
{
if ( komodo_blockload(block,pindex) == 0 )
pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block);
pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->GetHeight(),&block);
else
{
fprintf(stderr,"error loading block.%d\n",pindex->nHeight);
fprintf(stderr,"error loading block.%d\n",pindex->GetHeight());
return(0);
}
}
supply += pindex->newcoins;
zfunds += pindex->zfunds;
//printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds));
//printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->GetHeight(),dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds));
pindex = pindex->pprev;
}
}