Skip to content

Commit

Permalink
Update/clean up (#49)
Browse files Browse the repository at this point in the history
* edit names

* clean up & restructure

* move hbs types

* import download_file from hpos_hc_connect

* inline doc touch-ups

* clean up comments

* Update src/types/hbs.rs

Co-authored-by: Joel Ulahanna <joelulahanna@gmail.com>

* import core app types from hpos_hc_connect

* remove option from kyc

* edit comments

---------

Co-authored-by: Joel Ulahanna <joelulahanna@gmail.com>
  • Loading branch information
JettTech and zo-el authored Jul 10, 2024
1 parent a8c63c8 commit 713a176
Show file tree
Hide file tree
Showing 11 changed files with 663 additions and 751 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ holo auto installer does 2 main things.
- Install a happs that are supposed to be installed on the holoport but are not installed
`install_holo_hosted_happs`
- Uninstall happs that are not supposed to be installed on the holoport but are installed
`uninstall_ineligible_happs`
`handle_ineligible_happs`

Generally if you want to restrict something so it is not installed on the holoport you can use the function inside
`uninstall_apps.rs` called `should_be_installed` If this returns a `false` the happ will be uninstalled form the holoport.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ mr_bundle = { version = "0.4.0-dev.4" }
hpos-config-core = { git = "https://github.com/Holo-Host/hpos-config", rev = "a36f862869cc162c843ac27ed617910d68f480cc" }
hpos-config-seed-bundle-explorer ={ git = "https://github.com/Holo-Host/hpos-config", rev = "a36f862869cc162c843ac27ed617910d68f480cc" }
chrono = "0.4.33"
hpos_hc_connect = { git = "https://github.com/holo-host/hpos-service-crates.git", rev = "63044a665eafc9f8f6ff130801ad45303e1288f4" }
hpos_hc_connect = { git = "https://github.com/holo-host/hpos-service-crates.git", rev = "1a333b0688dbc7a2dbbe64eb25a2d98f8200b14d" }
80 changes: 0 additions & 80 deletions src/entries.rs

This file was deleted.

113 changes: 70 additions & 43 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,81 +1,108 @@
// TODO: https://github.com/tokio-rs/tracing/issues/843
#![allow(clippy::unit_arg)]
pub mod entries;
use std::collections::HashMap;
pub mod types;
mod utils;

pub use crate::types::happ::HappPreferences;
pub use hpos_hc_connect::AdminWebsocket;

use anyhow::Result;
use holochain_types::dna::{hash_type::Agent, HoloHash};
use hpos_hc_connect::hha_agent::HHAAgent;
pub use hpos_hc_connect::AdminWebsocket;
pub mod transaction_types;
mod utils;
use hpos_hc_connect::{hha_agent::HHAAgent, holo_config::Config};
use std::collections::HashMap;
use tracing::{debug, error, info};
use types::hbs::{HbsClient, KycLevel};
use types::PublishedHappDetails;
use utils::{
get_all_published_hosted_happs, get_happ_preferences, get_hosting_preferences,
get_pending_transactions, get_publisher_jurisdiction, install_holo_hosted_happs,
suspend_unpaid_happs, uninstall_ineligible_happs,
get_all_published_hosted_happs, handle_ineligible_happs, install_holo_hosted_happs,
suspend_unpaid_happs,
};
mod hbs;
use hbs::{HbsClient, KycLevel};
use hpos_hc_connect::holo_config::Config;

/// gets all the enabled happs from HHA
/// installs and enables new happs that were registered by a provider and holochain disables those paused by provider in hha
/// then uninstalls happs that are ineligible for host (eg: holo-disabled, unallowed pricing for kyc level)
/// 1. Gets all the holo-enabled happs from HHA
/// 2. Suspends happs with overdue payments
/// 3. Installs and enables (enables in holochain and holo) all new happs that were registered by a provider and holochain-disables those paused by provider in hha
/// 4. Uninstalls happs that are ineligible for host (eg: holo-disabled, unallowed pricing for kyc level, incongruent price settings with publisher/happ)
pub async fn run(config: &Config) -> Result<()> {
info!("Activating holo hosted apps");
let hbs_connect = HbsClient::connect()?;
let hosting_criteria = match hbs_connect.get_hosting_criteria().await {
let host_credentials = match hbs_connect.get_host_hosting_criteria().await {
Some(v) => v,
None => {
error!("Unable to get hosting criteria from HBS. Exiting...");
return Err(anyhow::anyhow!("Unable to get hosting criteria"));
}
};
let kyc_level = hosting_criteria.kyc;
debug!("Got kyc level {:?}", &kyc_level);
let jurisdiction = hosting_criteria.jurisdiction;
debug!("Got jurisdiction from hbs {:?}", jurisdiction);

let is_kyc_level_2 = kyc_level == KycLevel::Level2;
debug!("Got host credentials from hbs {:?}", host_credentials);

let mut core_app = HHAAgent::spawn(Some(config)).await?;

// suspend happs that have overdue payments
let pending_transactions = get_pending_transactions(&mut core_app).await?;
// Suspend happs that have overdue payments
let pending_transactions = core_app.get_pending_transactions().await?;
let suspended_happs = suspend_unpaid_happs(&mut core_app, pending_transactions).await?;
let hosting_preference = get_hosting_preferences(&mut core_app).await?;

let list_of_happs = get_all_published_hosted_happs(&mut core_app).await?;
let published_happs = get_all_published_hosted_happs(&mut core_app).await?;

// Get happ jurisdictions AND publisher jurisdiction for each happ
let mut published_happ_details: HashMap<String, PublishedHappDetails> = HashMap::new();
let mut publisher_jurisdictions: HashMap<HoloHash<Agent>, Option<String>> = HashMap::new();
let mut happ_jurisdictions: HashMap<String, Option<String>> = HashMap::new();
// get publisher jurisdiction for each happ
for happ in list_of_happs.iter() {
let happ_prefs = get_happ_preferences(&mut core_app, happ.happ_id.clone()).await?;

for happ in published_happs.iter() {
let happ_prefs = core_app.get_happ_preferences(happ.happ_id.clone()).await?;
let publisher_pubkey = happ_prefs.provider_pubkey;

// If already have publisher pubkey stored in `publisher_jurisdictions` map, then grab the jurisdiction value and set value in `published_happ_details` map
// otherwise, make a call to hha to fetch the publisher jurisdiction and set in both the `published_happ_details` map and `publisher_jurisdictions` map
match publisher_jurisdictions.get(&publisher_pubkey) {
Some(jurisdiction) => {
happ_jurisdictions
.insert(happ.happ_id.clone().to_string(), (*jurisdiction).clone());
published_happ_details.insert(
happ.happ_id.clone().to_string(),
PublishedHappDetails {
publisher_jurisdiction: (*jurisdiction).clone(),
happ_jurisdictions: happ.jurisdictions.clone(),
should_exclude_happ_jurisdictions: happ.exclude_jurisdictions,
happ_categories: happ.categories.clone(),
is_disabled_by_host: happ.is_host_disabled,
},
);
}
None => {
let jurisdiction =
get_publisher_jurisdiction(&mut core_app, publisher_pubkey.clone()).await?;
let jurisdiction = core_app
.get_publisher_jurisdiction(publisher_pubkey.clone())
.await?;
publisher_jurisdictions.insert(publisher_pubkey, jurisdiction.clone());
happ_jurisdictions.insert(happ.happ_id.clone().to_string(), jurisdiction);
published_happ_details.insert(
happ.happ_id.clone().to_string(),
PublishedHappDetails {
publisher_jurisdiction: jurisdiction,
happ_jurisdictions: happ.jurisdictions.clone(),
should_exclude_happ_jurisdictions: happ.exclude_jurisdictions,
happ_categories: happ.categories.clone(),
is_disabled_by_host: happ.is_host_disabled,
},
);
}
}
}

install_holo_hosted_happs(config, &list_of_happs, is_kyc_level_2).await?;
uninstall_ineligible_happs(
config,
&list_of_happs,
is_kyc_level_2,
let host_happ_preferences = core_app.get_host_preferences().await?.into();

let is_host_kyc_level_2 = host_credentials.clone().kyc == KycLevel::Level2;

install_holo_hosted_happs(
&mut core_app,
config.admin_port,
&published_happs,
is_host_kyc_level_2,
)
.await?;

handle_ineligible_happs(
&mut core_app,
config.admin_port,
suspended_happs,
jurisdiction,
hosting_preference,
happ_jurisdictions,
host_credentials,
host_happ_preferences,
published_happ_details,
)
.await?;
Ok(())
Expand Down
122 changes: 0 additions & 122 deletions src/transaction_types.rs

This file was deleted.

Loading

0 comments on commit 713a176

Please sign in to comment.