Skip to content

Commit

Permalink
Transfer balance from old Diamond membership payments to treasury (#5307
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hpeebles authored Feb 1, 2024
1 parent 4eb5af9 commit e6ed02d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
6 changes: 6 additions & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Added

- Transfer balance from old Diamond membership payments to treasury ([#5307](https://github.com/open-chat-labs/open-chat/pull/5307))

## [[2.0.1039](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1039-user_index)] - 2024-02-01

### Changed

- Reduce size of user data when serialized ([#5289](https://github.com/open-chat-labs/open-chat/pull/5289))
Expand Down
31 changes: 15 additions & 16 deletions backend/canisters/user_index/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::lifecycle::{init_env, init_state};
use crate::memory::get_upgrades_memory;
use crate::model::pending_payments_queue::{PendingPayment, PendingPaymentReason};
use crate::{mutate_state, Data};
use canister_logger::LogEntry;
use canister_tracing_macros::trace;
use ic_cdk_macros::post_upgrade;
use itertools::Itertools;
use icrc_ledger_types::icrc1::account::Account;
use rand::Rng;
use stable_memory::get_reader;
use tracing::info;
use types::Cryptocurrency;
use user_index_canister::post_upgrade::Args;
use utils::consts::SNS_GOVERNANCE_CANISTER_ID;
use utils::cycles::init_cycles_dispenser_client;

#[post_upgrade]
Expand Down Expand Up @@ -38,20 +42,15 @@ fn post_upgrade(args: Args) {
crate::jobs::sync_legacy_user_principals::start_job_if_required(state);
}

let users_whose_payments_failed: Vec<_> = state
.data
.users
.iter()
.filter(|u| u.diamond_membership_details.payment_in_progress())
.map(|u| u.user_id)
.collect();

for user_id in users_whose_payments_failed.iter() {
if let Some(membership) = state.data.users.diamond_membership_details_mut(user_id) {
membership.set_payment_in_progress(false);
}
}

info!(users_whose_payments_failed = ?users_whose_payments_failed.into_iter().map(|u| u.to_string()).collect_vec());
// Transfer previously raised funds to the treasury
state.data.pending_payments_queue.push(PendingPayment {
amount: 365285570000,
currency: Cryptocurrency::InternetComputer,
timestamp: state.env.now_nanos(),
recipient_account: Account::from(SNS_GOVERNANCE_CANISTER_ID),
memo: state.env.rng().gen(),
reason: PendingPaymentReason::Treasury,
});
crate::jobs::make_pending_payments::start_job_if_required(state);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ pub struct DiamondMembershipDetailsInternal {
pay_in_chat: bool,
#[serde(rename = "s", alias = "subscription", default, skip_serializing_if = "is_default")]
subscription: DiamondMembershipSubscription,
// Post release - reinstate `skip`
// #[serde(skip)]
#[serde(skip)]
payment_in_progress: bool,
}

Expand Down

0 comments on commit e6ed02d

Please sign in to comment.