From b7c15b587e6df78b3f76c48c4bbb9a309ae29e33 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Thu, 19 Oct 2023 00:32:56 -0500 Subject: [PATCH 01/13] add new methods --- Cargo.lock | 61 ++++++++++++++- crates/core_app_cli/Cargo.toml | 3 +- crates/core_app_cli/README.md | 16 ++-- .../src/actions/get_happ_hosts.rs | 48 ++++++++++++ .../src/actions/get_specific_happ_prefs.rs | 39 ++++++++++ crates/core_app_cli/src/actions/mod.rs | 3 + .../src/actions/set_happ_prefs.rs | 76 +++++++++++++++++++ crates/core_app_cli/src/main.rs | 52 +++++++++++++ 8 files changed, 290 insertions(+), 8 deletions(-) create mode 100644 crates/core_app_cli/src/actions/get_happ_hosts.rs create mode 100644 crates/core_app_cli/src/actions/get_specific_happ_prefs.rs create mode 100644 crates/core_app_cli/src/actions/set_happ_prefs.rs diff --git a/Cargo.lock b/Cargo.lock index fd5b2d6b..18abe5b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -902,10 +902,11 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "core_app_cli" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "holochain_types", + "holofuel_types", "hpos_hc_connect", "rmp-serde 1.1.1", "serde", @@ -2049,6 +2050,37 @@ dependencies = [ "sodoken", ] +[[package]] +name = "hdi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b12f620a0d22b7dcd534a849f0024b0b47c4343b15f1c0ec02e37f4990f6f16" +dependencies = [ + "hdk_derive", + "holo_hash", + "holochain_integrity_types", + "holochain_wasmer_guest", + "paste", + "serde", + "serde_bytes", +] + +[[package]] +name = "hdk_derive" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc855dc170fec9ca44d2b21cba90fb961ef92acadaae0f0c7d090312a6212552" +dependencies = [ + "darling 0.14.4", + "heck 0.4.1", + "holochain_integrity_types", + "paste", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "heck" version = "0.3.3" @@ -2550,6 +2582,20 @@ dependencies = [ "wasmer-engine", ] +[[package]] +name = "holochain_wasmer_guest" +version = "0.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92b2026e44595cb16108464973622577936605582aa22932933a5130ad32ce42" +dependencies = [ + "holochain_serialized_bytes 0.0.51", + "holochain_wasmer_common", + "parking_lot 0.12.1", + "paste", + "serde", + "tracing", +] + [[package]] name = "holochain_wasmer_host" version = "0.0.84" @@ -2641,6 +2687,19 @@ dependencies = [ "tracing-subscriber 0.2.25", ] +[[package]] +name = "holofuel_types" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176efe08825a6f66a00556e3c72bc39a3ac7d93160983c5d955357e5e0e1b173" +dependencies = [ + "hdi", + "lazy_static", + "regex", + "serde", + "thiserror", +] + [[package]] name = "home" version = "0.5.5" diff --git a/crates/core_app_cli/Cargo.toml b/crates/core_app_cli/Cargo.toml index 9f485ce6..72532298 100644 --- a/crates/core_app_cli/Cargo.toml +++ b/crates/core_app_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core_app_cli" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["zo-el "] @@ -12,3 +12,4 @@ serde = { version = "1.0", features = ["derive"] } structopt = "0.3.0" rmp-serde = "1.1.1" tokio = { version = "1.11", features = [ "full" ] } +holofuel_types = "0.5.0" diff --git a/crates/core_app_cli/README.md b/crates/core_app_cli/README.md index 1e9c5a9d..436d28cd 100644 --- a/crates/core_app_cli/README.md +++ b/crates/core_app_cli/README.md @@ -1,7 +1,7 @@ # core_app_cli ``` -core_app_cli 0.1.0 +core_app_cli 0.1.1 USAGE: core_app_cli @@ -11,9 +11,13 @@ FLAGS: -V, --version Prints version information SUBCOMMANDS: - b Gets your balance, fees, promised and available Fuel - help Prints this message or the help of the given subcommand(s) - pay Pay your first pending invoice - pr Gets profile details - tx Gets the list of all your transactions + b Gets your balance, fees, promised and available Fuel + happs List all happs published by me + help Prints this message or the help of the given subcommand(s) + hosts List all hosts for a happ by `happ_id`` + pay Pay your first pending invoice + pr Gets profile details + prefs Fetch the happ preferences associated with a `pref_hash` + set-prefs Set new happ preferences + tx Gets the list of all your transactions ``` diff --git a/crates/core_app_cli/src/actions/get_happ_hosts.rs b/crates/core_app_cli/src/actions/get_happ_hosts.rs new file mode 100644 index 00000000..f8b84580 --- /dev/null +++ b/crates/core_app_cli/src/actions/get_happ_hosts.rs @@ -0,0 +1,48 @@ +use anyhow::Result; +use holochain_types::prelude::{ActionHashB64, AgentPubKeyB64, ExternIO, FunctionName, ZomeName}; +use holofuel_types::fuel::Fuel; +use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; +use serde::{Deserialize, Serialize}; +use std::time::Duration; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct HappPreferences { + pub max_fuel_before_invoice: f64, + pub price_compute: Fuel, + pub price_storage: Fuel, + pub price_bandwidth: Fuel, + pub max_time_before_invoice: Duration, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct HoloportId(pub String); + +#[derive(Debug, Clone, Deserialize)] +pub struct HoloportDetails { + pub host_pub_key: AgentPubKeyB64, + pub holoport_id: HoloportId, + pub preferences: Option, + pub preferences_hash: Option, +} + +pub async fn get(happ_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 = rmp_serde::from_slice(result.as_bytes())?; + + println!("==================="); + println!("All Hosts for Happ ID {} are: ", happ_id); + println!("{:#?}", hosts); + println!("==================="); + + Ok(()) +} diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs new file mode 100644 index 00000000..fd2b984e --- /dev/null +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -0,0 +1,39 @@ +use anyhow::Result; +use holochain_types::prelude::{ActionHash, ActionHashB64, ExternIO, FunctionName, ZomeName}; +use holofuel_types::fuel::Fuel; +use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; +use serde::{Deserialize, Serialize}; +use std::time::Duration; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct HappPreferences { + pub max_fuel_before_invoice: f64, + pub price_compute: Fuel, + pub price_storage: Fuel, + pub price_bandwidth: Fuel, + pub max_time_before_invoice: Duration, +} + +pub async fn get(pref_hash: String) -> Result<()> { + let mut agent = CoreAppAgent::connect().await?; + + let pref_holo_hash = ActionHashB64::from_b64_str(&pref_hash)?; + + let result = agent + .zome_call( + CoreAppRoleName::HHA, + ZomeName::from("hha"), + FunctionName::from("get_specific_happ_preferences"), + ExternIO::encode(ActionHash::from(pref_holo_hash))?, + ) + .await?; + + let prefs: HappPreferences = rmp_serde::from_slice(result.as_bytes())?; + + println!("==================="); + println!("All Hosts for Preference Hash {} are: ", pref_hash); + println!("{:#?}", prefs); + println!("==================="); + + Ok(()) +} diff --git a/crates/core_app_cli/src/actions/mod.rs b/crates/core_app_cli/src/actions/mod.rs index 82233411..ca2564a5 100644 --- a/crates/core_app_cli/src/actions/mod.rs +++ b/crates/core_app_cli/src/actions/mod.rs @@ -1,5 +1,8 @@ +pub mod get_happ_hosts; +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; diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs new file mode 100644 index 00000000..0f289825 --- /dev/null +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -0,0 +1,76 @@ +use anyhow::Result; +use holochain_types::prelude::{ActionHashB64, ExternIO, FunctionName, ZomeName}; +use holofuel_types::fuel::Fuel; +use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; +use serde::{Deserialize, Serialize}; +use std::time::Duration; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct HappPreferences { + pub max_fuel_before_invoice: f64, + pub price_compute: Fuel, + pub price_storage: Fuel, + pub price_bandwidth: Fuel, + pub max_time_before_invoice: Duration, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct SetHappPreferencesInput { + pub happ_id: ActionHashB64, + pub max_fuel_before_invoice: f64, // how much holofuel to accumulate before sending invoice + pub price_compute: String, + pub price_storage: String, + pub price_bandwidth: String, + pub max_time_before_invoice: Duration, // how much time to allow to pass before sending invoice even if fuel trigger not reached. +} + +pub async fn get( + happ_id: String, + price_compute: String, + price_storage: String, + price_bandwidth: String, + max_fuel_before_invoice: String, + max_time_before_invoice: (String, String), +) -> Result<()> { + let mut agent = CoreAppAgent::connect().await?; + + let max_time_sec = max_time_before_invoice + .0 + .parse::() + .expect("Failed to convert `max_fuel_before_invoice` to i64."); + let max_time_ms = max_time_before_invoice + .1 + .parse::() + .expect("Failed to convert `max_fuel_before_invoice` to i32."); + + let max_fuel_before_invoice = max_fuel_before_invoice + .parse::() + .expect("Failed to convert `max_fuel_before_invoice` to f64."); + + let host_pricing_prefs = SetHappPreferencesInput { + happ_id: ActionHashB64::from_b64_str(&happ_id)?, + max_fuel_before_invoice, + price_compute, + price_storage, + price_bandwidth, + max_time_before_invoice: Duration::new(max_time_sec, max_time_ms), + }; + + let result = agent + .zome_call( + CoreAppRoleName::HHA, + ZomeName::from("hha"), + FunctionName::from("set_happ_preferences"), + ExternIO::encode(host_pricing_prefs)?, + ) + .await?; + + let happ_prefs: HappPreferences = rmp_serde::from_slice(result.as_bytes())?; + + println!("==================="); + println!("Your Published Happ Preferences are: "); + println!("{:?}", happ_prefs); + println!("==================="); + + Ok(()) +} diff --git a/crates/core_app_cli/src/main.rs b/crates/core_app_cli/src/main.rs index 1698404e..50568c0b 100644 --- a/crates/core_app_cli/src/main.rs +++ b/crates/core_app_cli/src/main.rs @@ -1,7 +1,13 @@ use anyhow::Result; use structopt::StructOpt; +fn parse_tuple(arg: &str) -> Result<(String, String)> { + let tuple_as_vec: Vec<&str> = arg.trim().split(",").collect(); + Ok((tuple_as_vec[0].to_string(), tuple_as_vec[1].to_string())) +} + #[derive(Debug, StructOpt)] +#[structopt(name = "core-app-cli", about = "An example of StructOpt usage.")] pub enum Opt { /// Gets profile details #[structopt(name = "pr")] @@ -18,6 +24,30 @@ pub enum Opt { /// List all happs published by me #[structopt(name = "happs")] Happs, + /// List all hosts for a happ by `happ_id`` + #[structopt(name = "hosts")] + Hosts { happ_id: String }, + /// Fetch the happ preferences associated with a `pref_hash` + #[structopt(name = "prefs")] + GetPreferenceByHash { + #[structopt(name = "hash")] + pref_hash: String, + }, + /// Set new happ preferences + #[structopt(name = "set-prefs")] + SetHappPreferences { + happ_id: String, + #[structopt(name = "compute")] + price_compute: String, + #[structopt(name = "storage")] + price_storage: String, + #[structopt(name = "bandwidth")] + price_bandwidth: String, + #[structopt(name = "max-fuel")] + max_fuel_before_invoice: String, + #[structopt(name = "max-time", parse(try_from_str = parse_tuple))] + max_time_before_invoice: (String, String), + }, } impl Opt { /// Run this command @@ -28,6 +58,28 @@ impl Opt { 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::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::SetHappPreferences { + happ_id, + price_compute, + price_bandwidth, + price_storage, + max_fuel_before_invoice, + max_time_before_invoice, + } => { + core_app_cli::set_happ_prefs::get( + happ_id, + price_compute, + price_bandwidth, + price_storage, + max_fuel_before_invoice, + max_time_before_invoice, + ) + .await? + } } Ok(()) } From cd3c57949100a73e4e51d5c6aebe7fb105e200b7 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Mon, 23 Oct 2023 00:28:15 -0500 Subject: [PATCH 02/13] add logs --- crates/core_app_cli/src/actions/get_happ_hosts.rs | 4 ++++ crates/core_app_cli/src/actions/get_specific_happ_prefs.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/crates/core_app_cli/src/actions/get_happ_hosts.rs b/crates/core_app_cli/src/actions/get_happ_hosts.rs index f8b84580..19f701e7 100644 --- a/crates/core_app_cli/src/actions/get_happ_hosts.rs +++ b/crates/core_app_cli/src/actions/get_happ_hosts.rs @@ -26,6 +26,8 @@ pub struct HoloportDetails { } pub async fn get(happ_id: String) -> Result<()> { + println!(" >>>>>>>>>>>>> happ_id {:?} ", happ_id); + let mut agent = CoreAppAgent::connect().await?; let result = agent @@ -36,8 +38,10 @@ pub async fn get(happ_id: String) -> Result<()> { ExternIO::encode(happ_id.clone())?, ) .await?; + println!(" >>>>>>>>>>>>> result {:?} ", result); let hosts: Vec = rmp_serde::from_slice(result.as_bytes())?; + println!(" >>>>>>>>>>>>> hosts {:?} ", hosts); println!("==================="); println!("All Hosts for Happ ID {} are: ", happ_id); diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs index fd2b984e..bc44fd14 100644 --- a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -15,9 +15,12 @@ pub struct HappPreferences { } pub async fn get(pref_hash: String) -> Result<()> { + println!(" >>>>>>>>>>>>> pref_hash {:?} ", pref_hash); + let mut agent = CoreAppAgent::connect().await?; let pref_holo_hash = ActionHashB64::from_b64_str(&pref_hash)?; + println!(" >>>>>>>>>>>>> pref_holo_hash {:?} ", pref_holo_hash); let result = agent .zome_call( @@ -28,7 +31,10 @@ pub async fn get(pref_hash: String) -> Result<()> { ) .await?; + println!(" >>>>>>>>>>>>> result {:?} ", result); + let prefs: HappPreferences = rmp_serde::from_slice(result.as_bytes())?; + println!(" >>>>>>>>>>>>> prefs {:?} ", prefs); println!("==================="); println!("All Hosts for Preference Hash {} are: ", pref_hash); From c713d1375364534b364fa742a8fcba19adb52401 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Tue, 24 Oct 2023 13:24:42 -0500 Subject: [PATCH 03/13] update types to match updates in hha types --- .../src/actions/get_happ_hosts.rs | 2 +- .../src/actions/get_specific_happ_prefs.rs | 2 +- .../src/actions/set_happ_prefs.rs | 24 ++++++++----------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/crates/core_app_cli/src/actions/get_happ_hosts.rs b/crates/core_app_cli/src/actions/get_happ_hosts.rs index 19f701e7..74a0a0c8 100644 --- a/crates/core_app_cli/src/actions/get_happ_hosts.rs +++ b/crates/core_app_cli/src/actions/get_happ_hosts.rs @@ -7,7 +7,7 @@ use std::time::Duration; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct HappPreferences { - pub max_fuel_before_invoice: f64, + pub max_fuel_before_invoice: Fuel, pub price_compute: Fuel, pub price_storage: Fuel, pub price_bandwidth: Fuel, diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs index bc44fd14..6dd2d86c 100644 --- a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -7,7 +7,7 @@ use std::time::Duration; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct HappPreferences { - pub max_fuel_before_invoice: f64, + pub max_fuel_before_invoice: Fuel, pub price_compute: Fuel, pub price_storage: Fuel, pub price_bandwidth: Fuel, diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index 0f289825..1926caf1 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -3,11 +3,11 @@ use holochain_types::prelude::{ActionHashB64, ExternIO, FunctionName, ZomeName}; use holofuel_types::fuel::Fuel; use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; use serde::{Deserialize, Serialize}; -use std::time::Duration; +use std::{str::FromStr, time::Duration}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct HappPreferences { - pub max_fuel_before_invoice: f64, + pub max_fuel_before_invoice: Fuel, pub price_compute: Fuel, pub price_storage: Fuel, pub price_bandwidth: Fuel, @@ -17,10 +17,10 @@ pub struct HappPreferences { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct SetHappPreferencesInput { pub happ_id: ActionHashB64, - pub max_fuel_before_invoice: f64, // how much holofuel to accumulate before sending invoice - pub price_compute: String, - pub price_storage: String, - pub price_bandwidth: String, + pub max_fuel_before_invoice: Fuel, // how much holofuel to accumulate before sending invoice + pub price_compute: Fuel, + pub price_storage: Fuel, + pub price_bandwidth: Fuel, pub max_time_before_invoice: Duration, // how much time to allow to pass before sending invoice even if fuel trigger not reached. } @@ -43,16 +43,12 @@ pub async fn get( .parse::() .expect("Failed to convert `max_fuel_before_invoice` to i32."); - let max_fuel_before_invoice = max_fuel_before_invoice - .parse::() - .expect("Failed to convert `max_fuel_before_invoice` to f64."); - let host_pricing_prefs = SetHappPreferencesInput { happ_id: ActionHashB64::from_b64_str(&happ_id)?, - max_fuel_before_invoice, - price_compute, - price_storage, - price_bandwidth, + max_fuel_before_invoice: Fuel::from_str(&max_fuel_before_invoice), + price_compute: Fuel::from_str(&price_compute), + price_storage: Fuel::from_str(&price_storage), + price_bandwidth: Fuel::from_str(&price_bandwidth), max_time_before_invoice: Duration::new(max_time_sec, max_time_ms), }; From a59e77c613f6f81aabf7ebe70c312e1c7499c210 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Wed, 25 Oct 2023 23:37:07 -0500 Subject: [PATCH 04/13] unwrap result --- crates/core_app_cli/src/actions/set_happ_prefs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index 1926caf1..5d8bb714 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -45,10 +45,10 @@ pub async fn get( let host_pricing_prefs = SetHappPreferencesInput { happ_id: ActionHashB64::from_b64_str(&happ_id)?, - max_fuel_before_invoice: Fuel::from_str(&max_fuel_before_invoice), - price_compute: Fuel::from_str(&price_compute), - price_storage: Fuel::from_str(&price_storage), - price_bandwidth: Fuel::from_str(&price_bandwidth), + max_fuel_before_invoice: Fuel::from_str(&max_fuel_before_invoice)?, + price_compute: Fuel::from_str(&price_compute)?, + price_storage: Fuel::from_str(&price_storage)?, + price_bandwidth: Fuel::from_str(&price_bandwidth)?, max_time_before_invoice: Duration::new(max_time_sec, max_time_ms), }; From 3ed73f48e50690e8d8af6394ed174ef8007468e5 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Thu, 26 Oct 2023 01:39:28 -0500 Subject: [PATCH 05/13] update logs --- crates/core_app_cli/src/actions/get_happ_hosts.rs | 4 ---- .../core_app_cli/src/actions/get_specific_happ_prefs.rs | 5 ++++- crates/core_app_cli/src/actions/set_happ_prefs.rs | 9 +++++++++ crates/core_app_cli/src/main.rs | 5 +---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/crates/core_app_cli/src/actions/get_happ_hosts.rs b/crates/core_app_cli/src/actions/get_happ_hosts.rs index 74a0a0c8..d694dfa1 100644 --- a/crates/core_app_cli/src/actions/get_happ_hosts.rs +++ b/crates/core_app_cli/src/actions/get_happ_hosts.rs @@ -26,8 +26,6 @@ pub struct HoloportDetails { } pub async fn get(happ_id: String) -> Result<()> { - println!(" >>>>>>>>>>>>> happ_id {:?} ", happ_id); - let mut agent = CoreAppAgent::connect().await?; let result = agent @@ -38,10 +36,8 @@ pub async fn get(happ_id: String) -> Result<()> { ExternIO::encode(happ_id.clone())?, ) .await?; - println!(" >>>>>>>>>>>>> result {:?} ", result); let hosts: Vec = rmp_serde::from_slice(result.as_bytes())?; - println!(" >>>>>>>>>>>>> hosts {:?} ", hosts); println!("==================="); println!("All Hosts for Happ ID {} are: ", happ_id); diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs index 6dd2d86c..f2b4f577 100644 --- a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -22,12 +22,15 @@ pub async fn get(pref_hash: String) -> Result<()> { let pref_holo_hash = ActionHashB64::from_b64_str(&pref_hash)?; println!(" >>>>>>>>>>>>> pref_holo_hash {:?} ", pref_holo_hash); + let hash = ActionHash::from(pref_holo_hash); + println!(" >>>>>>>>>>>>> hash {:?} ", hash); + let result = agent .zome_call( CoreAppRoleName::HHA, ZomeName::from("hha"), FunctionName::from("get_specific_happ_preferences"), - ExternIO::encode(ActionHash::from(pref_holo_hash))?, + ExternIO::encode(hash)?, ) .await?; diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index 5d8bb714..e74dbeb2 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -38,10 +38,13 @@ pub async fn get( .0 .parse::() .expect("Failed to convert `max_fuel_before_invoice` to i64."); + println!(" >>>>>>>>>>>>> max_time_sec {:?} ", max_time_sec); + let max_time_ms = max_time_before_invoice .1 .parse::() .expect("Failed to convert `max_fuel_before_invoice` to i32."); + println!(" >>>>>>>>>>>>> max_time_ms {:?} ", max_time_ms); let host_pricing_prefs = SetHappPreferencesInput { happ_id: ActionHashB64::from_b64_str(&happ_id)?, @@ -51,6 +54,10 @@ pub async fn get( price_bandwidth: Fuel::from_str(&price_bandwidth)?, max_time_before_invoice: Duration::new(max_time_sec, max_time_ms), }; + println!( + " >>>>>>>>>>>>> host_pricing_prefs {:?} ", + host_pricing_prefs + ); let result = agent .zome_call( @@ -60,8 +67,10 @@ pub async fn get( ExternIO::encode(host_pricing_prefs)?, ) .await?; + println!(" >>>>>>>>>>>>> result {:?} ", result); let happ_prefs: HappPreferences = rmp_serde::from_slice(result.as_bytes())?; + println!(" >>>>>>>>>>>>> happ_prefs {:?} ", happ_prefs); println!("==================="); println!("Your Published Happ Preferences are: "); diff --git a/crates/core_app_cli/src/main.rs b/crates/core_app_cli/src/main.rs index 50568c0b..026241ce 100644 --- a/crates/core_app_cli/src/main.rs +++ b/crates/core_app_cli/src/main.rs @@ -29,10 +29,7 @@ pub enum Opt { Hosts { happ_id: String }, /// Fetch the happ preferences associated with a `pref_hash` #[structopt(name = "prefs")] - GetPreferenceByHash { - #[structopt(name = "hash")] - pref_hash: String, - }, + GetPreferenceByHash { pref_hash: String }, /// Set new happ preferences #[structopt(name = "set-prefs")] SetHappPreferences { From 5ec23ba219f31e6b5875abe374217ceca9cd6749 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Thu, 26 Oct 2023 03:08:39 -0500 Subject: [PATCH 06/13] add log --- .../src/actions/get_specific_happ_prefs.rs | 2 +- .../src/actions/set_happ_prefs.rs | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs index f2b4f577..f6ea641b 100644 --- a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -30,7 +30,7 @@ pub async fn get(pref_hash: String) -> Result<()> { CoreAppRoleName::HHA, ZomeName::from("hha"), FunctionName::from("get_specific_happ_preferences"), - ExternIO::encode(hash)?, + ExternIO::encode(rmp_serde::to_vec_named(&hash)?)?, ) .await?; diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index e74dbeb2..74904fa8 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -32,18 +32,34 @@ pub async fn get( max_fuel_before_invoice: String, max_time_before_invoice: (String, String), ) -> Result<()> { + println!( + " >>>>>>>>>>>>> in `set_happ_prefs` helper: + happ_id ({:?}), + price_compute ({:?}), + price_storage ({:?}), + price_bandwidth ({:?}), + max_fuel_before_invoice ({:?}), + max_time_before_invoice ({:?})", + happ_id, + price_compute, + price_storage, + price_bandwidth, + max_fuel_before_invoice, + max_time_before_invoice + ); + let mut agent = CoreAppAgent::connect().await?; let max_time_sec = max_time_before_invoice .0 .parse::() - .expect("Failed to convert `max_fuel_before_invoice` to i64."); + .expect("Failed to convert `max_time_before_invoice` seconds to U64."); println!(" >>>>>>>>>>>>> max_time_sec {:?} ", max_time_sec); let max_time_ms = max_time_before_invoice .1 .parse::() - .expect("Failed to convert `max_fuel_before_invoice` to i32."); + .expect("Failed to convert `max_time_before_invoice` milliseconds to U32."); println!(" >>>>>>>>>>>>> max_time_ms {:?} ", max_time_ms); let host_pricing_prefs = SetHappPreferencesInput { From e699e778bdb854cae0c71bfc343f95b39508ec4d Mon Sep 17 00:00:00 2001 From: Jetttech Date: Thu, 26 Oct 2023 11:38:52 -0500 Subject: [PATCH 07/13] core-app-cli: parse tuple string --- .../core_app_cli/src/actions/get_specific_happ_prefs.rs | 2 +- crates/core_app_cli/src/actions/set_happ_prefs.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs index f6ea641b..f2b4f577 100644 --- a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -30,7 +30,7 @@ pub async fn get(pref_hash: String) -> Result<()> { CoreAppRoleName::HHA, ZomeName::from("hha"), FunctionName::from("get_specific_happ_preferences"), - ExternIO::encode(rmp_serde::to_vec_named(&hash)?)?, + ExternIO::encode(hash)?, ) .await?; diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index 74904fa8..1ce02ae0 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -50,6 +50,14 @@ pub async fn get( let mut agent = CoreAppAgent::connect().await?; + max_time_before_invoice = max_time_before_invoice + .parse::<(String, String)>() + .expect("Failed to convert `max_time_before_invoice` param to string tuple."); + println!( + " >>>>>>>>>>>>> max_time_before_invoice {:?} ", + max_time_before_invoice + ); + let max_time_sec = max_time_before_invoice .0 .parse::() From dbc7962cf38217e59a813c3d7fddc62e0d169e3d Mon Sep 17 00:00:00 2001 From: Jetttech Date: Fri, 27 Oct 2023 10:49:08 -0500 Subject: [PATCH 08/13] clean --- .../src/actions/set_happ_prefs.rs | 23 +++++++------------ crates/core_app_cli/src/main.rs | 17 +++++++------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index 1ce02ae0..efff3994 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -30,7 +30,8 @@ pub async fn get( price_storage: String, price_bandwidth: String, max_fuel_before_invoice: String, - max_time_before_invoice: (String, String), + max_time_before_invoice_sec: String, + max_time_before_invoice_ms: String, ) -> Result<()> { println!( " >>>>>>>>>>>>> in `set_happ_prefs` helper: @@ -39,33 +40,25 @@ pub async fn get( price_storage ({:?}), price_bandwidth ({:?}), max_fuel_before_invoice ({:?}), - max_time_before_invoice ({:?})", + max_time_before_invoice_sec ({:?}), + max_time_before_invoice_ms ({:?})", happ_id, price_compute, price_storage, price_bandwidth, max_fuel_before_invoice, - max_time_before_invoice + max_time_before_invoice_sec, + max_time_before_invoice_ms ); let mut agent = CoreAppAgent::connect().await?; - max_time_before_invoice = max_time_before_invoice - .parse::<(String, String)>() - .expect("Failed to convert `max_time_before_invoice` param to string tuple."); - println!( - " >>>>>>>>>>>>> max_time_before_invoice {:?} ", - max_time_before_invoice - ); - - let max_time_sec = max_time_before_invoice - .0 + let max_time_sec = max_time_before_invoice_sec .parse::() .expect("Failed to convert `max_time_before_invoice` seconds to U64."); println!(" >>>>>>>>>>>>> max_time_sec {:?} ", max_time_sec); - let max_time_ms = max_time_before_invoice - .1 + let max_time_ms = max_time_before_invoice_ms .parse::() .expect("Failed to convert `max_time_before_invoice` milliseconds to U32."); println!(" >>>>>>>>>>>>> max_time_ms {:?} ", max_time_ms); diff --git a/crates/core_app_cli/src/main.rs b/crates/core_app_cli/src/main.rs index 026241ce..8934f2df 100644 --- a/crates/core_app_cli/src/main.rs +++ b/crates/core_app_cli/src/main.rs @@ -1,11 +1,6 @@ use anyhow::Result; use structopt::StructOpt; -fn parse_tuple(arg: &str) -> Result<(String, String)> { - let tuple_as_vec: Vec<&str> = arg.trim().split(",").collect(); - Ok((tuple_as_vec[0].to_string(), tuple_as_vec[1].to_string())) -} - #[derive(Debug, StructOpt)] #[structopt(name = "core-app-cli", about = "An example of StructOpt usage.")] pub enum Opt { @@ -42,8 +37,10 @@ pub enum Opt { price_bandwidth: String, #[structopt(name = "max-fuel")] max_fuel_before_invoice: String, - #[structopt(name = "max-time", parse(try_from_str = parse_tuple))] - max_time_before_invoice: (String, String), + #[structopt(name = "max-time-s")] + max_time_before_invoice_sec: String, + #[structopt(name = "max-time-ms")] + max_time_before_invoice_ms: String, }, } impl Opt { @@ -65,7 +62,8 @@ impl Opt { price_bandwidth, price_storage, max_fuel_before_invoice, - max_time_before_invoice, + max_time_before_invoice_sec, + max_time_before_invoice_ms, } => { core_app_cli::set_happ_prefs::get( happ_id, @@ -73,7 +71,8 @@ impl Opt { price_bandwidth, price_storage, max_fuel_before_invoice, - max_time_before_invoice, + max_time_before_invoice_sec, + max_time_before_invoice_ms, ) .await? } From 593c6da2313d6ef7acebce62a60d740b926de9f9 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Sat, 28 Oct 2023 15:01:05 -0500 Subject: [PATCH 09/13] clean logs --- .../src/actions/get_specific_happ_prefs.rs | 9 ------- .../src/actions/set_happ_prefs.rs | 26 ------------------- 2 files changed, 35 deletions(-) diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs index f2b4f577..62999a5d 100644 --- a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -15,15 +15,9 @@ pub struct HappPreferences { } pub async fn get(pref_hash: String) -> Result<()> { - println!(" >>>>>>>>>>>>> pref_hash {:?} ", pref_hash); - let mut agent = CoreAppAgent::connect().await?; - let pref_holo_hash = ActionHashB64::from_b64_str(&pref_hash)?; - println!(" >>>>>>>>>>>>> pref_holo_hash {:?} ", pref_holo_hash); - let hash = ActionHash::from(pref_holo_hash); - println!(" >>>>>>>>>>>>> hash {:?} ", hash); let result = agent .zome_call( @@ -34,10 +28,7 @@ pub async fn get(pref_hash: String) -> Result<()> { ) .await?; - println!(" >>>>>>>>>>>>> result {:?} ", result); - let prefs: HappPreferences = rmp_serde::from_slice(result.as_bytes())?; - println!(" >>>>>>>>>>>>> prefs {:?} ", prefs); println!("==================="); println!("All Hosts for Preference Hash {} are: ", pref_hash); diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index efff3994..42af0d09 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -33,35 +33,15 @@ pub async fn get( max_time_before_invoice_sec: String, max_time_before_invoice_ms: String, ) -> Result<()> { - println!( - " >>>>>>>>>>>>> in `set_happ_prefs` helper: - happ_id ({:?}), - price_compute ({:?}), - price_storage ({:?}), - price_bandwidth ({:?}), - max_fuel_before_invoice ({:?}), - max_time_before_invoice_sec ({:?}), - max_time_before_invoice_ms ({:?})", - happ_id, - price_compute, - price_storage, - price_bandwidth, - max_fuel_before_invoice, - max_time_before_invoice_sec, - max_time_before_invoice_ms - ); - let mut agent = CoreAppAgent::connect().await?; let max_time_sec = max_time_before_invoice_sec .parse::() .expect("Failed to convert `max_time_before_invoice` seconds to U64."); - println!(" >>>>>>>>>>>>> max_time_sec {:?} ", max_time_sec); let max_time_ms = max_time_before_invoice_ms .parse::() .expect("Failed to convert `max_time_before_invoice` milliseconds to U32."); - println!(" >>>>>>>>>>>>> max_time_ms {:?} ", max_time_ms); let host_pricing_prefs = SetHappPreferencesInput { happ_id: ActionHashB64::from_b64_str(&happ_id)?, @@ -71,10 +51,6 @@ pub async fn get( price_bandwidth: Fuel::from_str(&price_bandwidth)?, max_time_before_invoice: Duration::new(max_time_sec, max_time_ms), }; - println!( - " >>>>>>>>>>>>> host_pricing_prefs {:?} ", - host_pricing_prefs - ); let result = agent .zome_call( @@ -84,10 +60,8 @@ pub async fn get( ExternIO::encode(host_pricing_prefs)?, ) .await?; - println!(" >>>>>>>>>>>>> result {:?} ", result); let happ_prefs: HappPreferences = rmp_serde::from_slice(result.as_bytes())?; - println!(" >>>>>>>>>>>>> happ_prefs {:?} ", happ_prefs); println!("==================="); println!("Your Published Happ Preferences are: "); From 77112329c39c30059e8808124f93ab43d853e225 Mon Sep 17 00:00:00 2001 From: zo-el Date: Sun, 29 Oct 2023 09:32:41 -0500 Subject: [PATCH 10/13] hha: types --- crates/core_app_cli/src/actions/list_all_my_happs.rs | 10 +++++----- crates/holo_happ_manager/src/hha_type.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/core_app_cli/src/actions/list_all_my_happs.rs b/crates/core_app_cli/src/actions/list_all_my_happs.rs index 171fcfad..dcd0c86f 100644 --- a/crates/core_app_cli/src/actions/list_all_my_happs.rs +++ b/crates/core_app_cli/src/actions/list_all_my_happs.rs @@ -23,16 +23,16 @@ pub struct PresentedHappBundle { pub categories: Vec, pub jurisdictions: Vec, pub exclude_jurisdictions: bool, - pub hosting_prices: HostingPrices, + pub publisher_pricing_pref: PublisherPricingPref, pub login_config: LoginConfig, pub special_installed_app_id: Option, } #[derive(Debug, Serialize, Deserialize, SerializedBytes)] -pub struct HostingPrices { - pub cpu: String, - pub storage: String, - pub bandwidth: String, +pub struct PublisherPricingPref { + pub cpu: Fuel, + pub storage: Fuel, + pub bandwidth: Fuel, } #[derive(Debug, Serialize, Deserialize, SerializedBytes)] diff --git a/crates/holo_happ_manager/src/hha_type.rs b/crates/holo_happ_manager/src/hha_type.rs index 0d66cfc4..c1277296 100644 --- a/crates/holo_happ_manager/src/hha_type.rs +++ b/crates/holo_happ_manager/src/hha_type.rs @@ -24,7 +24,7 @@ pub struct HappInput { #[serde(default)] pub exclude_jurisdictions: bool, // #[serde(default)] - pub hosting_prices: HostingPrices, + pub publisher_pricing_pref: PublisherPricingPref, #[serde(default)] pub login_config: LoginConfig, #[serde(default)] // default Option is None @@ -38,10 +38,10 @@ pub struct LoginConfig { } #[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone, Default)] -pub struct HostingPrices { - pub cpu: String, - pub storage: String, - pub bandwidth: String, +pub struct PublisherPricingPref { + pub cpu: Fuel, + pub storage: Fuel, + pub bandwidth: Fuel, } #[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] From 6c843149958bf7cbedf015e294f5ea75ce562000 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Sun, 29 Oct 2023 13:51:41 -0500 Subject: [PATCH 11/13] fix test and default trait for `PublisherPricingPref~ --- Cargo.lock | 1 + .../src/actions/list_all_my_happs.rs | 1 + crates/holo_happ_manager/Cargo.toml | 1 + crates/holo_happ_manager/src/hha_type.rs | 29 +++++++++++++------ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18abe5b0..c7c0c4b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2150,6 +2150,7 @@ dependencies = [ "holochain_env_setup", "holochain_keystore", "holochain_types", + "holofuel_types", "hpos-config-core", "hpos_hc_connect", "rmp-serde 1.1.1", diff --git a/crates/core_app_cli/src/actions/list_all_my_happs.rs b/crates/core_app_cli/src/actions/list_all_my_happs.rs index dcd0c86f..2a31373d 100644 --- a/crates/core_app_cli/src/actions/list_all_my_happs.rs +++ b/crates/core_app_cli/src/actions/list_all_my_happs.rs @@ -3,6 +3,7 @@ use holochain_types::prelude::{ holochain_serial, ActionHashB64, AgentPubKeyB64, ExternIO, FunctionName, SerializedBytes, ZomeName, }; +use holofuel_types::fuel::Fuel; use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; use serde::{Deserialize, Serialize}; diff --git a/crates/holo_happ_manager/Cargo.toml b/crates/holo_happ_manager/Cargo.toml index 27b0d419..32378858 100644 --- a/crates/holo_happ_manager/Cargo.toml +++ b/crates/holo_happ_manager/Cargo.toml @@ -21,6 +21,7 @@ tracing-subscriber = "0.3.17" tokio = "1.28.2" url2 = "0.0.6" hpos-config-core = { git = "https://github.com/Holo-Host/hpos-config", rev = "bfaced6044ae570bf20d4528fa9aaafcc43ddeec" } +holofuel_types = "0.5.0" [dev-dependencies] configure-holochain = { path = "../configure-holochain"} diff --git a/crates/holo_happ_manager/src/hha_type.rs b/crates/holo_happ_manager/src/hha_type.rs index c1277296..e4187ce1 100644 --- a/crates/holo_happ_manager/src/hha_type.rs +++ b/crates/holo_happ_manager/src/hha_type.rs @@ -1,4 +1,5 @@ use holochain_types::prelude::{holochain_serial, SerializedBytes}; +use holofuel_types::fuel::Fuel; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] @@ -18,11 +19,11 @@ pub struct HappInput { #[serde(default)] pub description: String, #[serde(default)] - pub categories: Vec, // + pub categories: Vec, #[serde(default)] - pub jurisdictions: Vec, // + pub jurisdictions: Vec, #[serde(default)] - pub exclude_jurisdictions: bool, // + pub exclude_jurisdictions: bool, #[serde(default)] pub publisher_pricing_pref: PublisherPricingPref, #[serde(default)] @@ -31,22 +32,32 @@ pub struct HappInput { pub uid: Option, } +#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] +pub struct DnaResource { + pub hash: String, // hash of the dna, not a stored dht address + pub src_url: String, + pub nick: String, +} + #[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone, Default)] pub struct LoginConfig { pub display_publisher_name: bool, pub registration_info_url: Option, } -#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone, Default)] +#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] pub struct PublisherPricingPref { pub cpu: Fuel, pub storage: Fuel, pub bandwidth: Fuel, } -#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] -pub struct DnaResource { - pub hash: String, // hash of the dna, not a stored dht address - pub src_url: String, - pub nick: String, +impl Default for PublisherPricingPref { + fn default() -> Self { + Self { + cpu: Fuel::new(0), + storage: Fuel::new(0), + bandwidth: Fuel::new(0), + } + } } From c45afb47f4d523ba579c5e7c1ebe6245a33cb6fb Mon Sep 17 00:00:00 2001 From: zo-el Date: Mon, 30 Oct 2023 09:30:17 -0500 Subject: [PATCH 12/13] hha_type: crate --- Cargo.lock | 1 + .../src/hpos_holochain_api.rs | 1 - .../src/actions/get_happ_hosts.rs | 27 +---- .../src/actions/get_specific_happ_prefs.rs | 14 +-- .../src/actions/list_all_my_happs.rs | 44 +------ .../src/actions/set_happ_prefs.rs | 25 +--- crates/holo_happ_manager/src/get_my_apps.rs | 13 +- crates/holo_happ_manager/src/hha_type.rs | 63 ---------- crates/holo_happ_manager/src/lib.rs | 7 +- crates/holo_happ_manager/src/publish.rs | 6 +- crates/hpos_connect_hc/Cargo.toml | 3 +- crates/hpos_connect_hc/src/hha_types.rs | 114 ++++++++++++++++++ crates/hpos_connect_hc/src/lib.rs | 1 + 13 files changed, 139 insertions(+), 180 deletions(-) delete mode 100644 crates/holo_happ_manager/src/hha_type.rs create mode 100644 crates/hpos_connect_hc/src/hha_types.rs diff --git a/Cargo.lock b/Cargo.lock index c7c0c4b2..4fccda8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2769,6 +2769,7 @@ dependencies = [ "holochain_keystore", "holochain_types", "holochain_websocket", + "holofuel_types", "hpos-config-core", "hpos-config-seed-bundle-explorer", "isahc", diff --git a/crates/configure-holochain/src/hpos_holochain_api.rs b/crates/configure-holochain/src/hpos_holochain_api.rs index 7d073113..d15ce998 100644 --- a/crates/configure-holochain/src/hpos_holochain_api.rs +++ b/crates/configure-holochain/src/hpos_holochain_api.rs @@ -1,7 +1,6 @@ use anyhow::Result; use serde::Deserialize; use std::process::{Command, Output}; -use tracing::debug; #[derive(Debug, Deserialize)] struct HostingCriteria { diff --git a/crates/core_app_cli/src/actions/get_happ_hosts.rs b/crates/core_app_cli/src/actions/get_happ_hosts.rs index d694dfa1..94e7f506 100644 --- a/crates/core_app_cli/src/actions/get_happ_hosts.rs +++ b/crates/core_app_cli/src/actions/get_happ_hosts.rs @@ -1,29 +1,6 @@ use anyhow::Result; -use holochain_types::prelude::{ActionHashB64, AgentPubKeyB64, ExternIO, FunctionName, ZomeName}; -use holofuel_types::fuel::Fuel; -use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; -use serde::{Deserialize, Serialize}; -use std::time::Duration; - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct HappPreferences { - pub max_fuel_before_invoice: Fuel, - pub price_compute: Fuel, - pub price_storage: Fuel, - pub price_bandwidth: Fuel, - pub max_time_before_invoice: Duration, -} - -#[derive(Debug, Clone, Deserialize)] -pub struct HoloportId(pub String); - -#[derive(Debug, Clone, Deserialize)] -pub struct HoloportDetails { - pub host_pub_key: AgentPubKeyB64, - pub holoport_id: HoloportId, - pub preferences: Option, - pub preferences_hash: Option, -} +use holochain_types::prelude::{ExternIO, FunctionName, ZomeName}; +use hpos_hc_connect::{hha_types::HoloportDetails, CoreAppAgent, CoreAppRoleName}; pub async fn get(happ_id: String) -> Result<()> { let mut agent = CoreAppAgent::connect().await?; diff --git a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs index 62999a5d..e3829b11 100644 --- a/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/get_specific_happ_prefs.rs @@ -1,18 +1,6 @@ use anyhow::Result; use holochain_types::prelude::{ActionHash, ActionHashB64, ExternIO, FunctionName, ZomeName}; -use holofuel_types::fuel::Fuel; -use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; -use serde::{Deserialize, Serialize}; -use std::time::Duration; - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct HappPreferences { - pub max_fuel_before_invoice: Fuel, - pub price_compute: Fuel, - pub price_storage: Fuel, - pub price_bandwidth: Fuel, - pub max_time_before_invoice: Duration, -} +use hpos_hc_connect::{hha_types::HappPreferences, CoreAppAgent, CoreAppRoleName}; pub async fn get(pref_hash: String) -> Result<()> { let mut agent = CoreAppAgent::connect().await?; diff --git a/crates/core_app_cli/src/actions/list_all_my_happs.rs b/crates/core_app_cli/src/actions/list_all_my_happs.rs index 2a31373d..13ab682f 100644 --- a/crates/core_app_cli/src/actions/list_all_my_happs.rs +++ b/crates/core_app_cli/src/actions/list_all_my_happs.rs @@ -1,46 +1,6 @@ use anyhow::Result; -use holochain_types::prelude::{ - holochain_serial, ActionHashB64, AgentPubKeyB64, ExternIO, FunctionName, SerializedBytes, - ZomeName, -}; -use holofuel_types::fuel::Fuel; -use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Serialize, Deserialize, SerializedBytes)] -pub struct PresentedHappBundle { - pub id: ActionHashB64, - pub provider_pubkey: AgentPubKeyB64, - pub is_draft: bool, - pub is_paused: bool, - pub uid: Option, - pub bundle_url: String, - pub ui_src_url: Option, - // pub dnas: Vec, - pub hosted_urls: Vec, - pub name: String, - pub logo_url: Option, - pub description: String, - pub categories: Vec, - pub jurisdictions: Vec, - pub exclude_jurisdictions: bool, - pub publisher_pricing_pref: PublisherPricingPref, - pub login_config: LoginConfig, - pub special_installed_app_id: Option, -} - -#[derive(Debug, Serialize, Deserialize, SerializedBytes)] -pub struct PublisherPricingPref { - pub cpu: Fuel, - pub storage: Fuel, - pub bandwidth: Fuel, -} - -#[derive(Debug, Serialize, Deserialize, SerializedBytes)] -pub struct LoginConfig { - pub display_publisher_name: bool, - pub registration_info_url: Option, -} +use holochain_types::prelude::{ExternIO, FunctionName, ZomeName}; +use hpos_hc_connect::{hha_types::PresentedHappBundle, CoreAppAgent, CoreAppRoleName}; pub async fn get() -> Result<()> { let mut agent = CoreAppAgent::connect().await?; diff --git a/crates/core_app_cli/src/actions/set_happ_prefs.rs b/crates/core_app_cli/src/actions/set_happ_prefs.rs index 42af0d09..3b694a77 100644 --- a/crates/core_app_cli/src/actions/set_happ_prefs.rs +++ b/crates/core_app_cli/src/actions/set_happ_prefs.rs @@ -1,29 +1,12 @@ use anyhow::Result; use holochain_types::prelude::{ActionHashB64, ExternIO, FunctionName, ZomeName}; use holofuel_types::fuel::Fuel; -use hpos_hc_connect::{CoreAppAgent, CoreAppRoleName}; -use serde::{Deserialize, Serialize}; +use hpos_hc_connect::{ + hha_types::{HappPreferences, SetHappPreferencesInput}, + CoreAppAgent, CoreAppRoleName, +}; use std::{str::FromStr, time::Duration}; -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct HappPreferences { - pub max_fuel_before_invoice: Fuel, - pub price_compute: Fuel, - pub price_storage: Fuel, - pub price_bandwidth: Fuel, - pub max_time_before_invoice: Duration, -} - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct SetHappPreferencesInput { - pub happ_id: ActionHashB64, - pub max_fuel_before_invoice: Fuel, // how much holofuel to accumulate before sending invoice - pub price_compute: Fuel, - pub price_storage: Fuel, - pub price_bandwidth: Fuel, - pub max_time_before_invoice: Duration, // how much time to allow to pass before sending invoice even if fuel trigger not reached. -} - pub async fn get( happ_id: String, price_compute: String, diff --git a/crates/holo_happ_manager/src/get_my_apps.rs b/crates/holo_happ_manager/src/get_my_apps.rs index f31a06e1..54e8c0a4 100644 --- a/crates/holo_happ_manager/src/get_my_apps.rs +++ b/crates/holo_happ_manager/src/get_my_apps.rs @@ -1,18 +1,13 @@ use super::hha::HHAAgent; use anyhow::{anyhow, Result}; use holochain_conductor_api::AppResponse; -use holochain_types::prelude::ActionHashB64; use holochain_types::prelude::{ExternIO, FunctionName, ZomeName}; -use hpos_hc_connect::holo_config::{Config, Happ}; -use serde::Deserialize; +use hpos_hc_connect::{ + hha_types::PresentedHappBundle, + holo_config::{Config, Happ}, +}; use tracing::debug; -#[derive(Deserialize, Debug, Clone)] -pub struct PresentedHappBundle { - pub id: ActionHashB64, - pub bundle_url: String, -} - pub async fn published(core_happ: &Happ, config: &Config) -> Result> { let mut agent = HHAAgent::spawn(core_happ, config).await?; let response = agent diff --git a/crates/holo_happ_manager/src/hha_type.rs b/crates/holo_happ_manager/src/hha_type.rs deleted file mode 100644 index e4187ce1..00000000 --- a/crates/holo_happ_manager/src/hha_type.rs +++ /dev/null @@ -1,63 +0,0 @@ -use holochain_types::prelude::{holochain_serial, SerializedBytes}; -use holofuel_types::fuel::Fuel; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] -pub struct HappInput { - #[serde(default)] - pub hosted_urls: Vec, - pub bundle_url: String, - #[serde(default)] - pub ui_src_url: Option, - #[serde(default)] - pub special_installed_app_id: Option, - pub name: String, - #[serde(default)] - pub logo_url: Option, - #[serde(default)] - pub dnas: Vec, - #[serde(default)] - pub description: String, - #[serde(default)] - pub categories: Vec, - #[serde(default)] - pub jurisdictions: Vec, - #[serde(default)] - pub exclude_jurisdictions: bool, - #[serde(default)] - pub publisher_pricing_pref: PublisherPricingPref, - #[serde(default)] - pub login_config: LoginConfig, - #[serde(default)] // default Option is None - pub uid: Option, -} - -#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] -pub struct DnaResource { - pub hash: String, // hash of the dna, not a stored dht address - pub src_url: String, - pub nick: String, -} - -#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone, Default)] -pub struct LoginConfig { - pub display_publisher_name: bool, - pub registration_info_url: Option, -} - -#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] -pub struct PublisherPricingPref { - pub cpu: Fuel, - pub storage: Fuel, - pub bandwidth: Fuel, -} - -impl Default for PublisherPricingPref { - fn default() -> Self { - Self { - cpu: Fuel::new(0), - storage: Fuel::new(0), - bandwidth: Fuel::new(0), - } - } -} diff --git a/crates/holo_happ_manager/src/lib.rs b/crates/holo_happ_manager/src/lib.rs index 1e6f8333..3c19bcd1 100644 --- a/crates/holo_happ_manager/src/lib.rs +++ b/crates/holo_happ_manager/src/lib.rs @@ -3,11 +3,12 @@ use anyhow::{anyhow, Context, Result}; use hha::HHAAgent; use holochain_conductor_api::AppResponse; use holochain_types::prelude::{AgentPubKey, ExternIO, FunctionName, ZomeName}; -pub use hpos_hc_connect::holo_config::{Config, Happ, HappsFile}; +pub use hpos_hc_connect::{ + hha_types::HappInput, + holo_config::{Config, Happ, HappsFile}, +}; use serde::Serialize; use tracing::{debug, info}; -mod hha_type; -use hha_type::HappInput; mod publish; use std::{env, fs, path::PathBuf}; pub mod hha; diff --git a/crates/holo_happ_manager/src/publish.rs b/crates/holo_happ_manager/src/publish.rs index a5439887..092a5dfa 100644 --- a/crates/holo_happ_manager/src/publish.rs +++ b/crates/holo_happ_manager/src/publish.rs @@ -1,10 +1,12 @@ use super::hha::HHAAgent; -use super::hha_type::HappInput; use anyhow::{anyhow, Result}; use holochain_conductor_api::AppResponse; use holochain_types::prelude::ActionHashB64; use holochain_types::prelude::{ExternIO, FunctionName, ZomeName}; -use hpos_hc_connect::holo_config::{Config, Happ}; +use hpos_hc_connect::{ + hha_types::HappInput, + holo_config::{Config, Happ}, +}; use serde::Deserialize; use tracing::debug; diff --git a/crates/hpos_connect_hc/Cargo.toml b/crates/hpos_connect_hc/Cargo.toml index 464223b3..115beaba 100644 --- a/crates/hpos_connect_hc/Cargo.toml +++ b/crates/hpos_connect_hc/Cargo.toml @@ -31,4 +31,5 @@ getrandom = "0.2.7" holochain_client = "0.4.2" holochain_keystore = "0.2.2" sodoken = "0.0.9" -url2 = "0.0.6" \ No newline at end of file +url2 = "0.0.6" +holofuel_types = "0.5.0" diff --git a/crates/hpos_connect_hc/src/hha_types.rs b/crates/hpos_connect_hc/src/hha_types.rs new file mode 100644 index 00000000..3c640d43 --- /dev/null +++ b/crates/hpos_connect_hc/src/hha_types.rs @@ -0,0 +1,114 @@ +use holochain_types::prelude::{holochain_serial, ActionHashB64, AgentPubKeyB64, SerializedBytes}; +use holofuel_types::fuel::Fuel; +use serde::{Deserialize, Serialize}; +use std::time::Duration; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct HappPreferences { + pub max_fuel_before_invoice: Fuel, + pub price_compute: Fuel, + pub price_storage: Fuel, + pub price_bandwidth: Fuel, + pub max_time_before_invoice: Duration, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct SetHappPreferencesInput { + pub happ_id: ActionHashB64, + pub max_fuel_before_invoice: Fuel, // how much holofuel to accumulate before sending invoice + pub price_compute: Fuel, + pub price_storage: Fuel, + pub price_bandwidth: Fuel, + pub max_time_before_invoice: Duration, // how much time to allow to pass before sending invoice even if fuel trigger not reached. +} + +#[derive(Debug, Clone, Deserialize)] +pub struct HoloportId(pub String); + +#[derive(Debug, Clone, Deserialize)] +pub struct HoloportDetails { + pub host_pub_key: AgentPubKeyB64, + pub holoport_id: HoloportId, + pub preferences: Option, + pub preferences_hash: Option, +} +#[derive(Debug, Serialize, Deserialize, SerializedBytes)] +pub struct PresentedHappBundle { + pub id: ActionHashB64, + pub provider_pubkey: AgentPubKeyB64, + pub is_draft: bool, + pub is_paused: bool, + pub uid: Option, + pub bundle_url: String, + pub ui_src_url: Option, + // pub dnas: Vec, + pub hosted_urls: Vec, + pub name: String, + pub logo_url: Option, + pub description: String, + pub categories: Vec, + pub jurisdictions: Vec, + pub exclude_jurisdictions: bool, + pub publisher_pricing_pref: PublisherPricingPref, + pub login_config: LoginConfig, + pub special_installed_app_id: Option, +} + +#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] +pub struct PublisherPricingPref { + pub cpu: Fuel, + pub storage: Fuel, + pub bandwidth: Fuel, +} +impl Default for PublisherPricingPref { + fn default() -> Self { + Self { + cpu: Fuel::new(0), + storage: Fuel::new(0), + bandwidth: Fuel::new(0), + } + } +} + +#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone, Default)] +pub struct LoginConfig { + pub display_publisher_name: bool, + pub registration_info_url: Option, +} + +#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] +pub struct HappInput { + #[serde(default)] + pub hosted_urls: Vec, + pub bundle_url: String, + #[serde(default)] + pub ui_src_url: Option, + #[serde(default)] + pub special_installed_app_id: Option, + pub name: String, + #[serde(default)] + pub logo_url: Option, + #[serde(default)] + pub dnas: Vec, + #[serde(default)] + pub description: String, + #[serde(default)] + pub categories: Vec, + #[serde(default)] + pub jurisdictions: Vec, + #[serde(default)] + pub exclude_jurisdictions: bool, + #[serde(default)] + pub publisher_pricing_pref: PublisherPricingPref, + #[serde(default)] + pub login_config: LoginConfig, + #[serde(default)] // default Option is None + pub uid: Option, +} + +#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)] +pub struct DnaResource { + pub hash: String, // hash of the dna, not a stored dht address + pub src_url: String, + pub nick: String, +} diff --git a/crates/hpos_connect_hc/src/lib.rs b/crates/hpos_connect_hc/src/lib.rs index b1d79cb3..c26014ad 100644 --- a/crates/hpos_connect_hc/src/lib.rs +++ b/crates/hpos_connect_hc/src/lib.rs @@ -41,4 +41,5 @@ pub mod hpos_membrane_proof; pub use hf_agent::*; pub mod core_app_agent; pub use core_app_agent::*; +pub mod hha_types; pub mod holofuel_types; From a4cb673e630772674b4c97ad2df1003a604b6c61 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Mon, 30 Oct 2023 11:16:19 -0500 Subject: [PATCH 13/13] bump core-app & sl daas --- crates/configure-holochain/tests/config.yaml | 4 ++-- crates/holo_happ_manager/tests/config.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/configure-holochain/tests/config.yaml b/crates/configure-holochain/tests/config.yaml index 54c5d2e0..f854c8f1 100644 --- a/crates/configure-holochain/tests/config.yaml +++ b/crates/configure-holochain/tests/config.yaml @@ -3,11 +3,11 @@ [ { 'app_id': 'core-app', - 'bundle_url': 'https://holo-host.github.io/holo-hosting-app-rsm/releases/downloads/core-app/0_5_7/core-app.0_5_7-skip-proof.happ', + 'bundle_url': 'https://holo-host.github.io/holo-hosting-app-rsm/releases/downloads/core-app/0_5_18/core-app.0_5_18-skip-proof.happ', }, { 'app_id': 'servicelogger', - 'bundle_url': 'https://holo-host.github.io/servicelogger-rsm/releases/downloads/0_4_12/servicelogger.0_4_12.happ', + 'bundle_url': 'https://holo-host.github.io/servicelogger-rsm/releases/downloads/0_4_18/servicelogger.0_4_18.happ', }, ], 'self_hosted_happs': diff --git a/crates/holo_happ_manager/tests/config.yaml b/crates/holo_happ_manager/tests/config.yaml index 86539133..81de7d44 100644 --- a/crates/holo_happ_manager/tests/config.yaml +++ b/crates/holo_happ_manager/tests/config.yaml @@ -3,7 +3,7 @@ [ { 'app_id': 'core-app', - 'bundle_url': 'https://holo-host.github.io/holo-hosting-app-rsm/releases/downloads/core-app/0_5_7/core-app.0_5_7-skip-proof.happ', + 'bundle_url': 'https://holo-host.github.io/holo-hosting-app-rsm/releases/downloads/core-app/0_5_18/core-app.0_5_18-skip-proof.happ', } ], 'self_hosted_happs': [],