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

core-app-cli: host-prefs #173

Merged
merged 2 commits into from
Nov 22, 2023
Merged
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
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;
JettTech marked this conversation as resolved.
Show resolved Hide resolved
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,10 +1,13 @@
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;

#[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
Loading