Skip to content

Commit

Permalink
Merge pull request #22 from Holo-Host/prefs-to-yaml
Browse files Browse the repository at this point in the history
Write default servicelogger prefs to file on HPOS
  • Loading branch information
peeech authored Nov 8, 2022
2 parents d96a6b7 + e7fa5a1 commit c7a7dd2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 35 deletions.
63 changes: 37 additions & 26 deletions Cargo.lock

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

21 changes: 20 additions & 1 deletion src/entries.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use anyhow::{Context, Result};
use hc_utils::{WrappedActionHash, WrappedAgentPubKey};
use holochain_types::prelude::MembraneProof;
use holofuel_types::fuel::Fuel;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use std::fs::File;
use std::{collections::HashMap, env};
use tracing::info;

#[derive(Deserialize, Debug, Clone)]
pub struct DnaResource {
Expand Down Expand Up @@ -32,6 +35,22 @@ pub struct Preferences {
pub price_storage: Fuel,
pub price_bandwidth: Fuel,
}
impl Preferences {
/// Save preferences to a file under {SL_PREFS_PATH}
/// which allows hpos-holochain-api to read current values
pub fn save(self) -> Result<Self> {
if let Ok(path) = env::var("SL_PREFS_PATH") {
info!("Writing default servicelogger prefs to {}", &path);
// create or overwrite to a file
let file = File::create(&path)?;
serde_yaml::to_writer(file, &self).context(format!(
"Failed writing service logger preferences to file {}",
path
))?;
};
Ok(self)
}
}

#[derive(Serialize, Debug, Clone)]
pub struct InstallHappBody {
Expand Down
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ pub struct HappPkg {

pub async fn install_holo_hosted_happs(happs: &[HappPkg], config: &Config) -> Result<()> {
info!("Starting to install....");

// Hardcoded servicelogger preferences for all the hosted happs installed
let preferences = Preferences {
max_fuel_before_invoice: Fuel::from_str("1000")?, // MAX_TX_AMT in holofuel is currently hard-coded to 50,000
max_time_before_invoice: vec![86400, 0],
price_compute: Fuel::from_str("0.025")?,
price_storage: Fuel::from_str("0.025")?,
price_bandwidth: Fuel::from_str("0.025")?,
}
.save()?;

if happs.is_empty() {
info!("No happs registered to be enabled for hosting.");
return Ok(());
Expand All @@ -61,14 +72,7 @@ pub async fn install_holo_hosted_happs(happs: &[HappPkg], config: &Config) -> Re
);

let client = reqwest::Client::new();
// Note: Tmp preferences
let preferences = Preferences {
max_fuel_before_invoice: Fuel::from_str("10000")?, // MAX_TX_AMT in holofuel is currently hard-coded to 50,000
max_time_before_invoice: vec![86400, 0],
price_compute: Fuel::from_str("1")?,
price_storage: Fuel::from_str("1")?,
price_bandwidth: Fuel::from_str("1")?,
};

// iterate through the vec and
// Call http://localhost/holochain-api/install_hosted_happ
// for each WrappedActionHash to install the hosted_happ
Expand Down

0 comments on commit c7a7dd2

Please sign in to comment.