-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new methods for core-app-cli (#171)
Co-authored-by: zo-el <[email protected]>
- Loading branch information
Showing
20 changed files
with
367 additions
and
120 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]>"] | ||
|
||
|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
crates/core_app_cli/src/actions/get_specific_happ_prefs.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
Oops, something went wrong.