Rename Blockchain type to EthereumBlockchain
This commit is contained in:
parent
cd7fa6a5d7
commit
0906fd8ae3
8 changed files with 26 additions and 22 deletions
|
@ -92,7 +92,7 @@ pub struct ContractSet {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Blockchain {
|
||||
pub struct EthereumBlockchain {
|
||||
pub config: EthereumConfig,
|
||||
pub contract_set: ContractSet,
|
||||
pub sync_state: SyncState,
|
||||
|
@ -102,7 +102,7 @@ pub async fn get_contracts(
|
|||
db_client: &impl DatabaseClient,
|
||||
config: &EthereumConfig,
|
||||
storage_dir: &Path,
|
||||
) -> Result<Blockchain, EthereumError> {
|
||||
) -> Result<EthereumBlockchain, EthereumError> {
|
||||
let web3 = connect(&config.api_url)?;
|
||||
let chain_id = web3.eth().chain_id().await?;
|
||||
if chain_id != config.ethereum_chain_id().into() {
|
||||
|
@ -198,7 +198,7 @@ pub async fn get_contracts(
|
|||
subscription: maybe_subscription,
|
||||
subscription_adapter: maybe_subscription_adapter,
|
||||
};
|
||||
Ok(Blockchain {
|
||||
Ok(EthereumBlockchain {
|
||||
config: config.clone(),
|
||||
contract_set,
|
||||
sync_state,
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::activitypub::queues::{
|
|||
process_queued_outgoing_activities,
|
||||
};
|
||||
use crate::ethereum::{
|
||||
contracts::Blockchain,
|
||||
contracts::EthereumBlockchain,
|
||||
subscriptions::{
|
||||
check_ethereum_subscriptions,
|
||||
update_expired_subscriptions,
|
||||
|
@ -35,7 +35,7 @@ use crate::ethereum::nft::process_nft_events;
|
|||
|
||||
#[cfg(feature = "ethereum-extras")]
|
||||
pub async fn nft_monitor(
|
||||
maybe_blockchain: Option<&mut Blockchain>,
|
||||
maybe_blockchain: Option<&mut EthereumBlockchain>,
|
||||
db_pool: &DbPool,
|
||||
) -> Result<(), Error> {
|
||||
let blockchain = match maybe_blockchain {
|
||||
|
@ -57,7 +57,7 @@ pub async fn nft_monitor(
|
|||
|
||||
pub async fn ethereum_subscription_monitor(
|
||||
config: &Config,
|
||||
maybe_blockchain: Option<&mut Blockchain>,
|
||||
maybe_blockchain: Option<&mut EthereumBlockchain>,
|
||||
db_pool: &DbPool,
|
||||
) -> Result<(), Error> {
|
||||
let blockchain = match maybe_blockchain {
|
||||
|
|
|
@ -6,7 +6,7 @@ use chrono::{DateTime, Utc};
|
|||
use mitra_config::Config;
|
||||
use mitra_models::database::DbPool;
|
||||
|
||||
use crate::ethereum::contracts::Blockchain;
|
||||
use crate::ethereum::contracts::EthereumBlockchain;
|
||||
use super::periodic_tasks::*;
|
||||
|
||||
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||
|
@ -55,7 +55,7 @@ impl PeriodicTask {
|
|||
|
||||
pub fn run(
|
||||
config: Config,
|
||||
mut maybe_blockchain: Option<Blockchain>,
|
||||
mut maybe_ethereum_blockchain: Option<EthereumBlockchain>,
|
||||
db_pool: DbPool,
|
||||
) -> () {
|
||||
tokio::spawn(async move {
|
||||
|
@ -89,7 +89,7 @@ pub fn run(
|
|||
PeriodicTask::EthereumSubscriptionMonitor => {
|
||||
ethereum_subscription_monitor(
|
||||
&config,
|
||||
maybe_blockchain.as_mut(),
|
||||
maybe_ethereum_blockchain.as_mut(),
|
||||
&db_pool,
|
||||
).await
|
||||
},
|
||||
|
@ -117,7 +117,7 @@ pub fn run(
|
|||
#[cfg(feature = "ethereum-extras")]
|
||||
PeriodicTask::NftMonitor => {
|
||||
nft_monitor(
|
||||
maybe_blockchain.as_mut(),
|
||||
maybe_ethereum_blockchain.as_mut(),
|
||||
&db_pool,
|
||||
).await
|
||||
},
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -61,7 +61,7 @@ async fn main() -> std::io::Result<()> {
|
|||
.expect("failed to create media directory");
|
||||
};
|
||||
|
||||
let maybe_blockchain = if let Some(blockchain_config) = config.blockchain() {
|
||||
let maybe_ethereum_blockchain = if let Some(blockchain_config) = config.blockchain() {
|
||||
if let Some(ethereum_config) = blockchain_config.ethereum_config() {
|
||||
// Create blockchain interface
|
||||
get_contracts(&**db_client, ethereum_config, &config.storage_dir).await
|
||||
|
@ -72,7 +72,7 @@ async fn main() -> std::io::Result<()> {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let maybe_contract_set = maybe_blockchain.clone()
|
||||
let maybe_ethereum_contracts = maybe_ethereum_blockchain.clone()
|
||||
.map(|blockchain| blockchain.contract_set);
|
||||
|
||||
std::mem::drop(db_client);
|
||||
|
@ -82,7 +82,11 @@ async fn main() -> std::io::Result<()> {
|
|||
config.environment,
|
||||
);
|
||||
|
||||
scheduler::run(config.clone(), maybe_blockchain, db_pool.clone());
|
||||
scheduler::run(
|
||||
config.clone(),
|
||||
maybe_ethereum_blockchain,
|
||||
db_pool.clone(),
|
||||
);
|
||||
log::info!("scheduler started");
|
||||
|
||||
let num_workers = std::cmp::max(num_cpus::get(), 4);
|
||||
|
@ -146,7 +150,7 @@ async fn main() -> std::io::Result<()> {
|
|||
)
|
||||
.app_data(web::Data::new(config.clone()))
|
||||
.app_data(web::Data::new(db_pool.clone()))
|
||||
.app_data(web::Data::new(maybe_contract_set.clone()))
|
||||
.app_data(web::Data::new(maybe_ethereum_contracts.clone()))
|
||||
.app_data(web::Data::clone(&inbox_mutex))
|
||||
.service(actix_files::Files::new(
|
||||
"/media",
|
||||
|
|
|
@ -130,7 +130,7 @@ pub async fn create_account(
|
|||
connection_info: ConnectionInfo,
|
||||
config: web::Data<Config>,
|
||||
db_pool: web::Data<DbPool>,
|
||||
maybe_blockchain: web::Data<Option<ContractSet>>,
|
||||
maybe_ethereum_contracts: web::Data<Option<ContractSet>>,
|
||||
account_data: web::Json<AccountCreateData>,
|
||||
) -> Result<HttpResponse, MastodonError> {
|
||||
let db_client = &mut **get_database_client(&db_pool).await?;
|
||||
|
@ -169,7 +169,7 @@ pub async fn create_account(
|
|||
return Err(ValidationError("invalid login data").into());
|
||||
};
|
||||
|
||||
if let Some(contract_set) = maybe_blockchain.as_ref() {
|
||||
if let Some(contract_set) = maybe_ethereum_contracts.as_ref() {
|
||||
if let Some(ref gate) = contract_set.gate {
|
||||
// Wallet address is required if token gate is present
|
||||
let wallet_address = maybe_wallet_address.as_ref()
|
||||
|
|
|
@ -86,7 +86,7 @@ fn get_full_api_version(version: &str) -> String {
|
|||
impl InstanceInfo {
|
||||
pub fn create(
|
||||
config: &Config,
|
||||
maybe_blockchain: Option<&ContractSet>,
|
||||
maybe_ethereum_contracts: Option<&ContractSet>,
|
||||
user_count: i64,
|
||||
post_count: i64,
|
||||
peer_count: i64,
|
||||
|
@ -94,7 +94,7 @@ impl InstanceInfo {
|
|||
let mut blockchains = vec![];
|
||||
match config.blockchain() {
|
||||
Some(BlockchainConfig::Ethereum(ethereum_config)) => {
|
||||
let features = if let Some(contract_set) = maybe_blockchain {
|
||||
let features = if let Some(contract_set) = maybe_ethereum_contracts {
|
||||
BlockchainFeatures {
|
||||
gate: contract_set.gate.is_some(),
|
||||
minter: contract_set.collectible.is_some(),
|
||||
|
|
|
@ -18,7 +18,7 @@ use super::types::InstanceInfo;
|
|||
async fn instance_view(
|
||||
config: web::Data<Config>,
|
||||
db_pool: web::Data<DbPool>,
|
||||
maybe_blockchain: web::Data<Option<ContractSet>>,
|
||||
maybe_ethereum_contracts: web::Data<Option<ContractSet>>,
|
||||
) -> Result<HttpResponse, MastodonError> {
|
||||
let db_client = &**get_database_client(&db_pool).await?;
|
||||
let user_count = get_user_count(db_client).await?;
|
||||
|
@ -26,7 +26,7 @@ async fn instance_view(
|
|||
let peer_count = get_peer_count(db_client).await?;
|
||||
let instance = InstanceInfo::create(
|
||||
config.as_ref(),
|
||||
maybe_blockchain.as_ref().as_ref(),
|
||||
maybe_ethereum_contracts.as_ref().as_ref(),
|
||||
user_count,
|
||||
post_count,
|
||||
peer_count,
|
||||
|
|
|
@ -104,7 +104,7 @@ pub async fn register_subscription_option(
|
|||
connection_info: ConnectionInfo,
|
||||
config: web::Data<Config>,
|
||||
db_pool: web::Data<DbPool>,
|
||||
maybe_blockchain: web::Data<Option<ContractSet>>,
|
||||
maybe_ethereum_contracts: web::Data<Option<ContractSet>>,
|
||||
subscription_option: web::Json<SubscriptionOption>,
|
||||
) -> Result<HttpResponse, MastodonError> {
|
||||
let db_client = &mut **get_database_client(&db_pool).await?;
|
||||
|
@ -118,7 +118,7 @@ pub async fn register_subscription_option(
|
|||
let ethereum_config = config.blockchain()
|
||||
.and_then(|conf| conf.ethereum_config())
|
||||
.ok_or(MastodonError::NotSupported)?;
|
||||
let contract_set = maybe_blockchain.as_ref().as_ref()
|
||||
let contract_set = maybe_ethereum_contracts.as_ref().as_ref()
|
||||
.ok_or(MastodonError::NotSupported)?;
|
||||
let wallet_address = current_user
|
||||
.public_wallet_address(&Currency::Ethereum)
|
||||
|
|
Loading…
Reference in a new issue