Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jedna committed Sep 19, 2024
1 parent 770c77e commit 866cc90
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
7 changes: 2 additions & 5 deletions canfund-rs/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ impl FundManager {
&maybe_funding_canister_record
.as_ref()
.and_then(|record| record.get_previous_cycles().clone()),
// pass in the strategy from maybe_funding_canister_record if it is not None,
// otherwise use the global strategy
&maybe_funding_canister_record
&maybe_funding_canister_record
.as_ref()
.and_then(|record| record.get_strategy().clone())
.unwrap_or_else(|| manager.borrow().options.strategy().clone()),
Expand Down Expand Up @@ -389,8 +387,7 @@ impl FundManager {
let needed_cycles = calc_needed_cycles(
&canister_record.get_cycles().clone().unwrap_or_default(),
canister_record.get_previous_cycles(),
// use canister record strategy if it is not None, otherwise use the global strategy
&canister_record
canister_record
.get_strategy()
.as_ref()
.unwrap_or_else(|| options.strategy()),
Expand Down
5 changes: 4 additions & 1 deletion canfund-rs/src/manager/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ pub struct CanisterRecord {
}

impl CanisterRecord {
pub fn new(cycles_fetcher: Arc<dyn FetchCyclesBalance>, strategy: Option<FundStrategy>) -> Self {
pub fn new(
cycles_fetcher: Arc<dyn FetchCyclesBalance>,
strategy: Option<FundStrategy>,
) -> Self {
Self {
cycles: None,
previous_cycles: None,
Expand Down
17 changes: 10 additions & 7 deletions examples/advanced_funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use candid::{self, CandidType, Deserialize, Principal};
use canfund::{
api::{cmc::IcCyclesMintingCanister, ledger::IcLedgerCanister},
manager::{
options::{CyclesThreshold, EstimatedRuntime, FundManagerOptions, FundStrategy, ObtainCyclesOptions},
options::{
CyclesThreshold, EstimatedRuntime, FundManagerOptions, FundStrategy,
ObtainCyclesOptions,
},
RegisterOpts,
},
operations::{fetch::FetchCyclesBalanceFromCanisterStatus, obtain::MintCycles},
Expand Down Expand Up @@ -86,12 +89,12 @@ pub fn start_canister_cycles_monitoring(config: FundingConfig) {
fund_manager.register(
id(),
RegisterOpts::new()
.with_cycles_fetcher(Arc::new(FetchCyclesBalanceFromCanisterStatus))
.with_strategy(FundStrategy::BelowThreshold(
CyclesThreshold::new()
.with_min_cycles(125_000_000_000)
.with_fund_cycles(750_000_000_000),
)),
.with_cycles_fetcher(Arc::new(FetchCyclesBalanceFromCanisterStatus))
.with_strategy(FundStrategy::BelowThreshold(
CyclesThreshold::new()
.with_min_cycles(125_000_000_000)
.with_fund_cycles(750_000_000_000),
)),
);

fund_manager.start();
Expand Down

0 comments on commit 866cc90

Please sign in to comment.