diff --git a/src/ethereum/gate.rs b/src/ethereum/gate.rs index e71911b..59a898d 100644 --- a/src/ethereum/gate.rs +++ b/src/ethereum/gate.rs @@ -10,11 +10,11 @@ pub async fn is_allowed_user( config: &Config, user_address: &str, ) -> Result { + let contract_dir = config.ethereum_contract_dir.as_ref() + .ok_or(EthereumError::ImproperlyConfigured)?; let json_rpc_url = config.ethereum_json_rpc_url.as_ref() .ok_or(EthereumError::ImproperlyConfigured)?; let web3 = connect(json_rpc_url)?; - let contract_dir = config.ethereum_contract_dir.as_ref() - .ok_or(EthereumError::ImproperlyConfigured)?; let ethereum_config = config.ethereum_contract.as_ref() .ok_or(EthereumError::ImproperlyConfigured)?; diff --git a/src/ethereum/nft.rs b/src/ethereum/nft.rs index 9ec1b81..41ae62f 100644 --- a/src/ethereum/nft.rs +++ b/src/ethereum/nft.rs @@ -30,11 +30,11 @@ const TOKEN_WAIT_TIME: i64 = 10; // in minutes pub async fn get_nft_contract( config: &Config, ) -> Result<(Web3, Contract), EthereumError> { + let contract_dir = config.ethereum_contract_dir.as_ref() + .ok_or(EthereumError::ImproperlyConfigured)?; let json_rpc_url = config.ethereum_json_rpc_url.as_ref() .ok_or(EthereumError::ImproperlyConfigured)?; let web3 = connect(json_rpc_url)?; - let contract_dir = config.ethereum_contract_dir.as_ref() - .ok_or(EthereumError::ImproperlyConfigured)?; let ethereum_config = config.ethereum_contract.as_ref() .ok_or(EthereumError::ImproperlyConfigured)?; diff --git a/src/scheduler.rs b/src/scheduler.rs index 3235823..9402de4 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -11,15 +11,20 @@ use crate::ethereum::nft::{get_nft_contract, process_events}; pub fn run(config: Config, db_pool: Pool) -> () { actix_rt::spawn(async move { let mut interval = actix_rt::time::interval(Duration::from_secs(30)); - // Verify config and create contract interface - let web3_contract = get_nft_contract(&config).await - .map_err(|err| log::error!("{}", err)) - .ok(); + let web3_contract = if config.ethereum_contract.is_some() { + // Verify config and create contract interface + get_nft_contract(&config).await + .map_err(|err| log::error!("{}", err)) + .ok() + } else { + None + }; let mut token_waitlist_map: HashMap> = HashMap::new(); loop { interval.tick().await; - // Process events only if contract is properly configured + if let Some((web3, contract)) = web3_contract.as_ref() { + // Monitor events only if ethereum integration is enabled process_events( web3, contract, &db_pool,