Merge pull request #14 from miketout/dev

Latest Komodo changes, spending time locked coinbases, some cleanup
This commit is contained in:
miketout
2018-05-09 00:55:45 -07:00
committed by GitHub
17 changed files with 189 additions and 66 deletions

View File

@@ -47,7 +47,6 @@ komodo_asset MNZ 257142858
komodo_asset AXO 200000000
komodo_asset ETOMIC 100000000
komodo_asset BTCH 20998641
komodo_asset VOTE2018 600000000
komodo_asset PIZZA 100000000
komodo_asset BEER 100000000
komodo_asset NINJA 100000000

View File

@@ -24,7 +24,6 @@ echo $pubkey
./komodod -pubkey=$pubkey -ac_name=AXO -ac_supply=200000000 -addnode=78.47.196.146 &
./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=78.47.196.146 &
./komodod -pubkey=$pubkey -ac_name=BTCH -ac_supply=20998641 -addnode=78.47.196.146 &
./komodod -pubkey=$pubkey -ac_name=VOTE2018 -ac_supply=600000000 -addnode=78.47.196.146 &
./komodod -pubkey=$pubkey -ac_name=BEER -ac_supply=100000000 -addnode=78.47.196.146 &
./komodod -pubkey=$pubkey -ac_name=PIZZA -ac_supply=100000000 -addnode=78.47.196.146 &
./komodod -pubkey=$pubkey -ac_name=NINJA -ac_supply=100000000 -addnode=78.47.196.146 &

View File

@@ -30,7 +30,6 @@ komodo_stop MNZ
komodo_stop AXO
komodo_stop ETOMIC
komodo_stop BTCH
komodo_stop VOTE2018
komodo_stop PIZZA
komodo_stop BEER
komodo_stop NINJA

View File

@@ -462,6 +462,7 @@ bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
const COutPoint &prevout = tx.vin[i].prevout;
const CCoins* coins = AccessCoins(prevout.hash);
if (!coins || !coins->IsAvailable(prevout.n)) {
fprintf(stderr,"HaveInputs missing input %s/v%d\n",prevout.hash.ToString().c_str(),prevout.n);
return false;
}
}

View File

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

View File

@@ -1085,12 +1085,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
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 = komodo_current_supply(nHeight);
txtime = komodo_txtime(&value,txid,vout,address);
if ( blocktime < prevtime+57 )
blocktime = prevtime+57;
if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 )
return(0);
if ( (minage= nHeight*3) > 6000 )
minage = 6000;
if ( blocktime < prevtime+57 )
blocktime = prevtime+57;
if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 )
{
vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address));

View File

@@ -48,7 +48,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig
}
else if ( strcmp(symbol,coin) == 0 )
{
if ( NOTARY_PUBKEY33[0] != 0 && verified != 0 )
if ( 0 && NOTARY_PUBKEY33[0] != 0 && verified != 0 )
fprintf(stderr,"validated [%s] ht.%d notarized %d\n",coin,height,notarizedheight);
memset(&N,0,sizeof(N));
N.blockhash = notarized_hash;

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,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;
int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256],notmatched=0; 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;
activation = 235300;
if ( *(int32_t *)&array[0] == 0 )
numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array)));
@@ -668,6 +668,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
{
for (i=0; i<txn_count; i++)
{
if ( i == 0 && txn_count > 1 && block.vtx[txn_count-1].vout.size() > 0 && block.vtx[txn_count-1].vout[0].nValue == 5000 )
{
if ( block.vtx[txn_count-1].vin.size() == 1 && GetTransaction(block.vtx[txn_count-1].vin[0].prevout.hash,tx,hash,false) && block.vtx[0].vout[0].scriptPubKey == tx.vout[block.vtx[txn_count-1].vin[0].prevout.n].scriptPubKey )
notmatched = 1;
}
n = block.vtx[i].vin.size();
for (j=0; j<n; j++)
{
@@ -683,18 +688,21 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
}
}
n = block.vtx[0].vout.size();
script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data();
//script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data();
//if ( n <= 2 || script[0] != 0x6a )
{
int64_t val,prevtotal = 0; int32_t overflow = 0;
int64_t val,prevtotal = 0; int32_t strangeout=0,overflow = 0;
total = 0;
for (i=1; i<n; i++)
{
script = (uint8_t *)block.vtx[0].vout[i].scriptPubKey.data();
if ( (val= block.vtx[0].vout[i].nValue) < 0 || val >= MAX_MONEY )
{
overflow = 1;
break;
}
if ( i > 1 && script[0] != 0x6a && val < 5000 )
strangeout++;
total += val;
if ( total < prevtotal || (val != 0 && total == prevtotal) )
{
@@ -719,11 +727,27 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
if ( height > KOMODO_NOTARIES_HEIGHT1 )
return(-1);
}
if ( strangeout != 0 || notmatched != 0 )
{
if ( strcmp(NOTARY_PUBKEY.c_str(),"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828") == 0 )
fprintf(stderr,">>>>>>>>>>>>> DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",height,strangeout,notmatched);
if ( height > 1000000 && strangeout != 0 )
return(-1);
}
else if ( height > 814000 )
{
script = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data();
return(-1 * (komodo_electednotary(&num,script+1,height,0) >= 0) * (height > 1000000));
}
}
else
{
if ( overflow != 0 || total > 0 )
if ( overflow != 0 || total > 0 || strangeout != 0 )
{
if ( strangeout != 0 )
fprintf(stderr,">>>>>>>>>>>>> DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",height,strangeout,notmatched);
return(-1);
}
}
return(0);
}

View File

@@ -2708,9 +2708,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (!tx.IsCoinBase())
{
if (!view.HaveInputs(tx))
{
return state.DoS(100, error("ConnectBlock(): inputs missing/spent"),
REJECT_INVALID, "bad-txns-inputs-missingorspent");
}
// are the JoinSplit's requirements met?
if (!view.HaveJoinSplitRequirements(tx))
return state.DoS(100, error("ConnectBlock(): JoinSplit requirements not met"),
@@ -3806,11 +3807,6 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,
return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new");
}
}
if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime )
{
fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime);
return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new");
}
// Check block version
if (height > 0 && blockhdr.nVersion < MIN_BLOCK_VERSION)
return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low");

View File

@@ -127,6 +127,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
int64_t komodo_block_unlocktime(uint32_t nHeight);
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)
{
@@ -328,7 +329,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
// Size limits
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
if (nBlockSize + nTxSize >= nBlockMaxSize)
if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx
{
//fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize);
continue;
@@ -433,22 +434,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 )
{
CAmount txfees = 0;
if ( 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;
if ( GetAdjustedTime() < pblock->nTime )//|| pblock->GetBlockTime() > GetAdjustedTime() + 60)
{
fprintf(stderr,"need to wait %d seconds to mine:\n",(int32_t)(pblock->nTime - GetAdjustedTime()));
while ( GetAdjustedTime()+30 < pblock->nTime )
{
sleep(30);
fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime()));
}
fprintf(stderr,"finished waiting\n");
//sleep(pblock->nTime - GetAdjustedTime());
}
//printf("PoS ht.%d t%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime);
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
}
@@ -518,12 +511,25 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
}
pblock->nSolution.clear();
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 )
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
{
pblock->nTime = pindexPrev->nTime + 60;
//while ( pblock->GetBlockTime() > GetAdjustedTime() + 10 )
// sleep(1);
//fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60));
CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
if ( pblock->nTime < pindexPrev->nTime+65 )
pblock->nTime = pindexPrev->nTime + 65;
if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 )
{
CAmount txfees = 0;
pblock->vtx.push_back(txNotary);
pblocktemplate->vTxFees.push_back(txfees);
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary));
nFees += txfees;
//fprintf(stderr,"added notaryvin\n");
}
else
{
fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n");
return(0);
}
}
else
{
@@ -778,7 +784,7 @@ void static BitcoinMiner_noeq()
do {
curTip = chainActive.Tip();
printf("Verifying block height %d \n", chainActive.Tip()->nHeight);
MilliSleep(100 + rand() % 1900);
MilliSleep(1000 + rand() % 1900);
} while (curTip != chainActive.Tip());
SetThreadPriority(THREAD_PRIORITY_LOWEST);
@@ -1243,19 +1249,26 @@ void static BitcoinMiner()
for (z=31; z>=16; z--)
fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]);
fprintf(stderr," POW\n");*/
if ( NOTARY_PUBKEY33[0] != 0 && B.nTime > GetAdjustedTime() )
{
fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime()));
while ( GetAdjustedTime() < B.nTime-2 )
{
sleep(1);
if ( chainActive.Tip()->nHeight >= Mining_height )
{
fprintf(stderr,"new block arrived\n");
return(false);
}
}
}
if ( ASSETCHAINS_STAKED == 0 )
{
if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay )
if ( NOTARY_PUBKEY33[0] != 0 )
{
//printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL)));
//int32_t nseconds = Mining_start+roundrobin_delay-time(NULL);
//if ( nseconds > 0 )
// sleep(nseconds);
MilliSleep((rand() % 1700) + 1);
}
else if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
sleep(rand() % 30);
int32_t r;
if ( (r= ((Mining_height + NOTARY_PUBKEY33[16]) % 64) / 8) > 0 )
MilliSleep((rand() % (r * 1000)) + 1000);
}
}
else

View File

@@ -268,7 +268,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
fprintf(stderr," hash vs ");
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
fprintf(stderr," ht.%d special.%d notaryid.%d mod.%d error\n",height,special,notaryid,(height % 35));
fprintf(stderr," ht.%d special.%d special2.%d flag.%d notaryid.%d mod.%d error\n",height,special,special2,flag,notaryid,(height % 35));
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pubkey33[i]);
fprintf(stderr," <- pubkey\n");

View File

@@ -138,6 +138,14 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
else {
in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
in.push_back(Pair("vout", (int64_t)txin.prevout.n));
{
uint256 hash; CTransaction tx; CTxDestination address;
if (GetTransaction(txin.prevout.hash,tx,hash,false))
{
if (ExtractDestination(tx.vout[txin.prevout.n].scriptPubKey, address))
in.push_back(Pair("address", CBitcoinAddress(address).ToString()));
}
}
UniValue o(UniValue::VOBJ);
o.push_back(Pair("asm", txin.scriptSig.ToString()));
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));

View File

@@ -75,8 +75,25 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
ret.clear();
vector<valtype> vSolutions;
if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
return false;
{
// if this is a CLTV script, solve for the destination after CLTV
if (scriptPubKey.IsCheckLockTimeVerify())
{
uint8_t pushOp = scriptPubKey.data()[0];
uint32_t scriptStart = pushOp + 3;
// check post CLTV script
CScript postfix = CScript(scriptPubKey.size() > scriptStart ? scriptPubKey.begin() + scriptStart : scriptPubKey.end(), scriptPubKey.end());
// check again with only postfix subscript
if (!Solver(postfix, whichTypeRet, vSolutions))
return false;
}
else
return false;
}
CKeyID keyID;
switch (whichTypeRet)

View File

@@ -407,6 +407,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
}
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag);
extern char ASSETCHAINS_SYMBOL[];
void CTxMemPool::removeExpired(unsigned int nBlockHeight)
{
@@ -418,7 +419,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight)
{
const CTransaction& tx = it->GetTx();
tipindex = chainActive.Tip();
if (IsExpiredTx(tx, nBlockHeight) || (tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,0)) < 0)
if (IsExpiredTx(tx, nBlockHeight) || (ASSETCHAINS_SYMBOL[0] == 0 && tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,0)) < 0)
{
transactionsToRemove.push_back(tx);
}

View File

@@ -211,6 +211,7 @@ bool AsyncRPCOperation_shieldcoinbase::main_impl() {
CMutableTransaction rawTx(tx_);
for (ShieldCoinbaseUTXO & t : inputs_) {
CTxIn in(COutPoint(t.txid, t.vout));
in.nSequence = 0;
rawTx.vin.push_back(in);
}
tx_ = CTransaction(rawTx);

View File

@@ -3971,6 +3971,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
continue;
}
// If taddr is not wildcard "*", filter utxos
if (setAddress.size()>0 && !setAddress.count(address)) {
continue;
@@ -4035,6 +4036,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
int nextBlockHeight = chainActive.Height() + 1;
CMutableTransaction contextualTx = CreateNewContextualCMutableTransaction(
Params().GetConsensus(), nextBlockHeight);
contextualTx.nLockTime = nextBlockHeight;
if (contextualTx.nVersion == 1) {
contextualTx.nVersion = 2; // Tx format should support vjoinsplits
}
@@ -4465,6 +4467,82 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
extern std::string NOTARY_PUBKEY;
uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr);
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33)
{
set<CBitcoinAddress> setAddress; uint8_t *script,utxosig[128]; uint256 utxotxid; uint64_t utxovalue; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector<COutput> vecOutputs; uint32_t utxovout,eligible,earliest = 0; CScript best_scriptPubKey; bool fNegative,fOverflow;
bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr;
auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus());
const CKeyStore& keystore = *pwalletMain;
assert(pwalletMain != NULL);
LOCK2(cs_main, pwalletMain->cs_wallet);
utxovalue = 0;
memset(&utxotxid,0,sizeof(utxotxid));
memset(&utxovout,0,sizeof(utxovout));
memset(utxosig,0,sizeof(utxosig));
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
BOOST_FOREACH(const COutput& out, vecOutputs)
{
if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth )
continue;
if ( setAddress.size() )
{
CTxDestination address;
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
continue;
if (!setAddress.count(address))
continue;
}
CAmount nValue = out.tx->vout[out.i].nValue;
if ( nValue != 10000 )
continue;
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
CTxDestination address;
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
{
//entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
//if (pwalletMain->mapAddressBook.count(address))
// entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
}
script = (uint8_t *)out.tx->vout[out.i].scriptPubKey.data();
if ( out.tx->vout[out.i].scriptPubKey.size() != 35 || script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(notarypub33,script+1,33) != 0 )
{
fprintf(stderr,"scriptsize.%d [0] %02x\n",(int32_t)out.tx->vout[out.i].scriptPubKey.size(),script[0]);
continue;
}
utxovalue = (uint64_t)nValue;
//decode_hex((uint8_t *)&utxotxid,32,(char *)out.tx->GetHash().GetHex().c_str());
utxotxid = out.tx->GetHash();
utxovout = out.i;
best_scriptPubKey = out.tx->vout[out.i].scriptPubKey;
//fprintf(stderr,"check %s/v%d %llu\n",(char *)utxotxid.GetHex().c_str(),utxovout,(long long)utxovalue);
txNew.vin.resize(1);
txNew.vout.resize(1);
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;
txNew.vin[0].prevout.n = utxovout;
txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
txNew.vout[0].nValue = utxovalue - txfee;
CTransaction txNewConst(txNew);
signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId);
if (!signSuccess)
fprintf(stderr,"notaryvin failed to create signature\n");
else
{
UpdateTransaction(txNew,0,sigdata);
ptr = (uint8_t *)sigdata.scriptSig.data();
siglen = sigdata.scriptSig.size();
for (i=0; i<siglen; i++)
utxosig[i] = ptr[i];//, fprintf(stderr,"%02x",ptr[i]);
//fprintf(stderr," siglen.%d notaryvin %s/v%d\n",siglen,utxotxid.GetHex().c_str(),utxovout);
break;
}
}
return(siglen);
}
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;
@@ -4498,23 +4576,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
//if (pwalletMain->mapAddressBook.count(address))
// entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
}
/*entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
if (pk.IsPayToScriptHash())
{
CTxDestination address;
if (ExtractDestination(pk, address)) {
const CScriptID& hash = boost::get<CScriptID>(address);
CScript redeemScript;
if (pwalletMain->GetCScript(hash, redeemScript))
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
}
}
entry.push_back(Pair("amount",ValueFromAmount(nValue)));*/
//BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *tipindex;
if ( (tipindex= chainActive.Tip()) != 0 )
{
eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str());
eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str());
if ( eligible > 0 )
{
if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) )
@@ -4561,7 +4627,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
for (i=0; i<siglen; i++)
utxosig[i] = ptr[i];//, fprintf(stderr,"%02x",ptr[i]);
//fprintf(stderr," siglen.%d\n",siglen);
fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep));
//fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep));
*blocktimep = earliest;
}
}

View File

@@ -3916,9 +3916,10 @@ int CMerkleTx::GetBlocksToMaturity() const
if (!IsCoinBase())
return 0;
int32_t depth = GetDepthInMainChain();
int32_t ui;
int32_t toMaturity = (ui = UnlockTime(0) - chainActive.Height()) < 0 ? 0 : ui;
return((ui = COINBASE_MATURITY - depth) < toMaturity ? toMaturity : ui);
int32_t ut = UnlockTime(0);
int32_t toMaturity = ut - chainActive.Height() < 0 ? 0 : ut - chainActive.Height();
ut = COINBASE_MATURITY - depth < 0 ? 0 : COINBASE_MATURITY - depth;
return(ut < toMaturity ? toMaturity : ut);
}
bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectAbsurdFee)