Allow blockchain configuration to be defined using a list
Multi-chain configurations are still not allowed.
This commit is contained in:
parent
cc6d9d7688
commit
260e62d51b
9 changed files with 56 additions and 39 deletions
|
@ -10,24 +10,23 @@ instance_short_description: My instance
|
|||
instance_description: My instance
|
||||
registrations_open: true
|
||||
|
||||
blockchain:
|
||||
blockchains:
|
||||
# Parameters for hardhat local node
|
||||
chain_id: eip155:31337
|
||||
chain_info: 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
|
||||
|
||||
#blockchain:
|
||||
# chain_id: monero:regtest
|
||||
# daemon_url: 'http://127.0.0.1:58081'
|
||||
# wallet_url: 'http://127.0.0.1:58083'
|
||||
# wallet_name: test
|
||||
# wallet_password: test
|
||||
- chain_id: eip155:31337
|
||||
chain_info: 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
|
||||
# # Parameters for local Monero node
|
||||
# - chain_id: monero:regtest
|
||||
# daemon_url: 'http://127.0.0.1:58081'
|
||||
# wallet_url: 'http://127.0.0.1:58083'
|
||||
# wallet_name: test
|
||||
# wallet_password: test
|
||||
|
||||
ipfs_api_url: 'http://127.0.0.1:5001'
|
||||
ipfs_gateway_url: 'http://127.0.0.1:8001'
|
||||
|
|
|
@ -26,18 +26,18 @@ registrations_open: false
|
|||
# List of blocked domains
|
||||
#blocked_instances: []
|
||||
|
||||
# Blockchain integration
|
||||
# Blockchain integrations
|
||||
# Signing key for ethereum integration can be generated with `mitractl generate-ethereum-address`
|
||||
#blockchain:
|
||||
# chain_id: eip155:31337
|
||||
# chain_info: 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
|
||||
#blockchains:
|
||||
# - chain_id: eip155:31337
|
||||
# chain_info: 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
|
||||
|
||||
# IPFS integration
|
||||
#ipfs_api_url: 'http://127.0.0.1:5001'
|
||||
|
|
|
@ -301,7 +301,7 @@ impl CreateMoneroWallet {
|
|||
&self,
|
||||
config: &Config,
|
||||
) -> Result<(), Error> {
|
||||
let monero_config = config.blockchain.as_ref()
|
||||
let monero_config = config.blockchain()
|
||||
.and_then(|conf| conf.monero_config())
|
||||
.ok_or(anyhow!("monero configuration not found"))?;
|
||||
create_monero_wallet(monero_config).await?;
|
||||
|
|
|
@ -100,8 +100,11 @@ pub struct Config {
|
|||
#[serde(default)]
|
||||
pub blocked_instances: Vec<String>,
|
||||
|
||||
// Blockchain integration
|
||||
pub blockchain: Option<BlockchainConfig>,
|
||||
// Blockchain integrations
|
||||
#[serde(rename = "blockchain")]
|
||||
pub _blockchain: Option<BlockchainConfig>, // deprecated
|
||||
#[serde(default)]
|
||||
blockchains: Vec<BlockchainConfig>,
|
||||
|
||||
// IPFS
|
||||
pub ipfs_api_url: Option<String>,
|
||||
|
@ -137,6 +140,18 @@ impl Config {
|
|||
pub fn media_dir(&self) -> PathBuf {
|
||||
self.storage_dir.join("media")
|
||||
}
|
||||
|
||||
pub fn blockchain(&self) -> Option<&BlockchainConfig> {
|
||||
if let Some(ref blockchain_config) = self._blockchain {
|
||||
Some(blockchain_config)
|
||||
} else {
|
||||
match &self.blockchains[..] {
|
||||
[blockchain_config] => Some(blockchain_config),
|
||||
[] => None,
|
||||
_ => panic!("multichain deployments are not supported"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -237,7 +252,7 @@ pub fn parse_config() -> Config {
|
|||
};
|
||||
check_directory_owner(&config.storage_dir);
|
||||
config.try_instance_url().expect("invalid instance URI");
|
||||
if let Some(blockchain_config) = config.blockchain.as_ref() {
|
||||
if let Some(blockchain_config) = config.blockchain() {
|
||||
if let Some(ethereum_config) = blockchain_config.ethereum_config() {
|
||||
ethereum_config.try_ethereum_chain_id().unwrap();
|
||||
if !ethereum_config.contract_dir.exists() {
|
||||
|
|
|
@ -51,7 +51,10 @@ async fn main() -> std::io::Result<()> {
|
|||
config.environment,
|
||||
);
|
||||
|
||||
let maybe_blockchain = if let Some(blockchain_config) = &config.blockchain {
|
||||
if config._blockchain.is_some() {
|
||||
log::warn!("'blockchain' property is deprecated, use 'blockchains' instead");
|
||||
};
|
||||
let maybe_blockchain = if let Some(blockchain_config) = config.blockchain() {
|
||||
if let Some(ethereum_config) = blockchain_config.ethereum_config() {
|
||||
// Create blockchain interface
|
||||
get_contracts(ethereum_config, &config.storage_dir).await
|
||||
|
@ -147,7 +150,7 @@ async fn main() -> std::io::Result<()> {
|
|||
.service(atom::get_atom_feed)
|
||||
.service(nodeinfo::get_nodeinfo)
|
||||
.service(nodeinfo::get_nodeinfo_2_0);
|
||||
if let Some(blockchain_config) = &config.blockchain {
|
||||
if let Some(blockchain_config) = config.blockchain() {
|
||||
if let Some(ethereum_config) = blockchain_config.ethereum_config() {
|
||||
// Serve artifacts if available
|
||||
app = app.service(actix_files::Files::new(
|
||||
|
|
|
@ -134,7 +134,7 @@ pub async fn create_account(
|
|||
return Err(ValidationError("not allowed to sign up").into());
|
||||
};
|
||||
} else {
|
||||
assert!(config.blockchain.is_none());
|
||||
assert!(config.blockchain().is_none());
|
||||
};
|
||||
|
||||
// Generate RSA private key for actor
|
||||
|
|
|
@ -41,7 +41,7 @@ fn get_full_api_version(version: &str) -> String {
|
|||
|
||||
impl InstanceInfo {
|
||||
pub fn create(config: &Config, maybe_blockchain: Option<&ContractSet>) -> Self {
|
||||
let ethereum_config = config.blockchain.as_ref()
|
||||
let ethereum_config = config.blockchain()
|
||||
.and_then(|conf| conf.ethereum_config());
|
||||
let blockchain_features = maybe_blockchain.map(|contract_set| {
|
||||
BlockchainFeatures {
|
||||
|
|
|
@ -426,7 +426,7 @@ async fn get_signature(
|
|||
) -> Result<HttpResponse, HttpError> {
|
||||
let db_client = &**get_database_client(&db_pool).await?;
|
||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||
let ethereum_config = config.blockchain.as_ref()
|
||||
let ethereum_config = config.blockchain()
|
||||
.ok_or(HttpError::NotSupported)?
|
||||
.ethereum_config()
|
||||
.ok_or(HttpError::NotSupported)?;
|
||||
|
|
|
@ -32,7 +32,7 @@ pub async fn authorize_subscription(
|
|||
) -> Result<HttpResponse, HttpError> {
|
||||
let db_client = &**get_database_client(&db_pool).await?;
|
||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||
let ethereum_config = config.blockchain.as_ref()
|
||||
let ethereum_config = config.blockchain()
|
||||
.ok_or(HttpError::NotSupported)?
|
||||
.ethereum_config()
|
||||
.ok_or(HttpError::NotSupported)?;
|
||||
|
@ -63,7 +63,7 @@ pub async fn subscriptions_enabled(
|
|||
let mut maybe_payment_option = None;
|
||||
match subscription_settings.into_inner() {
|
||||
SubscriptionSettings::Ethereum => {
|
||||
let ethereum_config = config.blockchain.as_ref()
|
||||
let ethereum_config = config.blockchain()
|
||||
.and_then(|conf| conf.ethereum_config())
|
||||
.ok_or(HttpError::NotSupported)?;
|
||||
let contract_set = maybe_blockchain.as_ref().as_ref()
|
||||
|
|
Loading…
Reference in a new issue