Skip to content

Commit

Permalink
add agent pref
Browse files Browse the repository at this point in the history
  • Loading branch information
JettTech committed Sep 10, 2024
1 parent 7d7d188 commit 387c4f6
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/core_app_cli/src/actions/enable_happ_for_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn get(happ_id: String, host_id: String) -> Result<()> {
println!("Enabled Happ ID {} for Host {}: ", happ_id, host_id);
println!("Fetching happ preference hash...");

crate::get_happ_pref_for_host::get(happ_id, host_id).await?;
crate::get_happ_pref_hash_for_host::get(happ_id, host_id).await?;

println!("===================");

Expand Down
37 changes: 37 additions & 0 deletions crates/core_app_cli/src/actions/get_agents_jurisdiction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use anyhow::Result;
use holochain_types::{
dna::{AgentPubKey, AgentPubKeyB64},
prelude::{FunctionName, ZomeName},
};
use hpos_hc_connect::{
app_connection::CoreAppRoleName, hha_agent::CoreAppAgent, hha_types::PresentedHappBundle,
};

pub async fn get(agent_pubkey: String) -> Result<()> {
let mut agent = CoreAppAgent::spawn(None).await?;
let pubkey_bytes: AgentPubKey = AgentPubKeyB64::from_b64_str(&agent_pubkey.clone())?.into();

let agent_jurisdiction: Vec<(AgentPubKey, Option<String>)> = agent
.app
.zome_call_typed(
CoreAppRoleName::HHA.into(),
ZomeName::from("hha"),
FunctionName::from("get_agents_jurisdiction"),
vec![pubkey_bytes],
)
.await?[0];

if let Some(d) = agent_jurisdiction.1 {
// Please do not change this print and if you do see that the nightly tests that depend on this print are updated as well
println!("===================");
println!(
"Hosting Preference for agent {:?}: {}",
agent_pubkey, jurisdiction
);
println!("===================");
} else {
println!("Error: No jurisdiction found for agent {:?}", agent_pubkey)
}

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub async fn get(happ_id: String, host_id: String) -> Result<()> {
println!("Happ Preference Hash: {:#?}", p);
println!("===================");
}
} else {
println!("Error: No preferences found for host {:?}", host_id)
}

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions crates/core_app_cli/src/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pub mod enable_happ_for_host;
pub mod get_agents_jurisdiction;
pub mod get_all_happs_by;
pub mod get_happ_hosts;
pub mod get_happ_pref_for_host;
pub mod get_happ_pref_hash_for_host;
pub mod get_specific_happ_prefs;
pub mod ledger;
pub mod list_all_my_happs;
pub mod list_all_tx;
pub mod pay_invoices;
pub mod profile;
pub mod set_happ_prefs;
pub mod set_host_happ_prefs;
10 changes: 8 additions & 2 deletions crates/core_app_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub enum Opt {
/// List all happs by provided publisher
#[structopt(name = "publisher-happs")]
GetHappsForPublisher { publisher_pubkey: String },
/// List all happs by provided publisher
#[structopt(name = "jurisdiction")]
GetAgentsJurisdiction { agent_pubkey: String },
/// List all hosts for a happ by `happ_id``
#[structopt(name = "hosts")]
Hosts { happ_id: String },
Expand Down Expand Up @@ -68,11 +71,14 @@ impl Opt {
Opt::GetHappsForPublisher { publisher_pubkey } => {
core_app_cli::get_all_happs_by::get(publisher_pubkey).await?
}
Opt::GetAgentsJurisdiction { agent_pubkey } => {
core_app_cli::get_agents_jurisdiction::get(agent_pubkey).await?
}
Opt::EnableHappForHost { happ_id, host_id } => {
core_app_cli::enable_happ_for_host::get(happ_id, host_id).await?
}
Opt::GetHappPrefHashForHost { happ_id, host_id } => {
core_app_cli::get_happ_pref_for_host::get(happ_id, host_id).await?
core_app_cli::get_happ_pref_hash_for_host::get(happ_id, host_id).await?
}
Opt::SetHappPreferences {
happ_id,
Expand All @@ -83,7 +89,7 @@ impl Opt {
max_time_before_invoice_sec,
max_time_before_invoice_ms,
} => {
core_app_cli::set_happ_prefs::get(
core_app_cli::set_host_happ_prefs::get(
happ_id,
price_compute,
price_bandwidth,
Expand Down

0 comments on commit 387c4f6

Please sign in to comment.