diff --git a/src/init.cpp b/src/init.cpp index 56944cc7d0..cf8b935294 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2209,9 +2209,8 @@ bool AppInitMain(InitInterfaces& interfaces) // Import privkey const auto key = DecodeSecret("L5DhrVPhA2FbJ1ezpN3JijHVnnH1sVcbdcAcp3nE373ooGH6LEz6"); - const auto pubkey = key.GetPubKey(); - const auto dest = WitnessV0KeyHash(PKHash{pubkey}); - const auto keyID = pubkey.GetID(); + const auto keyID = key.GetPubKey().GetID(); + const auto dest = WitnessV0KeyHash(PKHash{keyID}); const auto time{std::time(nullptr)}; auto pwallet = GetWallets()[0]; diff --git a/src/validation.cpp b/src/validation.cpp index e2d8c77b58..dd785e6492 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2835,38 +2835,45 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl mnview.SetLastHeight(pindex->nHeight); if (pindex->nHeight >= chainparams.GetConsensus().NextNetworkUpgradeHeight) { -// CKeyID minter; -// block.ExtractMinterKey(minter); -// const auto id = mnview.GetMasternodeIdByOperator(minter); -// assert(id); -// const auto node = mnview.GetMasternode(*id); -// assert(node); -// -// auto height = node->creationHeight; -// uint256 mnID = *id; -// if (!node->collateralTx.IsNull()) { -// const auto idHeight = mnview.GetNewCollateral(node->collateralTx); -// assert(idHeight); -// height = idHeight->blockHeight - GetMnResignDelay(std::numeric_limits::max()); -// mnID = node->collateralTx; -// } - -// const auto blockindex = ::ChainActive()[height]; -// assert(blockindex); -// CTransactionRef tx; -// uint256 hash_block; -// assert(GetTransaction(mnID, tx, Params().GetConsensus(), hash_block, blockindex)); -// assert(tx->vout.size() >= 2); - -// CTxDestination dest; -// assert(ExtractDestination(tx->vout[1].scriptPubKey, dest)); -// assert(dest.index() == PKHashType || dest.index() == WitV0KeyHashType); - -// const auto keyID = dest.index() == PKHashType ? CKeyID(std::get(dest)) : CKeyID(std::get(dest)); -// std::array minerAddress{}; -// std::copy(keyID.begin(), keyID.end(), minerAddress.begin()); - std::array x {}; - evm_finalise(evmContext, true, x); + CKeyID minter; + assert(block.ExtractMinterKey(minter)); + std::array minerAddress{}; + + if (!fMockNetwork) { + const auto id = mnview.GetMasternodeIdByOperator(minter); + assert(id); + const auto node = mnview.GetMasternode(*id); + assert(node); + + auto height = node->creationHeight; + auto mnID = *id; + if (!node->collateralTx.IsNull()) { + const auto idHeight = mnview.GetNewCollateral(node->collateralTx); + assert(idHeight); + height = idHeight->blockHeight - GetMnResignDelay(std::numeric_limits::max()); + mnID = node->collateralTx; + } + + const auto blockindex = ::ChainActive()[height]; + assert(blockindex); + + + CTransactionRef tx; + uint256 hash_block; + assert(GetTransaction(mnID, tx, Params().GetConsensus(), hash_block, blockindex)); + assert(tx->vout.size() >= 2); + + CTxDestination dest; + assert(ExtractDestination(tx->vout[1].scriptPubKey, dest)); + assert(dest.index() == PKHashType || dest.index() == WitV0KeyHashType); + + const auto keyID = dest.index() == PKHashType ? CKeyID(std::get(dest)) : CKeyID(std::get(dest)); + std::copy(keyID.begin(), keyID.end(), minerAddress.begin()); + } else { + std::copy(minter.begin(), minter.end(), minerAddress.begin()); + } + + evm_finalise(evmContext, true, minerAddress); } auto &checkpoints = chainparams.Checkpoints().mapCheckpoints;