Initialize contract set in main()
This commit is contained in:
parent
f700d79754
commit
30f7f5d996
3 changed files with 20 additions and 13 deletions
|
@ -73,11 +73,11 @@ pub async fn get_contracts(
|
|||
"collectible",
|
||||
(), None, Options::default(), None,
|
||||
).await?;
|
||||
let collectibe_abi = load_abi(&config.contract_dir, ERC721)?;
|
||||
let collectible_abi = load_abi(&config.contract_dir, ERC721)?;
|
||||
let collectible = Contract::from_json(
|
||||
web3.eth(),
|
||||
collectible_address,
|
||||
&collectibe_abi,
|
||||
&collectible_abi,
|
||||
)?;
|
||||
log::info!("collectible item contract address is {:?}", collectible.address());
|
||||
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -12,6 +12,7 @@ use mitra::atom::views as atom;
|
|||
use mitra::config::{Environment, parse_config};
|
||||
use mitra::database::{get_database_client, create_pool};
|
||||
use mitra::database::migrate::apply_migrations;
|
||||
use mitra::ethereum::contracts::get_contracts;
|
||||
use mitra::logger::configure_logger;
|
||||
use mitra::mastodon_api::accounts::views::account_api_scope;
|
||||
use mitra::mastodon_api::directory::views::directory_api_scope;
|
||||
|
@ -35,6 +36,7 @@ async fn main() -> std::io::Result<()> {
|
|||
let config = parse_config();
|
||||
configure_logger(config.log_level);
|
||||
log::info!("config loaded from {}", config.config_path);
|
||||
|
||||
let db_pool = create_pool(&config.database_url);
|
||||
let mut db_client = get_database_client(&db_pool).await.unwrap();
|
||||
apply_migrations(&mut **db_client).await;
|
||||
|
@ -49,7 +51,16 @@ async fn main() -> std::io::Result<()> {
|
|||
config.environment,
|
||||
);
|
||||
|
||||
scheduler::run(config.clone(), db_pool.clone());
|
||||
let maybe_contract_set = if let Some(blockchain_config) = &config.blockchain {
|
||||
// Create blockchain interface
|
||||
get_contracts(blockchain_config).await
|
||||
.map_err(|err| log::error!("{}", err))
|
||||
.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
scheduler::run(config.clone(), maybe_contract_set, db_pool.clone());
|
||||
log::info!("scheduler started");
|
||||
|
||||
let http_socket_addr = format!(
|
||||
|
|
|
@ -6,21 +6,17 @@ use uuid::Uuid;
|
|||
|
||||
use crate::config::Config;
|
||||
use crate::database::Pool;
|
||||
use crate::ethereum::contracts::get_contracts;
|
||||
use crate::ethereum::contracts::ContractSet;
|
||||
use crate::ethereum::nft::process_nft_events;
|
||||
use crate::ethereum::subscriptions::check_subscriptions;
|
||||
|
||||
pub fn run(config: Config, db_pool: Pool) -> () {
|
||||
pub fn run(
|
||||
_config: Config,
|
||||
maybe_contract_set: Option<ContractSet>,
|
||||
db_pool: Pool,
|
||||
) -> () {
|
||||
tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(30));
|
||||
let maybe_contract_set = if let Some(blockchain_config) = &config.blockchain {
|
||||
// Create blockchain interface
|
||||
get_contracts(blockchain_config).await
|
||||
.map_err(|err| log::error!("{}", err))
|
||||
.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut token_waitlist_map: HashMap<Uuid, DateTime<Utc>> = HashMap::new();
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
|
Loading…
Reference in a new issue