Allow multiple configurations in blockchains array

This commit is contained in:
silverpill 2023-04-09 00:23:12 +00:00
parent d2d340158e
commit faca485ebf
4 changed files with 21 additions and 3 deletions

View file

@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added emoji count check to profile data validator.
- Check mention and link counts when creating post.
- Disable transaction monitor tasks if blockchain integration is disabled.
- Allow multiple configurations in `blockchains` array.
## [1.20.0] - 2023-03-07

View file

@ -57,7 +57,7 @@ retention:
#blocked_instances: []
# Blockchain integrations
# Multiple configuration are currently not allowed.
# Multi-chain setups are currently not supported.
# Chain metadata for EVM chains can be found at https://github.com/ethereum-lists/chains
# Signing key for ethereum integration can be generated with `mitractl generate-ethereum-address`
#blockchains:

View file

@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::path::PathBuf;
use log::{Level as LogLevel};
@ -125,8 +126,21 @@ impl Config {
if let Some(ref _blockchain_config) = self._blockchain {
panic!("'blockchain' setting is not supported anymore, use 'blockchains' instead");
} else {
if self.blockchains.len() > 1 {
panic!("multichain deployments are not supported");
let is_error = self.blockchains.iter()
.fold(HashMap::new(), |mut map, blockchain_config| {
let key = match blockchain_config {
BlockchainConfig::Ethereum(_) => 1,
BlockchainConfig::Monero(_) => 2,
};
map.entry(key)
.and_modify(|count| *count += 1)
.or_insert(1);
map
})
.into_values()
.any(|count| count > 1);
if is_error {
panic!("'blockchains' array contains more than one chain of the same kind");
};
&self.blockchains
}

View file

@ -102,6 +102,9 @@ pub fn parse_config() -> (Config, Vec<&'static str>) {
};
check_directory_owner(&config.storage_dir);
config.try_instance_url().expect("invalid instance URI");
if config.blockchains().len() > 1 {
warnings.push("multichain deployments are not recommended");
};
if let Some(ethereum_config) = config.ethereum_config() {
ethereum_config.try_ethereum_chain_id().unwrap();
if !ethereum_config.contract_dir.exists() {