2022-08-09 21:21:17 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-08-31 18:54:10 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-08-09 21:21:17 +00:00
|
|
|
|
|
|
|
use crate::ethereum::utils::{parse_caip2_chain_id, ChainIdError};
|
2022-08-10 11:14:17 +00:00
|
|
|
use crate::utils::caip2::ChainId;
|
2022-08-09 21:21:17 +00:00
|
|
|
|
|
|
|
fn default_chain_sync_step() -> u64 { 1000 }
|
|
|
|
|
|
|
|
fn default_chain_reorg_max_depth() -> u64 { 10 }
|
|
|
|
|
2022-08-31 18:54:10 +00:00
|
|
|
#[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>,
|
|
|
|
}
|
|
|
|
|
2022-08-09 21:21:17 +00:00
|
|
|
#[derive(Clone, Deserialize)]
|
2022-08-10 11:57:18 +00:00
|
|
|
pub struct EthereumConfig {
|
2022-08-10 11:14:17 +00:00
|
|
|
// CAIP-2 chain ID
|
|
|
|
pub chain_id: ChainId,
|
2022-08-09 21:21:17 +00:00
|
|
|
// Additional information for clients
|
2022-08-31 18:54:10 +00:00
|
|
|
// https://github.com/ethereum-lists/chains
|
|
|
|
pub chain_metadata: Option<EthereumChainMetadata>,
|
|
|
|
|
2022-08-09 21:21:17 +00:00
|
|
|
pub contract_address: String,
|
|
|
|
pub contract_dir: PathBuf,
|
|
|
|
pub api_url: String,
|
|
|
|
// Instance private key
|
|
|
|
pub signing_key: String,
|
|
|
|
|
|
|
|
#[serde(default = "default_chain_sync_step")]
|
|
|
|
pub chain_sync_step: u64,
|
|
|
|
#[serde(default = "default_chain_reorg_max_depth")]
|
|
|
|
pub chain_reorg_max_depth: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-10 11:57:18 +00:00
|
|
|
impl EthereumConfig {
|
2022-08-09 21:21:17 +00:00
|
|
|
pub fn try_ethereum_chain_id(&self) -> Result<u32, ChainIdError> {
|
|
|
|
parse_caip2_chain_id(&self.chain_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ethereum_chain_id(&self) -> u32 {
|
|
|
|
self.try_ethereum_chain_id().unwrap()
|
|
|
|
}
|
|
|
|
}
|
2022-08-10 11:57:18 +00:00
|
|
|
|
2022-08-15 23:56:06 +00:00
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
pub struct MoneroConfig {
|
|
|
|
pub chain_id: ChainId,
|
2022-09-24 20:26:34 +00:00
|
|
|
#[serde(alias = "daemon_url")]
|
|
|
|
pub node_url: String,
|
2022-08-15 23:56:06 +00:00
|
|
|
pub wallet_url: String,
|
2022-11-27 13:04:42 +00:00
|
|
|
// Wallet name and password are required when
|
|
|
|
// monero-wallet-rpc is running with --wallet-dir option
|
|
|
|
pub wallet_name: Option<String>,
|
2022-08-15 23:56:06 +00:00
|
|
|
pub wallet_password: Option<String>,
|
|
|
|
}
|
|
|
|
|
2022-08-10 11:57:18 +00:00
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum BlockchainConfig {
|
|
|
|
Ethereum(EthereumConfig),
|
2022-08-15 23:56:06 +00:00
|
|
|
Monero(MoneroConfig),
|
2022-08-10 11:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BlockchainConfig {
|
|
|
|
pub fn ethereum_config(&self) -> Option<&EthereumConfig> {
|
2022-08-15 23:56:06 +00:00
|
|
|
if let Self::Ethereum(ethereum_config) = self {
|
|
|
|
Some(ethereum_config)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn monero_config(&self) -> Option<&MoneroConfig> {
|
|
|
|
if let Self::Monero(monero_config) = self {
|
|
|
|
Some(monero_config)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2022-08-10 11:57:18 +00:00
|
|
|
}
|
|
|
|
}
|