Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit: update happ bundle type #69

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -35,4 +35,4 @@ holochain_websocket = { version = "0.4.0-dev.20"}
mr_bundle = { version = "0.4.0-dev.7" }
hpos-config-core = { git = "https://github.com/Holo-Host/hpos-config", rev = "77d740c83a02e322e670e360eb450076b593b328" }
hpos-config-seed-bundle-explorer ={ git = "https://github.com/Holo-Host/hpos-config", rev = "77d740c83a02e322e670e360eb450076b593b328" }
hpos_hc_connect = { git = "https://github.com/holo-host/hpos-service-crates.git", rev = "6a58c8de95b0b38fed3bf9db2c93eeebd3f3c480" }
hpos_hc_connect = { git = "https://github.com/holo-host/hpos-service-crates.git", rev = "b60c6e3c8419f55048af734c80f54456de7a10be" }
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pub mod types;
mod utils;

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

use anyhow::Result;
Expand Down Expand Up @@ -66,7 +65,7 @@ pub async fn run(config: &Config) -> Result<()> {
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,
is_disabled_by_host: happ.host_settings.is_host_disabled,
},
);
}
Expand All @@ -87,14 +86,18 @@ pub async fn run(config: &Config) -> Result<()> {
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,
is_disabled_by_host: happ.host_settings.is_host_disabled,
},
);
}
}
}

let host_happ_preferences = core_app.get_host_preferences().await?.into();
trace!(
"Got host's hosting preferences : {:#?}",
host_happ_preferences
);

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

Expand Down
10 changes: 6 additions & 4 deletions src/types/happ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct InstallHappBody {
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct HappPreferences {
pub struct HostHappPreferences {
pub max_fuel_before_invoice: Fuel,
pub max_time_before_invoice: Duration,
pub price_compute: Fuel,
Expand All @@ -24,7 +24,7 @@ pub struct HappPreferences {
pub jurisdiction_prefs: Option<ExclusivePreferences>,
pub categories_prefs: Option<ExclusivePreferences>,
}
impl HappPreferences {
impl HostHappPreferences {
pub fn is_happ_publisher_in_valid_jurisdiction(
&self, // host preferences
maybe_publisher_jurisdiction: &Option<String>,
Expand Down Expand Up @@ -67,6 +67,8 @@ impl HappPreferences {
&self, // host preferences
happ_categories: &[String],
) -> bool {
tracing::trace!("Host's category settings: {:#?}", self.categories_prefs);

let (categories_list, is_exclusive_list) = match self.categories_prefs.to_owned() {
Some(c) => {
let categories_list: HashSet<String> = c.value.iter().cloned().collect();
Expand Down Expand Up @@ -95,9 +97,9 @@ impl HappPreferences {
}
}

impl From<hpos_hc_connect::hha_types::HappPreferences> for HappPreferences {
impl From<hpos_hc_connect::hha_types::HappPreferences> for HostHappPreferences {
fn from(value: hpos_hc_connect::hha_types::HappPreferences) -> Self {
HappPreferences {
HostHappPreferences {
max_fuel_before_invoice: value.max_fuel_before_invoice,
max_time_before_invoice: value.max_time_before_invoice,
price_compute: value.price_compute,
Expand Down
8 changes: 5 additions & 3 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ pub mod happ;
pub mod hbs;
pub mod transaction;
use holochain_types::dna::ActionHashB64;
use holochain_types::prelude::{holochain_serial, SerializedBytes};
use holochain_types::prelude::{holochain_serial, AgentPubKeyB64, SerializedBytes};
use hpos_hc_connect::hha_types::HostSettings;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Clone)]
pub struct HappBundle {
pub happ_id: ActionHashB64,
pub bundle_url: String,
pub is_paused: bool,
pub is_host_disabled: bool,
pub special_installed_app_id: Option<String>,
pub jurisdictions: Vec<String>,
pub exclude_jurisdictions: bool,
pub categories: Vec<String>,
pub host_settings: HostSettings,
pub host_settings: HostSettings, // host "enabled" settings
pub provider_pubkey: AgentPubKeyB64,
pub network_seed: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, SerializedBytes)]
Expand Down
21 changes: 13 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::types::PublishedHappDetails;
pub use crate::types::{
happ::{HappPreferences, InstallHappBody},
happ::{HostHappPreferences, InstallHappBody},
hbs::{HostCredentials, KycLevel},
transaction::InvoiceNote,
HappBundle,
Expand Down Expand Up @@ -72,12 +72,13 @@ pub async fn get_all_published_hosted_happs(
happ_id: happ.id,
bundle_url: happ.bundle_url,
is_paused: happ.is_paused,
is_host_disabled: happ.host_settings.is_host_disabled,
special_installed_app_id: happ.special_installed_app_id,
jurisdictions: happ.jurisdictions,
exclude_jurisdictions: happ.exclude_jurisdictions,
categories: happ.categories,
host_settings: happ.host_settings,
provider_pubkey: happ.provider_pubkey,
network_seed: happ.uid,
}
})
.collect();
Expand Down Expand Up @@ -161,7 +162,7 @@ pub async fn should_be_enabled(
happ_id: String,
suspended_happs: Vec<String>,
host_credentials: HostCredentials, // the kyc and jurisdiction of a host
host_happ_preferences: HappPreferences, // the hosting preferences a host sets
host_happ_preferences: HostHappPreferences, // the hosting preferences a host sets
published_happ_details: HashMap<String, PublishedHappDetails>, // the jurisdiction, categories, and publisher jurisdiction for each happ
) -> bool {
trace!(
Expand Down Expand Up @@ -203,6 +204,10 @@ pub async fn should_be_enabled(
}

// Verify that the hApp category is a valid host category.
trace!(
"Happ registered categories {:?}",
happ_registration_details.happ_categories
);
if !host_happ_preferences.is_happ_valid_category(&happ_registration_details.happ_categories)
{
warn!(
Expand Down Expand Up @@ -265,12 +270,12 @@ pub async fn install_holo_hosted_happs(
happ_id,
bundle_url,
is_paused,
is_host_disabled,
special_installed_app_id,
exclude_jurisdictions: _,
jurisdictions: _,
categories: _,
host_settings,
..
} in happs
{
trace!("Trying to install {}", happ_id);
Expand Down Expand Up @@ -305,7 +310,7 @@ pub async fn install_holo_hosted_happs(
}
}
// if the expected happ is disabled by the host, we don't install
else if is_host_disabled.to_owned() {
else if host_settings.is_host_disabled.to_owned() {
trace!(
"Skipping happ installation due to host's disabled setting for happ {}",
happ_id
Expand Down Expand Up @@ -364,7 +369,7 @@ pub async fn handle_ineligible_happs(
admin_port: u16,
suspended_happs: Vec<String>,
host_credentials: HostCredentials,
host_happ_preferences: HappPreferences,
host_happ_preferences: HostHappPreferences,
published_happ_details: HashMap<String, PublishedHappDetails>,
) -> Result<()> {
info!("Checking to uninstall happs that were removed from the hosted list....");
Expand All @@ -385,10 +390,10 @@ pub async fn handle_ineligible_happs(
.map(|h| &h.installed_app_id)
.unique()
.collect();
trace!("enabled_happ_ids {:?}", enabled_happ_ids);
trace!("Holochain enabled happ ids: {:?}", enabled_happ_ids);

let published_happ_ids: Vec<String> = published_happ_details.clone().into_keys().collect();
trace!("published_happ_ids {:?}", published_happ_ids);
trace!("Published happ ids {:?}", published_happ_ids);

for enabled_happ_id in enabled_happ_ids {
// Deteremine if the enabled happ is an instance of a published happ
Expand Down
Loading