Test
This commit is contained in:
@@ -568,10 +568,9 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n)
|
|||||||
#endif
|
#endif
|
||||||
hashBlock, true))
|
hashBlock, true))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s/v%d null GetTransaction locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
|
//fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
|
||||||
if ( n < tx.vout.size() )
|
if ( n < tx.vout.size() )
|
||||||
*valuep = tx.vout[n].nValue;
|
*valuep = tx.vout[n].nValue;
|
||||||
return(tx.nLockTime);
|
return(tx.nLockTime);
|
||||||
|
|||||||
@@ -670,14 +670,15 @@ uint64_t komodo_commission(const CBlock &block)
|
|||||||
return((total * ASSETCHAINS_COMMISSION) / COIN);
|
return((total * ASSETCHAINS_COMMISSION) / COIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime)
|
uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime)
|
||||||
{
|
{
|
||||||
uint32_t txtime,minutes; uint64_t value;
|
uint32_t txtime,minutes; uint64_t value,hit;
|
||||||
txtime = komodo_txtime(&value,hash,n);
|
txtime = komodo_txtime(&value,hash,n);
|
||||||
minutes = (blocktime - txtime) / 60;
|
minutes = (blocktime - txtime) / 60;
|
||||||
fprintf(stderr,"ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value));
|
hit = value / (blocktime - txtime);
|
||||||
|
fprintf(stderr,"hit.%llu ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)hit,nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value));
|
||||||
if ( nHeight < 200 )
|
if ( nHeight < 200 )
|
||||||
return(1);
|
return(blocktime);
|
||||||
else return(0);
|
else return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,13 +754,15 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
|
|||||||
{
|
{
|
||||||
if ( ASSETCHAINS_STAKED != 0 )
|
if ( ASSETCHAINS_STAKED != 0 )
|
||||||
{
|
{
|
||||||
CBlockIndex *previndex;
|
CBlockIndex *previndex; uint32_t eligible;
|
||||||
if ( prevtime == 0 )
|
if ( prevtime == 0 )
|
||||||
{
|
{
|
||||||
if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 )
|
if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 )
|
||||||
prevtime = (uint32_t)previndex->nTime;
|
prevtime = (uint32_t)previndex->nTime;
|
||||||
}
|
}
|
||||||
komodo_stake(height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime);
|
eligible = komodo_stake(height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime);
|
||||||
|
if ( eligible > block.nTime )
|
||||||
|
fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime));
|
||||||
}
|
}
|
||||||
if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 )
|
if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4439,11 +4439,11 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp)
|
|||||||
#include "script/sign.h"
|
#include "script/sign.h"
|
||||||
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
||||||
extern std::string NOTARY_PUBKEY;
|
extern std::string NOTARY_PUBKEY;
|
||||||
int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime);
|
uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime);
|
||||||
|
|
||||||
int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig)
|
int32_t komodo_staked(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;
|
set<CBitcoinAddress> setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector<COutput> vecOutputs; const COutput& best; uint32_t earliest = 0;
|
||||||
assert(pwalletMain != NULL);
|
assert(pwalletMain != NULL);
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
*utxovaluep = 0;
|
*utxovaluep = 0;
|
||||||
@@ -4466,10 +4466,6 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,
|
|||||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||||
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
||||||
//entry.push_back(Pair("generated", out.tx->IsCoinBase()));
|
//entry.push_back(Pair("generated", out.tx->IsCoinBase()));
|
||||||
*utxovaluep = (uint64_t)nValue;
|
|
||||||
decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str());
|
|
||||||
*utxovoutp = out.i;
|
|
||||||
*txtimep = (uint32_t)out.tx->nLockTime;
|
|
||||||
CTxDestination address;
|
CTxDestination address;
|
||||||
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
|
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
|
||||||
{
|
{
|
||||||
@@ -4499,35 +4495,47 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,
|
|||||||
komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
|
komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
|
||||||
interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime);
|
interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime);
|
||||||
//entry.push_back(Pair("interest",ValueFromAmount(interest)));
|
//entry.push_back(Pair("interest",ValueFromAmount(interest)));
|
||||||
komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime);
|
eligible = komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime);
|
||||||
|
if ( eligible > 0 && eligible < earliest )
|
||||||
|
{
|
||||||
|
earliest = eligible;
|
||||||
|
best = out;
|
||||||
|
*utxovaluep = (uint64_t)nValue;
|
||||||
|
decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str());
|
||||||
|
*utxovoutp = out.i;
|
||||||
|
*txtimep = (uint32_t)out.tx->nLockTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight);
|
//fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight);
|
||||||
}
|
}
|
||||||
bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid;
|
if ( earliest != 0 )
|
||||||
auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus());
|
|
||||||
const CKeyStore& keystore = *pwalletMain;
|
|
||||||
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
|
|
||||||
txNew.vin.resize(1);
|
|
||||||
txNew.vout.resize(1);
|
|
||||||
txfee = 0;
|
|
||||||
for (i=0; i<32; i++)
|
|
||||||
((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i];
|
|
||||||
txNew.vin[0].prevout.hash = revtxid;
|
|
||||||
txNew.vin[0].prevout.n = *utxovoutp;
|
|
||||||
txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
|
|
||||||
txNew.vout[0].nValue = nValue - txfee;
|
|
||||||
txNew.nLockTime = *blocktimep;
|
|
||||||
CTransaction txNewConst(txNew);
|
|
||||||
signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId);
|
|
||||||
if (!signSuccess)
|
|
||||||
fprintf(stderr,"failed to create signature\n");
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
ptr = (uint8_t *)sigdata.scriptSig.data();
|
bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid;
|
||||||
siglen = sigdata.scriptSig.size();
|
auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus());
|
||||||
for (i=0; i<siglen; i++)
|
const CKeyStore& keystore = *pwalletMain;
|
||||||
utxosig[i] = ptr[i];//, fprintf(stderr,"%02x",ptr[i]);
|
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
|
||||||
//fprintf(stderr," siglen.%d\n",siglen);
|
txNew.vin.resize(1);
|
||||||
|
txNew.vout.resize(1);
|
||||||
|
txfee = 0;
|
||||||
|
for (i=0; i<32; i++)
|
||||||
|
((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i];
|
||||||
|
txNew.vin[0].prevout.hash = revtxid;
|
||||||
|
txNew.vin[0].prevout.n = *utxovoutp;
|
||||||
|
txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
|
||||||
|
txNew.vout[0].nValue = nValue - txfee;
|
||||||
|
txNew.nLockTime = *blocktimep;
|
||||||
|
CTransaction txNewConst(txNew);
|
||||||
|
signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), best.tx->vout[best.i].scriptPubKey, sigdata, consensusBranchId);
|
||||||
|
if (!signSuccess)
|
||||||
|
fprintf(stderr,"failed to create signature\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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\n",siglen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(siglen);
|
return(siglen);
|
||||||
|
|||||||
Reference in New Issue
Block a user