Skip to content

Commit

Permalink
add new methods for core-app-cli (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: zo-el <[email protected]>
  • Loading branch information
JettTech and zo-el authored Oct 30, 2023
1 parent e1d1baa commit 1eb51b7
Show file tree
Hide file tree
Showing 20 changed files with 367 additions and 120 deletions.
63 changes: 62 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/configure-holochain/src/hpos_holochain_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use serde::Deserialize;
use std::process::{Command, Output};
use tracing::debug;

#[derive(Debug, Deserialize)]
struct HostingCriteria {
Expand Down
4 changes: 2 additions & 2 deletions crates/configure-holochain/tests/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
3 changes: 2 additions & 1 deletion crates/core_app_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core_app_cli"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["zo-el <[email protected]>"]

Expand All @@ -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"
16 changes: 10 additions & 6 deletions crates/core_app_cli/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# core_app_cli

```
core_app_cli 0.1.0
core_app_cli 0.1.1
USAGE:
core_app_cli <SUBCOMMAND>
Expand All @@ -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
```
25 changes: 25 additions & 0 deletions crates/core_app_cli/src/actions/get_happ_hosts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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) -> 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())?;

println!("===================");
println!("All Hosts for Happ ID {} are: ", happ_id);
println!("{:#?}", hosts);
println!("===================");

Ok(())
}
27 changes: 27 additions & 0 deletions crates/core_app_cli/src/actions/get_specific_happ_prefs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use anyhow::Result;
use holochain_types::prelude::{ActionHash, ActionHashB64, ExternIO, FunctionName, ZomeName};
use hpos_hc_connect::{hha_types::HappPreferences, CoreAppAgent, CoreAppRoleName};

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 hash = ActionHash::from(pref_holo_hash);

let result = agent
.zome_call(
CoreAppRoleName::HHA,
ZomeName::from("hha"),
FunctionName::from("get_specific_happ_preferences"),
ExternIO::encode(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(())
}
43 changes: 2 additions & 41 deletions crates/core_app_cli/src/actions/list_all_my_happs.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
use anyhow::Result;
use holochain_types::prelude::{
holochain_serial, ActionHashB64, AgentPubKeyB64, ExternIO, FunctionName, SerializedBytes,
ZomeName,
};
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<String>,
pub bundle_url: String,
pub ui_src_url: Option<String>,
// pub dnas: Vec<DnaResource>,
pub hosted_urls: Vec<String>,
pub name: String,
pub logo_url: Option<String>,
pub description: String,
pub categories: Vec<String>,
pub jurisdictions: Vec<String>,
pub exclude_jurisdictions: bool,
pub hosting_prices: HostingPrices,
pub login_config: LoginConfig,
pub special_installed_app_id: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
pub struct HostingPrices {
pub cpu: String,
pub storage: String,
pub bandwidth: String,
}

#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
pub struct LoginConfig {
pub display_publisher_name: bool,
pub registration_info_url: Option<String>,
}
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?;
Expand Down
3 changes: 3 additions & 0 deletions crates/core_app_cli/src/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
55 changes: 55 additions & 0 deletions crates/core_app_cli/src/actions/set_happ_prefs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use anyhow::Result;
use holochain_types::prelude::{ActionHashB64, ExternIO, FunctionName, ZomeName};
use holofuel_types::fuel::Fuel;
use hpos_hc_connect::{
hha_types::{HappPreferences, SetHappPreferencesInput},
CoreAppAgent, CoreAppRoleName,
};
use std::{str::FromStr, time::Duration};

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_sec: String,
max_time_before_invoice_ms: String,
) -> Result<()> {
let mut agent = CoreAppAgent::connect().await?;

let max_time_sec = max_time_before_invoice_sec
.parse::<u64>()
.expect("Failed to convert `max_time_before_invoice` seconds to U64.");

let max_time_ms = max_time_before_invoice_ms
.parse::<u32>()
.expect("Failed to convert `max_time_before_invoice` milliseconds to U32.");

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_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(())
}
Loading

0 comments on commit 1eb51b7

Please sign in to comment.