That makes sense, but I don’t quite see the case for changing GetNetworkForMagic
to accept a span in the future, so it feels a bit like premature optimization to me, but I may be missing context.
It’s a nit, and the commit is orthogonal to the PR anyway, so this is the last I’ll comment on it - up to you what you prefer, but I feel like this would probably be the most elegant implementation:
0std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& message)
1{
2 static const std::array<std::pair<MessageStartChars, ChainType>, 5> network_map = {{
3 {CChainParams::Main()->MessageStart(), ChainType::MAIN},
4 {CChainParams::TestNet()->MessageStart(), ChainType::TESTNET},
5 {CChainParams::TestNet4()->MessageStart(), ChainType::TESTNET4},
6 {CChainParams::RegTest({})->MessageStart(), ChainType::REGTEST},
7 {CChainParams::SigNet({})->MessageStart(), ChainType::SIGNET}
8 }};
9
10 auto it = std::ranges::find_if(network_map, [&message](const auto& pair) { return pair.first == message; });
11 return (it != network_map.end()) ? std::make_optional(it->second) : std::nullopt;
12}