use std::{
path::{Path, PathBuf},
time::{SystemTime, UNIX_EPOCH},
};
use canic_core::{
cdk::types::Cycles,
ids::{
CyclesFundingBudget, FleetFundingProfile, FleetSubnetRootFundingAuthority,
FleetSubnetRootFundingPolicy,
},
};
pub fn fleet_subnet_root_funding_authority() -> FleetSubnetRootFundingAuthority {
FleetSubnetRootFundingAuthority {
root_funding: FleetSubnetRootFundingPolicy {
funding_profile: FleetFundingProfile::SingleSubnet,
request_threshold: Cycles::new(10_000_000_000_000),
target_balance: Cycles::new(30_000_000_000_000),
cooldown_secs: 30 * 24 * 60 * 60,
budget: CyclesFundingBudget {
window_secs: 90 * 24 * 60 * 60,
maximum_cycles: Cycles::new(30_000_000_000_000),
},
maximum_automatic_grants: 4,
maximum_automatic_cycles: Cycles::new(120_000_000_000_000),
},
icp_refill: None,
}
}
pub fn temp_dir(prefix: &str) -> PathBuf {
let unique = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time after epoch")
.as_nanos();
std::env::temp_dir().join(format!("{prefix}-{}-{unique}", std::process::id()))
}
#[cfg(unix)]
pub fn create_fifo(path: &Path) {
let status = std::process::Command::new("mkfifo")
.args(["-m", "600"])
.arg(path)
.status()
.expect("run mkfifo");
assert!(status.success(), "mkfifo failed with {status}");
}