Skip to content

Commit

Permalink
For mocknet use operator key as miner address
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Apr 18, 2023
1 parent 2a86059 commit 6fee45a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
5 changes: 2 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
71 changes: 39 additions & 32 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::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<PKHash>(dest)) : CKeyID(std::get<WitnessV0KeyHash>(dest));
// std::array<uint8_t, 20> minerAddress{};
// std::copy(keyID.begin(), keyID.end(), minerAddress.begin());
std::array<uint8_t, 20> x {};
evm_finalise(evmContext, true, x);
CKeyID minter;
assert(block.ExtractMinterKey(minter));
std::array<uint8_t, 20> 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<int>::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<PKHash>(dest)) : CKeyID(std::get<WitnessV0KeyHash>(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;
Expand Down

0 comments on commit 6fee45a

Please sign in to comment.