Skip to content

feature: add agent pref endpoint #208

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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
31 changes: 31 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,31 @@
use anyhow::Result;
use holochain_types::{
dna::{AgentPubKey, AgentPubKeyB64},
prelude::{FunctionName, ZomeName},
};
use hpos_hc_connect::{app_connection::CoreAppRoleName, hha_agent::CoreAppAgent};

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_jurisdictions: Vec<(AgentPubKey, Option<String>)> = agent
.app
.zome_call_typed(
CoreAppRoleName::HHA.into(),
ZomeName::from("hha"),
FunctionName::from("get_agents_jurisdiction"),
vec![pubkey_bytes],
)
.await?;

if let Some(j) = &agent_jurisdictions[0].1 {
println!("===================");
println!("Jurisdiction for agent {:?}: {:?}", agent_pubkey, j);
println!("===================");
} else {
println!("Error: No jurisdiction found for agent {:?}", agent_pubkey)
}

Ok(())
}
25 changes: 25 additions & 0 deletions crates/core_app_cli/src/actions/get_happ_details.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use anyhow::Result;
use holochain_types::prelude::{FunctionName, ZomeName};
use hpos_hc_connect::{
app_connection::CoreAppRoleName, hha_agent::CoreAppAgent, hha_types::PresentedHappBundle,
};

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

let happ: PresentedHappBundle = agent
.app
.zome_call_typed(
CoreAppRoleName::HHA.into(),
ZomeName::from("hha"),
FunctionName::from("get_happ"),
happ_id.clone(),
)
.await?;

println!("===================");
println!("Happ Details {:?}", happ);
println!("===================");

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
26 changes: 26 additions & 0 deletions crates/core_app_cli/src/actions/list_all_happs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use anyhow::Result;
use holochain_types::prelude::{FunctionName, ZomeName};
use hpos_hc_connect::{
app_connection::CoreAppRoleName, hha_agent::CoreAppAgent, hha_types::PresentedHappBundle,
};

pub async fn get() -> Result<()> {
let mut agent = CoreAppAgent::spawn(None).await?;

let happs: Vec<PresentedHappBundle> = agent
.app
.zome_call_typed(
CoreAppRoleName::HHA.into(),
ZomeName::from("hha"),
FunctionName::from("get_happs"),
(),
)
.await?;

println!("===================");
println!("All Holo Happs: ");
println!("{:?}", happs);
println!("===================");

Ok(())
}
8 changes: 6 additions & 2 deletions crates/core_app_cli/src/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
pub mod enable_happ_for_host;
pub mod get_agents_jurisdiction;
pub mod get_all_happs_by;
pub mod get_happ_details;
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_happs;
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 register_happ;
pub mod set_host_happ_prefs;
pub mod summary;
43 changes: 43 additions & 0 deletions crates/core_app_cli/src/actions/register_happ.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use anyhow::Result;
use holochain_types::prelude::{FunctionName, ZomeName};
use hpos_hc_connect::{
app_connection::CoreAppRoleName,
hha_agent::CoreAppAgent,
hha_types::{HappInput, PresentedHappBundle},
};

pub async fn get(
hosted_urls: Vec<String>,
bundle_url: String,
name: String,
uid: Option<String>,
special_installed_app_id: Option<String>,
) -> Result<()> {
let mut agent = CoreAppAgent::spawn(None).await?;

let register_payload = HappInput {
name,
bundle_url,
uid,
hosted_urls,
special_installed_app_id,
..HappInput::default()
};

let published_happ: PresentedHappBundle = agent
.app
.zome_call_typed(
CoreAppRoleName::HHA.into(),
ZomeName::from("hha"),
FunctionName::from("register_happ"),
register_payload,
)
.await?;

println!("===================");
println!("Your Published Happ Bundle is: ");
println!("{:?}", published_happ);
println!("===================");

Ok(())
}
47 changes: 41 additions & 6 deletions crates/core_app_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,32 @@ pub enum Opt {
/// Pay your first pending invoice
#[structopt(name = "pay")]
PayInvoice,
/// List all happs registered in hha
#[structopt(name = "all-happs")]
AllHapps,
/// List happ setting details
#[structopt(name = "happ-details")]
HappDetails { happ_id: String },
/// Register happ
#[structopt(name = "register")]
RegisterHapp {
#[structopt(name = "hosted-urls")]
hosted_urls: Vec<String>,
bundle_url: String,
name: String,
#[structopt(name = "special-uid")]
uid: Option<String>,
special_id: Option<String>,
},
/// List all happs published by me
#[structopt(name = "my-happs")]
Happs,
HappsByMe,
/// List all happs by provided publisher
#[structopt(name = "publisher-happs")]
GetHappsForPublisher { publisher_pubkey: String },
GetHappsByPublisher { publisher_pubkey: String },
/// List the jurisdiction for the provided agent
#[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 @@ -67,19 +87,34 @@ impl Opt {
Opt::Ledger => core_app_cli::ledger::get().await?,
Opt::Transactions => core_app_cli::list_all_tx::get().await?,
Opt::PayInvoice => core_app_cli::pay_invoices::get().await?,
Opt::Happs => core_app_cli::list_all_my_happs::get().await?,
Opt::AllHapps => core_app_cli::list_all_happs::get().await?,
Opt::HappDetails { happ_id } => core_app_cli::get_happ_details::get(happ_id).await?,
Opt::RegisterHapp {
hosted_urls,
bundle_url,
name,
uid,
special_id,
} => {
core_app_cli::register_happ::get(hosted_urls, bundle_url, name, uid, special_id)
.await?
}
Opt::HappsByMe => core_app_cli::list_all_my_happs::get().await?,
Opt::Hosts { happ_id } => core_app_cli::get_happ_hosts::get(happ_id).await?,
Opt::GetPreferenceByHash { pref_hash } => {
core_app_cli::get_specific_happ_prefs::get(pref_hash).await?
}
Opt::GetHappsForPublisher { publisher_pubkey } => {
Opt::GetHappsByPublisher { 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 @@ -90,7 +125,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
2 changes: 1 addition & 1 deletion crates/hpos_connect_hc/src/hha_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub struct LoginConfig {
pub registration_info_url: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)]
#[derive(Default, Debug, Serialize, Deserialize, SerializedBytes, Clone)]
pub struct HappInput {
#[serde(default)]
pub hosted_urls: Vec<String>,
Expand Down
Loading