Change representation of blockchain config in Instance API response
Allowed multiple blockchain configs.
This commit is contained in:
parent
b357b9bfa0
commit
26ae1036de
3 changed files with 86 additions and 58 deletions
|
@ -918,36 +918,36 @@ components:
|
|||
description: Post character limit.
|
||||
type: integer
|
||||
example: 5000
|
||||
blockchain_id:
|
||||
description: CAIP-2 chain ID.
|
||||
type: string
|
||||
nullable: true
|
||||
example: 'eip155:1'
|
||||
blockchain_explorer_url:
|
||||
description: Blockchain explorer base URL.
|
||||
type: string
|
||||
nullable: true
|
||||
blockchain_contract_address:
|
||||
description: Blockchain contract address.
|
||||
type: string
|
||||
nullable: true
|
||||
blockchain_features:
|
||||
description: Blockchain contract features.
|
||||
type: object
|
||||
nullable: true
|
||||
properties:
|
||||
minter:
|
||||
description: Minter feature flag.
|
||||
type: boolean
|
||||
example: true
|
||||
subscription:
|
||||
description: Subscription feature flag.
|
||||
type: boolean
|
||||
example: true
|
||||
blockchain_info:
|
||||
description: Additional information about blockchain
|
||||
type: object
|
||||
nullable: true
|
||||
blockchains:
|
||||
description: Information about blockchain integrations.
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
chain_id:
|
||||
description: CAIP-2 chain ID.
|
||||
type: string
|
||||
example: 'eip155:1'
|
||||
chain_metadata:
|
||||
description: Additional information about blockchain
|
||||
type: object
|
||||
nullable: true
|
||||
contract_address:
|
||||
description: Blockchain contract address.
|
||||
type: string
|
||||
nullable: true
|
||||
features:
|
||||
description: Blockchain features.
|
||||
type: object
|
||||
properties:
|
||||
minter:
|
||||
description: Minter feature flag.
|
||||
type: boolean
|
||||
example: true
|
||||
subscriptions:
|
||||
description: Subscriptions feature flag.
|
||||
type: boolean
|
||||
example: true
|
||||
ipfs_gateway_url:
|
||||
description: IPFS gateway URL.
|
||||
type: string
|
||||
|
|
|
@ -2,6 +2,10 @@ mod blockchain;
|
|||
mod environment;
|
||||
mod main;
|
||||
|
||||
pub use blockchain::{EthereumConfig, MoneroConfig};
|
||||
pub use blockchain::{
|
||||
BlockchainConfig,
|
||||
EthereumConfig,
|
||||
MoneroConfig,
|
||||
};
|
||||
pub use environment::Environment;
|
||||
pub use main::{parse_config, Config, Instance};
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
use serde::Serialize;
|
||||
use serde_json::{to_value, Value};
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::config::{BlockchainConfig, Config};
|
||||
use crate::ethereum::contracts::ContractSet;
|
||||
use crate::mastodon_api::MASTODON_API_VERSION;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct BlockchainFeatures {
|
||||
minter: bool,
|
||||
subscription: bool,
|
||||
subscriptions: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct BlockchainInfo {
|
||||
chain_id: String,
|
||||
chain_metadata: Option<Value>,
|
||||
contract_address: Option<String>,
|
||||
features: BlockchainFeatures,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -22,11 +30,7 @@ pub struct InstanceInfo {
|
|||
|
||||
login_message: String,
|
||||
post_character_limit: usize,
|
||||
blockchain_id: Option<String>,
|
||||
blockchain_explorer_url: Option<String>,
|
||||
blockchain_contract_address: Option<String>,
|
||||
blockchain_features: Option<BlockchainFeatures>,
|
||||
blockchain_info: Option<Value>,
|
||||
blockchains: Vec<BlockchainInfo>,
|
||||
ipfs_gateway_url: Option<String>,
|
||||
}
|
||||
|
||||
|
@ -40,17 +44,45 @@ 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()
|
||||
.and_then(|conf| conf.ethereum_config());
|
||||
let blockchain_features = maybe_blockchain.map(|contract_set| {
|
||||
BlockchainFeatures {
|
||||
minter: contract_set.collectible.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());
|
||||
let mut blockchains = vec![];
|
||||
match config.blockchain() {
|
||||
Some(BlockchainConfig::Ethereum(ethereum_config)) => {
|
||||
let features = if let Some(contract_set) = maybe_blockchain {
|
||||
BlockchainFeatures {
|
||||
minter: contract_set.collectible.is_some(),
|
||||
subscriptions: contract_set.subscription.is_some(),
|
||||
}
|
||||
} else {
|
||||
BlockchainFeatures {
|
||||
minter: false,
|
||||
subscriptions: false,
|
||||
}
|
||||
};
|
||||
let maybe_chain_metadata = ethereum_config
|
||||
.chain_metadata.as_ref()
|
||||
.and_then(|metadata| to_value(metadata).ok());
|
||||
blockchains.push(BlockchainInfo {
|
||||
chain_id: ethereum_config.chain_id.to_string(),
|
||||
chain_metadata: maybe_chain_metadata,
|
||||
contract_address:
|
||||
Some(ethereum_config.contract_address.clone()),
|
||||
features: features,
|
||||
});
|
||||
},
|
||||
Some(BlockchainConfig::Monero(monero_config)) => {
|
||||
let features = BlockchainFeatures {
|
||||
minter: false,
|
||||
subscriptions: true,
|
||||
};
|
||||
blockchains.push(BlockchainInfo {
|
||||
chain_id: monero_config.chain_id.to_string(),
|
||||
chain_metadata: None,
|
||||
contract_address: None,
|
||||
features: features,
|
||||
})
|
||||
},
|
||||
None => (),
|
||||
};
|
||||
Self {
|
||||
uri: config.instance().host(),
|
||||
title: config.instance_title.clone(),
|
||||
|
@ -60,15 +92,7 @@ impl InstanceInfo {
|
|||
registrations: config.registrations_open,
|
||||
login_message: config.login_message.clone(),
|
||||
post_character_limit: config.post_character_limit,
|
||||
blockchain_id: ethereum_config
|
||||
.map(|val| val.chain_id.to_string()),
|
||||
blockchain_explorer_url: ethereum_config
|
||||
.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: maybe_blockchain_info,
|
||||
blockchains: blockchains,
|
||||
ipfs_gateway_url: config.ipfs_gateway_url.clone(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue