Don't write error message to log if ethereum integration is disabled

This commit is contained in:
silverpill 2021-11-06 12:48:52 +00:00
parent 979588b5b8
commit 9a0a11e33f
3 changed files with 14 additions and 9 deletions

View file

@ -10,11 +10,11 @@ pub async fn is_allowed_user(
config: &Config, config: &Config,
user_address: &str, user_address: &str,
) -> Result<bool, EthereumError> { ) -> Result<bool, 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() let json_rpc_url = config.ethereum_json_rpc_url.as_ref()
.ok_or(EthereumError::ImproperlyConfigured)?; .ok_or(EthereumError::ImproperlyConfigured)?;
let web3 = connect(json_rpc_url)?; 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() let ethereum_config = config.ethereum_contract.as_ref()
.ok_or(EthereumError::ImproperlyConfigured)?; .ok_or(EthereumError::ImproperlyConfigured)?;

View file

@ -30,11 +30,11 @@ const TOKEN_WAIT_TIME: i64 = 10; // in minutes
pub async fn get_nft_contract( pub async fn get_nft_contract(
config: &Config, config: &Config,
) -> Result<(Web3<Http>, Contract<Http>), EthereumError> { ) -> Result<(Web3<Http>, Contract<Http>), 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() let json_rpc_url = config.ethereum_json_rpc_url.as_ref()
.ok_or(EthereumError::ImproperlyConfigured)?; .ok_or(EthereumError::ImproperlyConfigured)?;
let web3 = connect(json_rpc_url)?; 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() let ethereum_config = config.ethereum_contract.as_ref()
.ok_or(EthereumError::ImproperlyConfigured)?; .ok_or(EthereumError::ImproperlyConfigured)?;

View file

@ -11,15 +11,20 @@ use crate::ethereum::nft::{get_nft_contract, process_events};
pub fn run(config: Config, db_pool: Pool) -> () { pub fn run(config: Config, db_pool: Pool) -> () {
actix_rt::spawn(async move { actix_rt::spawn(async move {
let mut interval = actix_rt::time::interval(Duration::from_secs(30)); let mut interval = actix_rt::time::interval(Duration::from_secs(30));
let web3_contract = if config.ethereum_contract.is_some() {
// Verify config and create contract interface // Verify config and create contract interface
let web3_contract = get_nft_contract(&config).await get_nft_contract(&config).await
.map_err(|err| log::error!("{}", err)) .map_err(|err| log::error!("{}", err))
.ok(); .ok()
} else {
None
};
let mut token_waitlist_map: HashMap<Uuid, DateTime<Utc>> = HashMap::new(); let mut token_waitlist_map: HashMap<Uuid, DateTime<Utc>> = HashMap::new();
loop { loop {
interval.tick().await; interval.tick().await;
// Process events only if contract is properly configured
if let Some((web3, contract)) = web3_contract.as_ref() { if let Some((web3, contract)) = web3_contract.as_ref() {
// Monitor events only if ethereum integration is enabled
process_events( process_events(
web3, contract, web3, contract,
&db_pool, &db_pool,