Skip to content

Commit

Permalink
Ocean: Genesis block indexed + missing mn info update (#2791)
Browse files Browse the repository at this point in the history
* add mn info

* index genesis
  • Loading branch information
canonbrother committed Feb 7, 2024
1 parent 9f8770d commit 0fe7ce7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2809,8 +2809,23 @@ Res ProcessDeFiEventFallible(const CBlock &block,
info.size_stripped = GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
info.weight = GetBlockWeight(block);
info.stake_modifier = pindex->stakeModifier.ToString();
info.minter = "", // mn operator address
info.masternode = "", // mn owner address
info.minter = ""; // mn operator address
info.masternode = ""; // mn owner address

// minter info
CKeyID minter;
block.ExtractMinterKey(minter);

auto id = mnview.GetMasternodeIdByOperator(minter);
if (id) {
info.masternode = id->ToString();
auto mn = mnview.GetMasternode(*id);
if (mn) {
auto dest = mn->operatorType == 1 ? CTxDestination(PKHash(minter)) : CTxDestination(WitnessV0KeyHash(minter));
info.minter = EncodeDestination(dest);
}
}

ocean_index_block(result, serializedData, info);
// if (!result.ok) {
// return Res::Err(result.reason.c_str());
Expand Down
45 changes: 45 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2561,5 +2561,50 @@ bool AppInitMain(InitInterfaces& interfaces)
});
}

// ********************************************************* Step 16: start genesis ocean indexing
if(gArgs.GetBoolArg("-oceanarchive", DEFAULT_OCEAN_ARCHIVE_ENABLED)) {
const CBlock &block = chainparams.GenesisBlock();

CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << block;
CBlockIndex* pindex = ::ChainActive().Tip();

// Convert the serialized data to a string
std::string serializedData = HexStr(ss.begin(), ss.end());

CrossBoundaryResult result;
BlockV2Info info;
info.height = pindex->nHeight;
info.difficulty = pindex->nBits;
info.version = pindex->nVersion;
info.median_time = (int64_t)pindex->GetMedianTimePast();
info.minter_block_count = pindex->mintedBlocks;
info.size = GetSerializeSize(block, PROTOCOL_VERSION);
info.size_stripped = GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
info.weight = GetBlockWeight(block);
info.stake_modifier = pindex->stakeModifier.ToString();
info.minter = ""; // mn operator address
info.masternode = ""; // mn owner address

// minter info
CKeyID minter;
block.ExtractMinterKey(minter);

auto id = pcustomcsview->GetMasternodeIdByOperator(minter);
if (id) {
info.masternode = id->ToString();
auto mn = pcustomcsview->GetMasternode(*id);
if (mn) {
auto dest = mn->operatorType == 1 ? CTxDestination(PKHash(minter)) : CTxDestination(WitnessV0KeyHash(minter));
info.minter = EncodeDestination(dest);
}
}

ocean_index_block(result, serializedData, info);
// if (!result.ok) {
// return Res::Err(result.reason.c_str());
// }
}

return true;
}

0 comments on commit 0fe7ce7

Please sign in to comment.