Skip to content

Commit

Permalink
core-app-cli: host-prefs (#173)
Browse files Browse the repository at this point in the history
Co-authored-by: Lisa Jetton <[email protected]>
  • Loading branch information
zo-el and JettTech authored Nov 22, 2023
1 parent 32ef10c commit c092929
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
30 changes: 30 additions & 0 deletions crates/core_app_cli/src/actions/get_happ_pref_for_host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// NB: This endpoint is used by the nightly tests. Any change to it's input or output should also be updated there.

use anyhow::Result;
use holochain_types::prelude::{ExternIO, FunctionName, ZomeName};
use hpos_hc_connect::{hha_types::HoloportDetails, CoreAppAgent, CoreAppRoleName};

pub async fn get(happ_id: String, host_id: String) -> Result<()> {
let mut agent = CoreAppAgent::connect().await?;

let result = agent
.zome_call(
CoreAppRoleName::HHA,
ZomeName::from("hha"),
FunctionName::from("get_hosts"),
ExternIO::encode(happ_id.clone())?,
)
.await?;

let hosts: Vec<HoloportDetails> = rmp_serde::from_slice(result.as_bytes())?;

let found = hosts.into_iter().find(|h| h.holoport_id.0 == host_id);

if let Some(d) = found {
if let Some(p) = d.preferences_hash {
println!("{:#?}", p)
}
}

Ok(())
}
1 change: 1 addition & 0 deletions crates/core_app_cli/src/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod get_happ_hosts;
pub mod get_happ_pref_for_host;
pub mod get_specific_happ_prefs;
pub mod ledger;
pub mod list_all_my_happs;
Expand Down
6 changes: 6 additions & 0 deletions crates/core_app_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub enum Opt {
/// Fetch the happ preferences associated with a `pref_hash`
#[structopt(name = "prefs")]
GetPreferenceByHash { pref_hash: String },
/// Fetch the happ preferences for a specific host for a specific happ
#[structopt(name = "host-prefs")]
GetHappPrefForHost { happ_id: String, host_id: String },
/// Set new happ preferences
#[structopt(name = "set-prefs")]
SetHappPreferences {
Expand Down Expand Up @@ -56,6 +59,9 @@ impl Opt {
Opt::GetPreferenceByHash { pref_hash } => {
core_app_cli::get_specific_happ_prefs::get(pref_hash).await?
}
Opt::GetHappPrefForHost { happ_id, host_id } => {
core_app_cli::get_happ_pref_for_host::get(happ_id, host_id).await?
}
Opt::SetHappPreferences {
happ_id,
price_compute,
Expand Down
5 changes: 4 additions & 1 deletion crates/hpos_connect_hc/src/hha_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use holochain_types::prelude::{holochain_serial, ActionHashB64, AgentPubKeyB64, SerializedBytes};
use holochain_types::prelude::{
holochain_serial, ActionHashB64, AgentPubKeyB64, SerializedBytes, Timestamp,
};
use holofuel_types::fuel::Fuel;
use serde::{Deserialize, Serialize};
use std::time::Duration;
Expand All @@ -11,6 +13,7 @@ pub struct HappAndHost {

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct HappPreferences {
pub timestamp: Timestamp,
pub max_fuel_before_invoice: Fuel,
pub price_compute: Fuel,
pub price_storage: Fuel,
Expand Down

0 comments on commit c092929

Please sign in to comment.