Beginning of N@S solution using CoinbaseGuard CC

This commit is contained in:
miketout
2018-10-02 19:49:54 -07:00
parent c68ca1a225
commit 8a727a26a7
49 changed files with 832 additions and 62 deletions

View File

@@ -1254,10 +1254,9 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe
std::vector<std::vector<unsigned char>> vSolutions;
CBlockIndex *tipindex;
{
LOCK(cs_main);
tipindex = chainActive.Tip();
}
tipindex = chainActive.LastTip();
bool extendedStake = tipindex->GetHeight() >= Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight;
bnTarget = lwmaGetNextPOSRequired(tipindex, Params().GetConsensus());
if (!VerusSelectStakeOutput(pBlock, hashResult, stakeSource, voutNum, tipindex->GetHeight() + 1, bnTarget) ||
@@ -1275,21 +1274,56 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe
const CKeyStore& keystore = *pwalletMain;
txNew.vin.resize(1);
txNew.vout.resize(1);
txfee = 0;
txfee = extendedStake ? 10000 : 0; // extended stakes will always be rebroadcast, so they require a fee to make it fast
txNew.vin[0].prevout.hash = stakeSource.GetHash();
txNew.vin[0].prevout.n = voutNum;
CPubKey pk = CPubKey();
if (whichType == TX_PUBKEY)
{
txNew.vout[0].scriptPubKey << ToByteVector(vSolutions[0]) << OP_CHECKSIG;
pk = CPubKey(vSolutions[0]);
}
else if (whichType == TX_PUBKEYHASH)
{
txNew.vout[0].scriptPubKey << OP_DUP << OP_HASH160 << ToByteVector(vSolutions[0]) << OP_EQUALVERIFY << OP_CHECKSIG;
if (extendedStake)
{
// we need a pubkey, so try to get one from the key ID, if not there, fail
if (!keystore.GetPubKey(CKeyID(uint160(vSolutions[0])), pk))
return 0;
}
}
else
return 0;
// if we are staking with the extended format, add the opreturn data required
//if (extendedStake)
{
uint256 srcBlock = uint256();
CBlockIndex *pSrcIndex;
txNew.vout.push_back(CTxOut());
CTxOut &txOut1 = txNew.vout[1];
txOut1.nValue = 0;
if (!GetTransaction(stakeSource.GetHash(), stakeSource, srcBlock))
return 0;
if ((pSrcIndex = mapBlockIndex[srcBlock]) == 0)
return 0;
txOut1.scriptPubKey << OP_RETURN
<< (int8_t)OPRETTYPE_STAKEPARAMS
<< pSrcIndex->GetHeight() << tipindex->GetHeight()
<< std::vector<unsigned char>(pBlock->hashPrevBlock.begin(), pBlock->hashPrevBlock.end())
<< std::vector<unsigned char>(pk.begin(), pk.end());
// need to decide how to decide, but then we can add a delegated source here for the coinbase output
//if (USE_EXTERNAL_PUBKEY)
// txOut1.scriptPubKey << ParseHex(NOTARY_PUBKEY);
}
nValue = txNew.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee;
txNew.nLockTime = 0;
CTransaction txNewConst(txNew);