Skip to content

Commit

Permalink
Merge branch 'feature-add-agent-pref-endpoint' of github.com:Holo-Hos…
Browse files Browse the repository at this point in the history
…t/hpos-service-crates into feature-add-agent-pref-endpoint
  • Loading branch information
JettTech committed Sep 24, 2024
2 parents af309d0 + c9d8da2 commit d11d1d1
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 10 deletions.
26 changes: 17 additions & 9 deletions crates/core_app_cli/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# core_app_cli

>Note: In holoports, this command can be used with the command: `holo-host <SUBCOMMAND>`
```
core_app_cli 0.1.1
Expand All @@ -11,13 +13,19 @@ FLAGS:
-V, --version Prints version information
SUBCOMMANDS:
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
all-happs List all happs registered in hha
b Gets your balance, fees, promised and available Fuel
enable-happ Enable hosting for a specific happ
help Prints this message or the help of the given subcommand(s)
host-prefs Fetch the happ preference hash for a specific host for a specific happ
hosts List all hosts for a happ by `happ_id``
jurisdiction List the jurisdiction for the provided agent
my-happs List all happs published by me
pay Pay your first pending invoice
pr Gets profile details
pref-details Fetch the happ preferences associated with a happ preference hash
publisher-happs List all happs by provided publisher
set-prefs Set new happ preferences
tx Gets the list of all your transactions
```

1 change: 1 addition & 0 deletions crates/core_app_cli/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pub mod pay_invoices;
pub mod profile;
pub mod register_happ;
pub mod set_host_happ_prefs;
pub mod summary;
70 changes: 70 additions & 0 deletions crates/core_app_cli/src/actions/summary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use anyhow::Result;
use holochain_types::dna::AgentPubKey;
use holochain_types::prelude::{FunctionName, ZomeName};
use hpos_hc_connect::app_connection::CoreAppRoleName;
use hpos_hc_connect::hha_agent::CoreAppAgent;
use hpos_hc_connect::holofuel_types::MigrationCloseStateV1Handler;

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

let summary: MigrationCloseStateV1Handler = agent
.app
.zome_call_typed(
CoreAppRoleName::Holofuel.into(),
ZomeName::from("transactor"),
FunctionName::from("get_my_summary"),
(),
)
.await?;

display(summary);
Ok(())
}

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

let summary: MigrationCloseStateV1Handler = agent
.app
.zome_call_typed(
CoreAppRoleName::Holofuel.into(),
ZomeName::from("transactor"),
FunctionName::from("get_agent_summary"),
pub_key,
)
.await?;
display(summary);
Ok(())
}

fn display(summary: MigrationCloseStateV1Handler) {
println!("===================");
println!("Your Summary: ");
println!("multi_sig_authorizer: {:?}", summary.multi_sig_authorizer);
println!("reserve_setting: {:?}", summary.reserve_setting);
println!("reserve_sale_price: {:?}", summary.reserve_sale_price);
println!("tx_parked_links: {:?}", summary.tx_parked_links);
println!("cs_txs: {:?}", summary.cs_txs);
println!(
"incomplete_invoice_txs: {:?}",
summary.incomplete_invoice_txs
);
println!(
"incomplete_promise_txs: {:?}",
summary.incomplete_promise_txs
);
println!("Number of cs tx: {:?}", summary.cs_txs.len());
println!(
"Number of incomplete invoice: {:?}",
summary.incomplete_invoice_txs.len()
);
println!(
"Number of incomplete promises: {:?}",
summary.incomplete_promise_txs.len()
);
println!("Number of declined: {:?}", summary.number_of_declined);
println!("opening_balance: {:?}", summary.opening_balance);
println!("closing_balance: {:?}", summary.closing_balance);
println!("===================");
}
13 changes: 13 additions & 0 deletions crates/core_app_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use holochain_types::dna::AgentPubKeyB64;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -71,6 +72,12 @@ pub enum Opt {
#[structopt(name = "max-time-ms")]
max_time_before_invoice_ms: String,
},
/// Get My Summary
#[structopt(name = "gms")]
GetMySummary,
/// Get Summary by providing an agent public key
#[structopt(name = "gas")]
GetAgentSummary { pub_key: String },
}
impl Opt {
/// Run this command
Expand Down Expand Up @@ -129,6 +136,12 @@ impl Opt {
)
.await?
}
Opt::GetMySummary => core_app_cli::summary::get_my_summary().await?,
Opt::GetAgentSummary { pub_key } => {
let pub_key = AgentPubKeyB64::from_b64_str(&pub_key)
.expect("Failed to serialize string into AgentPubKey");
core_app_cli::summary::get_agent_summary(pub_key.into()).await?
}
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions crates/holofuel_cli/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod ledger;
pub mod pending;
pub mod profile;
pub mod reserve;
pub mod summary;
70 changes: 70 additions & 0 deletions crates/holofuel_cli/src/actions/summary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use anyhow::Result;
use holochain_types::dna::AgentPubKey;
use holochain_types::prelude::{FunctionName, ZomeName};
use hpos_hc_connect::app_connection::CoreAppRoleName;
use hpos_hc_connect::hf_agent::HfAgent;
use hpos_hc_connect::holofuel_types::MigrationCloseStateV1Handler;

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

let summary: MigrationCloseStateV1Handler = agent
.app
.zome_call_typed(
CoreAppRoleName::Holofuel.into(),
ZomeName::from("transactor"),
FunctionName::from("get_my_summary"),
(),
)
.await?;

display(summary);
Ok(())
}

pub async fn get_agent_summary(pub_key: AgentPubKey) -> Result<()> {
let mut agent = HfAgent::spawn(None).await?;

let summary: MigrationCloseStateV1Handler = agent
.app
.zome_call_typed(
CoreAppRoleName::Holofuel.into(),
ZomeName::from("transactor"),
FunctionName::from("get_agent_summary"),
pub_key,
)
.await?;
display(summary);
Ok(())
}

fn display(summary: MigrationCloseStateV1Handler) {
println!("===================");
println!("Your Summary: ");
println!("multi_sig_authorizer: {:?}", summary.multi_sig_authorizer);
println!("reserve_setting: {:?}", summary.reserve_setting);
println!("reserve_sale_price: {:?}", summary.reserve_sale_price);
println!("tx_parked_links: {:?}", summary.tx_parked_links);
println!("cs_txs: {:?}", summary.cs_txs);
println!(
"incomplete_invoice_txs: {:?}",
summary.incomplete_invoice_txs
);
println!(
"incomplete_promise_txs: {:?}",
summary.incomplete_promise_txs
);
println!("Number of cs tx: {:?}", summary.cs_txs.len());
println!(
"Number of incomplete invoice: {:?}",
summary.incomplete_invoice_txs.len()
);
println!(
"Number of incomplete promises: {:?}",
summary.incomplete_promise_txs.len()
);
println!("Number of declined: {:?}", summary.number_of_declined);
println!("opening_balance: {:?}", summary.opening_balance);
println!("closing_balance: {:?}", summary.closing_balance);
println!("===================");
}
14 changes: 14 additions & 0 deletions crates/holofuel_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use holochain_types::dna::AgentPubKeyB64;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand All @@ -24,7 +25,14 @@ pub enum Opt {
/// Get this reserve accounts sales price
#[structopt(name = "rsp")]
ReserveSalePrice,
/// Get My Summary
#[structopt(name = "gms")]
GetMySummary,
/// Get Summary by providing an agent public key
#[structopt(name = "gas")]
GetAgentSummary { pub_key: String },
}

impl Opt {
/// Run this command
pub async fn run(self) -> Result<()> {
Expand All @@ -36,6 +44,12 @@ impl Opt {
Opt::Profile => hf::actions::profile::get().await?,
Opt::ReserveSetting => hf::actions::reserve::get_setting().await?,
Opt::ReserveSalePrice => hf::actions::reserve::get_sale_price().await?,
Opt::GetMySummary => hf::actions::summary::get_my_summary().await?,
Opt::GetAgentSummary { pub_key } => {
let pub_key = AgentPubKeyB64::from_b64_str(&pub_key)
.expect("Failed to serialize string into AgentPubKey");
hf::actions::summary::get_agent_summary(pub_key.into()).await?
}
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hpos_connect_hc/src/hf_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl HfAgent {
let app_file = HappsFile::load_happ_file_from_env(config)?;
let holofuel = app_file
.holofuel()
.ok_or(anyhow!("There's no core-app defined in a happs file"))?;
.ok_or(anyhow!("There's no holofuel app defined in a happs file"))?;

// connect to lair
let passphrase = sodoken::BufRead::from(default_password()?.as_bytes().to_vec());
Expand Down
Loading

0 comments on commit d11d1d1

Please sign in to comment.