Rename chain_info config parameter to chain_metadata and define its type

This commit is contained in:
silverpill 2022-08-31 18:54:10 +00:00
parent 64fb51e92a
commit b357b9bfa0
4 changed files with 38 additions and 15 deletions

View file

@ -13,11 +13,16 @@ registrations_open: true
blockchains: blockchains:
# Parameters for hardhat local node # Parameters for hardhat local node
- chain_id: eip155:31337 - 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_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
contract_dir: contracts contract_dir: contracts
api_url: 'http://127.0.0.1:8546' api_url: 'http://127.0.0.1:8546'
explorer_url: null
signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
chain_sync_step: 100 chain_sync_step: 100
chain_reorg_max_depth: 0 chain_reorg_max_depth: 0

View file

@ -27,14 +27,20 @@ registrations_open: false
#blocked_instances: [] #blocked_instances: []
# Blockchain integrations # 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` # Signing key for ethereum integration can be generated with `mitractl generate-ethereum-address`
#blockchains: #blockchains:
# - chain_id: eip155:31337 # - 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_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
# contract_dir: /usr/share/mitra/contracts # contract_dir: /usr/share/mitra/contracts
# api_url: 'http://127.0.0.1:8545' # api_url: 'http://127.0.0.1:8545'
# explorer_url: null
# signing_key: null # signing_key: null
# chain_sync_step: 1000 # chain_sync_step: 1000
# chain_reorg_max_depth: 10 # chain_reorg_max_depth: 10

View file

@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
use serde::Deserialize; use serde::{Deserialize, Serialize};
use crate::ethereum::utils::{parse_caip2_chain_id, ChainIdError}; use crate::ethereum::utils::{parse_caip2_chain_id, ChainIdError};
use crate::utils::caip2::ChainId; use crate::utils::caip2::ChainId;
@ -10,17 +9,28 @@ fn default_chain_sync_step() -> u64 { 1000 }
fn default_chain_reorg_max_depth() -> u64 { 10 } 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<String>,
}
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize)]
pub struct EthereumConfig { pub struct EthereumConfig {
// CAIP-2 chain ID // CAIP-2 chain ID
pub chain_id: ChainId, pub chain_id: ChainId,
// Additional information for clients // Additional information for clients
pub chain_info: Option<HashMap<String, String>>, // https://github.com/ethereum-lists/chains
pub chain_metadata: Option<EthereumChainMetadata>,
pub contract_address: String, pub contract_address: String,
pub contract_dir: PathBuf, pub contract_dir: PathBuf,
pub api_url: String, pub api_url: String,
// Block explorer base URL (should be compatible with https://eips.ethereum.org/EIPS/eip-3091)
pub explorer_url: Option<String>,
// Instance private key // Instance private key
pub signing_key: String, pub signing_key: String,

View file

@ -1,6 +1,5 @@
use std::collections::HashMap;
use serde::Serialize; use serde::Serialize;
use serde_json::{to_value, Value};
use crate::config::Config; use crate::config::Config;
use crate::ethereum::contracts::ContractSet; use crate::ethereum::contracts::ContractSet;
@ -27,7 +26,7 @@ pub struct InstanceInfo {
blockchain_explorer_url: Option<String>, blockchain_explorer_url: Option<String>,
blockchain_contract_address: Option<String>, blockchain_contract_address: Option<String>,
blockchain_features: Option<BlockchainFeatures>, blockchain_features: Option<BlockchainFeatures>,
blockchain_info: Option<HashMap<String, String>>, blockchain_info: Option<Value>,
ipfs_gateway_url: Option<String>, ipfs_gateway_url: Option<String>,
} }
@ -49,6 +48,9 @@ impl InstanceInfo {
subscription: contract_set.subscription.is_some(), 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 { Self {
uri: config.instance().host(), uri: config.instance().host(),
title: config.instance_title.clone(), title: config.instance_title.clone(),
@ -61,12 +63,12 @@ impl InstanceInfo {
blockchain_id: ethereum_config blockchain_id: ethereum_config
.map(|val| val.chain_id.to_string()), .map(|val| val.chain_id.to_string()),
blockchain_explorer_url: ethereum_config 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 blockchain_contract_address: ethereum_config
.map(|val| val.contract_address.clone()), .map(|val| val.contract_address.clone()),
blockchain_features: blockchain_features, blockchain_features: blockchain_features,
blockchain_info: ethereum_config blockchain_info: maybe_blockchain_info,
.and_then(|val| val.chain_info.clone()),
ipfs_gateway_url: config.ipfs_gateway_url.clone(), ipfs_gateway_url: config.ipfs_gateway_url.clone(),
} }
} }