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,9 +10,9 @@ instance_short_description: My instance
|
||||||
instance_description: My instance
|
instance_description: My instance
|
||||||
registrations_open: true
|
registrations_open: true
|
||||||
|
|
||||||
blockchain:
|
blockchains:
|
||||||
# Parameters for hardhat local node
|
# Parameters for hardhat local node
|
||||||
chain_id: eip155:31337
|
- chain_id: eip155:31337
|
||||||
chain_info: null
|
chain_info: null
|
||||||
contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
|
contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
|
||||||
contract_dir: contracts
|
contract_dir: contracts
|
||||||
|
@ -21,9 +21,8 @@ blockchain:
|
||||||
signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
|
signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
|
||||||
chain_sync_step: 100
|
chain_sync_step: 100
|
||||||
chain_reorg_max_depth: 0
|
chain_reorg_max_depth: 0
|
||||||
|
# # Parameters for local Monero node
|
||||||
#blockchain:
|
# - chain_id: monero:regtest
|
||||||
# chain_id: monero:regtest
|
|
||||||
# daemon_url: 'http://127.0.0.1:58081'
|
# daemon_url: 'http://127.0.0.1:58081'
|
||||||
# wallet_url: 'http://127.0.0.1:58083'
|
# wallet_url: 'http://127.0.0.1:58083'
|
||||||
# wallet_name: test
|
# wallet_name: test
|
||||||
|
|
|
@ -26,10 +26,10 @@ registrations_open: false
|
||||||
# List of blocked domains
|
# List of blocked domains
|
||||||
#blocked_instances: []
|
#blocked_instances: []
|
||||||
|
|
||||||
# Blockchain integration
|
# Blockchain integrations
|
||||||
# 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`
|
||||||
#blockchain:
|
#blockchains:
|
||||||
# chain_id: eip155:31337
|
# - chain_id: eip155:31337
|
||||||
# chain_info: null
|
# chain_info: null
|
||||||
# contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
|
# contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
|
||||||
# contract_dir: /usr/share/mitra/contracts
|
# contract_dir: /usr/share/mitra/contracts
|
||||||
|
|
|
@ -301,7 +301,7 @@ impl CreateMoneroWallet {
|
||||||
&self,
|
&self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let monero_config = config.blockchain.as_ref()
|
let monero_config = config.blockchain()
|
||||||
.and_then(|conf| conf.monero_config())
|
.and_then(|conf| conf.monero_config())
|
||||||
.ok_or(anyhow!("monero configuration not found"))?;
|
.ok_or(anyhow!("monero configuration not found"))?;
|
||||||
create_monero_wallet(monero_config).await?;
|
create_monero_wallet(monero_config).await?;
|
||||||
|
|
|
@ -100,8 +100,11 @@ pub struct Config {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub blocked_instances: Vec<String>,
|
pub blocked_instances: Vec<String>,
|
||||||
|
|
||||||
// Blockchain integration
|
// Blockchain integrations
|
||||||
pub blockchain: Option<BlockchainConfig>,
|
#[serde(rename = "blockchain")]
|
||||||
|
pub _blockchain: Option<BlockchainConfig>, // deprecated
|
||||||
|
#[serde(default)]
|
||||||
|
blockchains: Vec<BlockchainConfig>,
|
||||||
|
|
||||||
// IPFS
|
// IPFS
|
||||||
pub ipfs_api_url: Option<String>,
|
pub ipfs_api_url: Option<String>,
|
||||||
|
@ -137,6 +140,18 @@ impl Config {
|
||||||
pub fn media_dir(&self) -> PathBuf {
|
pub fn media_dir(&self) -> PathBuf {
|
||||||
self.storage_dir.join("media")
|
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)]
|
#[derive(Clone)]
|
||||||
|
@ -237,7 +252,7 @@ pub fn parse_config() -> Config {
|
||||||
};
|
};
|
||||||
check_directory_owner(&config.storage_dir);
|
check_directory_owner(&config.storage_dir);
|
||||||
config.try_instance_url().expect("invalid instance URI");
|
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() {
|
if let Some(ethereum_config) = blockchain_config.ethereum_config() {
|
||||||
ethereum_config.try_ethereum_chain_id().unwrap();
|
ethereum_config.try_ethereum_chain_id().unwrap();
|
||||||
if !ethereum_config.contract_dir.exists() {
|
if !ethereum_config.contract_dir.exists() {
|
||||||
|
|
|
@ -51,7 +51,10 @@ async fn main() -> std::io::Result<()> {
|
||||||
config.environment,
|
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() {
|
if let Some(ethereum_config) = blockchain_config.ethereum_config() {
|
||||||
// Create blockchain interface
|
// Create blockchain interface
|
||||||
get_contracts(ethereum_config, &config.storage_dir).await
|
get_contracts(ethereum_config, &config.storage_dir).await
|
||||||
|
@ -147,7 +150,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.service(atom::get_atom_feed)
|
.service(atom::get_atom_feed)
|
||||||
.service(nodeinfo::get_nodeinfo)
|
.service(nodeinfo::get_nodeinfo)
|
||||||
.service(nodeinfo::get_nodeinfo_2_0);
|
.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() {
|
if let Some(ethereum_config) = blockchain_config.ethereum_config() {
|
||||||
// Serve artifacts if available
|
// Serve artifacts if available
|
||||||
app = app.service(actix_files::Files::new(
|
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());
|
return Err(ValidationError("not allowed to sign up").into());
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
assert!(config.blockchain.is_none());
|
assert!(config.blockchain().is_none());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate RSA private key for actor
|
// Generate RSA private key for actor
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn get_full_api_version(version: &str) -> String {
|
||||||
|
|
||||||
impl InstanceInfo {
|
impl InstanceInfo {
|
||||||
pub fn create(config: &Config, maybe_blockchain: Option<&ContractSet>) -> Self {
|
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());
|
.and_then(|conf| conf.ethereum_config());
|
||||||
let blockchain_features = maybe_blockchain.map(|contract_set| {
|
let blockchain_features = maybe_blockchain.map(|contract_set| {
|
||||||
BlockchainFeatures {
|
BlockchainFeatures {
|
||||||
|
|
|
@ -426,7 +426,7 @@ async fn get_signature(
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
let db_client = &**get_database_client(&db_pool).await?;
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
let current_user = get_current_user(db_client, auth.token()).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)?
|
.ok_or(HttpError::NotSupported)?
|
||||||
.ethereum_config()
|
.ethereum_config()
|
||||||
.ok_or(HttpError::NotSupported)?;
|
.ok_or(HttpError::NotSupported)?;
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub async fn authorize_subscription(
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
let db_client = &**get_database_client(&db_pool).await?;
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
let current_user = get_current_user(db_client, auth.token()).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)?
|
.ok_or(HttpError::NotSupported)?
|
||||||
.ethereum_config()
|
.ethereum_config()
|
||||||
.ok_or(HttpError::NotSupported)?;
|
.ok_or(HttpError::NotSupported)?;
|
||||||
|
@ -63,7 +63,7 @@ pub async fn subscriptions_enabled(
|
||||||
let mut maybe_payment_option = None;
|
let mut maybe_payment_option = None;
|
||||||
match subscription_settings.into_inner() {
|
match subscription_settings.into_inner() {
|
||||||
SubscriptionSettings::Ethereum => {
|
SubscriptionSettings::Ethereum => {
|
||||||
let ethereum_config = config.blockchain.as_ref()
|
let ethereum_config = config.blockchain()
|
||||||
.and_then(|conf| conf.ethereum_config())
|
.and_then(|conf| conf.ethereum_config())
|
||||||
.ok_or(HttpError::NotSupported)?;
|
.ok_or(HttpError::NotSupported)?;
|
||||||
let contract_set = maybe_blockchain.as_ref().as_ref()
|
let contract_set = maybe_blockchain.as_ref().as_ref()
|
||||||
|
|
Loading…
Reference in a new issue