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

add new methods for core-app-cli #171

Merged
merged 13 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
62 changes: 61 additions & 1 deletion Cargo.lock

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

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
```
48 changes: 48 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,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: 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<HappPreferences>,
pub preferences_hash: Option<ActionHashB64>,
}

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(())
}
39 changes: 39 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,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: Fuel,
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 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(())
}
11 changes: 6 additions & 5 deletions crates/core_app_cli/src/actions/list_all_my_happs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -23,16 +24,16 @@ pub struct PresentedHappBundle {
pub categories: Vec<String>,
pub jurisdictions: Vec<String>,
pub exclude_jurisdictions: bool,
pub hosting_prices: HostingPrices,
pub publisher_pricing_pref: PublisherPricingPref,
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,
pub struct PublisherPricingPref {
pub cpu: Fuel,
pub storage: Fuel,
pub bandwidth: Fuel,
}

#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
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;
72 changes: 72 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,72 @@
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::{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,
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
Loading