diff --git a/config.yaml.example b/config.yaml.example index f05b3f4..08fa3e6 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -13,11 +13,16 @@ registrations_open: true blockchains: # Parameters for hardhat local node - chain_id: eip155:31337 - chain_info: null + chain_metadata: + chain_name: localhost + currency_name: ETH + currency_symbol: ETH + currency_decimals: 18 + public_api_url: 'http://127.0.0.1:8546' + explorer_url: null contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' contract_dir: contracts api_url: 'http://127.0.0.1:8546' - explorer_url: null signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' chain_sync_step: 100 chain_reorg_max_depth: 0 diff --git a/contrib/mitra_config.yaml b/contrib/mitra_config.yaml index 9f3c314..0d0c4bb 100644 --- a/contrib/mitra_config.yaml +++ b/contrib/mitra_config.yaml @@ -27,14 +27,20 @@ registrations_open: false #blocked_instances: [] # Blockchain integrations +# 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: # - chain_id: eip155:31337 -# chain_info: null +# chain_metadata: +# chain_name: localhost +# currency_name: ETH +# currency_symbol: ETH +# currency_decimals: 18 +# public_api_url: 'http://127.0.0.1:8545' +# explorer_url: null # contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' # contract_dir: /usr/share/mitra/contracts # api_url: 'http://127.0.0.1:8545' -# explorer_url: null # signing_key: null # chain_sync_step: 1000 # chain_reorg_max_depth: 10 diff --git a/src/config/blockchain.rs b/src/config/blockchain.rs index 4796ad1..fb88a97 100644 --- a/src/config/blockchain.rs +++ b/src/config/blockchain.rs @@ -1,7 +1,6 @@ -use std::collections::HashMap; use std::path::PathBuf; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use crate::ethereum::utils::{parse_caip2_chain_id, ChainIdError}; use crate::utils::caip2::ChainId; @@ -10,17 +9,28 @@ fn default_chain_sync_step() -> u64 { 1000 } fn default_chain_reorg_max_depth() -> u64 { 10 } +#[derive(Clone, Deserialize, Serialize)] +pub struct EthereumChainMetadata { + pub chain_name: String, + pub currency_name: String, + pub currency_symbol: String, + pub currency_decimals: u8, + pub public_api_url: String, + // Block explorer base URL (should be compatible with https://eips.ethereum.org/EIPS/eip-3091) + pub explorer_url: Option, +} + #[derive(Clone, Deserialize)] pub struct EthereumConfig { // CAIP-2 chain ID pub chain_id: ChainId, // Additional information for clients - pub chain_info: Option>, + // https://github.com/ethereum-lists/chains + pub chain_metadata: Option, + pub contract_address: String, pub contract_dir: PathBuf, pub api_url: String, - // Block explorer base URL (should be compatible with https://eips.ethereum.org/EIPS/eip-3091) - pub explorer_url: Option, // Instance private key pub signing_key: String, diff --git a/src/mastodon_api/instance/types.rs b/src/mastodon_api/instance/types.rs index 2121ee8..d4813e8 100644 --- a/src/mastodon_api/instance/types.rs +++ b/src/mastodon_api/instance/types.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; - use serde::Serialize; +use serde_json::{to_value, Value}; use crate::config::Config; use crate::ethereum::contracts::ContractSet; @@ -27,7 +26,7 @@ pub struct InstanceInfo { blockchain_explorer_url: Option, blockchain_contract_address: Option, blockchain_features: Option, - blockchain_info: Option>, + blockchain_info: Option, ipfs_gateway_url: Option, } @@ -49,6 +48,9 @@ impl InstanceInfo { subscription: contract_set.subscription.is_some(), } }); + let maybe_blockchain_info = ethereum_config + .and_then(|conf| conf.chain_metadata.as_ref()) + .and_then(|metadata| to_value(metadata).ok()); Self { uri: config.instance().host(), title: config.instance_title.clone(), @@ -61,12 +63,12 @@ impl InstanceInfo { blockchain_id: ethereum_config .map(|val| val.chain_id.to_string()), blockchain_explorer_url: ethereum_config - .and_then(|val| val.explorer_url.clone()), + .and_then(|conf| conf.chain_metadata.as_ref()) + .and_then(|metadata| metadata.explorer_url.clone()), blockchain_contract_address: ethereum_config .map(|val| val.contract_address.clone()), blockchain_features: blockchain_features, - blockchain_info: ethereum_config - .and_then(|val| val.chain_info.clone()), + blockchain_info: maybe_blockchain_info, ipfs_gateway_url: config.ipfs_gateway_url.clone(), } }