Skip to content

Commit

Permalink
Merge branch 'master' into edit-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs authored Jan 24, 2024
2 parents 226e9fe + fc05093 commit 455bfcb
Show file tree
Hide file tree
Showing 137 changed files with 1,276 additions and 966 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"backend/canisters/community/c2c_client",
"backend/canisters/community/impl",
"backend/canisters/cycles_dispenser/api",
"backend/canisters/cycles_dispenser/c2c_client",
"backend/canisters/cycles_dispenser/impl",
"backend/canisters/escrow/api",
"backend/canisters/escrow/c2c_client",
Expand Down
8 changes: 5 additions & 3 deletions backend/canister_installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ async fn install_service_canisters_impl(

let user_index_canister_wasm = get_canister_wasm(CanisterName::UserIndex, version);
let user_index_init_args = user_index_canister::init::Args {
service_principals: vec![principal],
governance_principals: vec![principal],
user_canister_wasm: CanisterWasm::default(),
local_user_index_canister_wasm: CanisterWasm::default(),
group_index_canister_id: canister_ids.group_index,
notifications_index_canister_id: canister_ids.notifications_index,
identity_canister_id: canister_ids.identity,
proposals_bot_canister_id: canister_ids.proposals_bot,
storage_index_canister_id: canister_ids.storage_index,
cycles_dispenser_canister_id: canister_ids.cycles_dispenser,
Expand All @@ -74,7 +75,7 @@ async fn install_service_canisters_impl(

let group_index_canister_wasm = get_canister_wasm(CanisterName::GroupIndex, version);
let group_index_init_args = group_index_canister::init::Args {
service_principals: vec![principal],
governance_principals: vec![principal],
group_canister_wasm: CanisterWasm::default(),
community_canister_wasm: CanisterWasm::default(),
local_group_index_canister_wasm: CanisterWasm::default(),
Expand All @@ -88,7 +89,7 @@ async fn install_service_canisters_impl(

let notifications_index_canister_wasm = get_canister_wasm(CanisterName::NotificationsIndex, version);
let notifications_index_init_args = notifications_index_canister::init::Args {
service_principals: vec![principal],
governance_principals: vec![principal],
push_service_principals: vec![principal],
user_index_canister_id: canister_ids.user_index,
authorizers: vec![canister_ids.user_index, canister_ids.group_index],
Expand All @@ -100,6 +101,7 @@ async fn install_service_canisters_impl(

let identity_canister_wasm = get_canister_wasm(CanisterName::Identity, version);
let identity_init_args = identity_canister::init::Args {
governance_principals: vec![principal],
user_index_canister_id: canister_ids.user_index,
cycles_dispenser_canister_id: canister_ids.cycles_dispenser,
wasm_version: version,
Expand Down
6 changes: 6 additions & 0 deletions backend/canisters/community/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

- Implement ability to update user principals ([#5220](https://github.com/open-chat-labs/open-chat/pull/5220))

## [[2.0.1021](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1021-community)] - 2024-01-24

### Changed

- Simplify timer jobs + make them more efficient ([#5233](https://github.com/open-chat-labs/open-chat/pull/5233))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use types::{UpdateUserPrincipalArgs, UpdateUserPrincipalResponse};

pub type Args = UpdateUserPrincipalArgs;
pub type Response = UpdateUserPrincipalResponse;
1 change: 1 addition & 0 deletions backend/canisters/community/api/src/updates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod c2c_set_user_suspended;
pub mod c2c_tip_message;
pub mod c2c_unfreeze_community;
pub mod c2c_update_proposals;
pub mod c2c_update_user_principal;
pub mod cancel_invites;
pub mod cancel_p2p_swap;
pub mod change_channel_role;
Expand Down
6 changes: 6 additions & 0 deletions backend/canisters/community/impl/src/model/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ impl CommunityMembers {
self.display_names_last_updated
}

pub fn update_user_principal(&mut self, old_principal: Principal, new_principal: Principal) {
if let Some(user_id) = self.principal_to_user_id_map.remove(&old_principal) {
self.principal_to_user_id_map.insert(new_principal, user_id);
}
}

pub fn mark_member_joined_channel(&mut self, user_id: &UserId, channel_id: ChannelId) {
if let Some(member) = self.members.get_mut(user_id) {
member.channels.insert(channel_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::guards::caller_is_user_index;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_tracing_macros::trace;
use community_canister::c2c_update_user_principal::*;

#[update_msgpack(guard = "caller_is_user_index")]
#[trace]
async fn c2c_update_user_principal(args: Args) -> Response {
run_regular_jobs();

mutate_state(|state| c2c_update_user_principal_impl(args, state))
}

fn c2c_update_user_principal_impl(args: Args, state: &mut RuntimeState) -> Response {
state
.data
.members
.update_user_principal(args.old_principal, args.new_principal);

Response::Success
}
1 change: 1 addition & 0 deletions backend/canisters/community/impl/src/updates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod c2c_set_user_suspended;
pub mod c2c_tip_message;
pub mod c2c_unfreeze_community;
pub mod c2c_update_proposals;
pub mod c2c_update_user_principal;
pub mod cancel_invites;
pub mod cancel_p2p_swap;
pub mod change_channel_role;
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/cycles_dispenser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Avoid usages of `make_c2c_call` and use macro instead ([#5252](https://github.com/open-chat-labs/open-chat/pull/5252))

## [[2.0.1017](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1017-cycles_dispenser)] - 2024-01-19

### Changed
Expand Down
15 changes: 15 additions & 0 deletions backend/canisters/cycles_dispenser/c2c_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "cycles_dispenser_canister_c2c_client"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
candid = { workspace = true }
canister_client = { path = "../../../libraries/canister_client" }
cycles_dispenser_canister = { path = "../api" }
ic-cdk = { workspace = true }
msgpack = { path = "../../../libraries/msgpack" }
tracing = { workspace = true }
types = { path = "../../../libraries/types" }
7 changes: 7 additions & 0 deletions backend/canisters/cycles_dispenser/c2c_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use canister_client::generate_candid_c2c_call;
use cycles_dispenser_canister::*;

// Queries

// Updates
generate_candid_c2c_call!(c2c_request_cycles);
2 changes: 2 additions & 0 deletions backend/canisters/cycles_dispenser/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ canister_logger = { path = "../../../libraries/canister_logger" }
canister_state_macros = { path = "../../../libraries/canister_state_macros" }
canister_tracing_macros = { path = "../../../libraries/canister_tracing_macros" }
cycles_dispenser_canister = { path = "../api" }
cycles_minting_canister = { path = "../../../external_canisters/cmc/api" }
cycles_minting_canister_c2c_client = { path = "../../../external_canisters/cmc/c2c_client" }
human_readable = { path = "../../../libraries/human_readable" }
ic-cdk = { workspace = true }
ic-cdk-timers = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use crate::{mutate_state, State};
use candid::CandidType;
use canister_client::make_c2c_call;
use ic_cdk::api::call::CallResult;
use ic_ledger_types::{AccountIdentifier, BlockIndex, Memo, Subaccount, Timestamp, Tokens, TransferArgs};
use serde::{Deserialize, Serialize};
use std::time::Duration;
use tracing::{error, info};
use types::{CanisterId, Cycles, TimestampMillis};
use types::{CanisterId, TimestampMillis};
use utils::canister_timers::run_now_then_interval;

const INTERVAL: Duration = Duration::from_secs(300);
Expand Down Expand Up @@ -107,15 +103,12 @@ async fn burn_icp(burn_details: BurnIcpDetails) {
}

async fn notify_cmc(notify_details: NotifyTopUpDetails) {
let response: CallResult<Result<Cycles, NotifyError>> = make_c2c_call(
let response = cycles_minting_canister_c2c_client::notify_top_up(
notify_details.cmc,
"notify_top_up",
&NotifyTopUpArgs {
&cycles_minting_canister::notify_top_up::Args {
block_index: notify_details.block_index,
canister_id: notify_details.this_canister_id,
},
candid::encode_one,
|r| candid::decode_one(r),
)
.await;

Expand All @@ -129,24 +122,3 @@ async fn notify_cmc(notify_details: NotifyTopUpDetails) {
}
}
}

#[derive(CandidType)]
struct NotifyTopUpArgs {
block_index: BlockIndex,
canister_id: CanisterId,
}

#[derive(Serialize, Deserialize, CandidType, Debug)]
enum NotifyError {
Refunded {
reason: String,
block_index: Option<BlockIndex>,
},
InvalidTransaction(String),
TransactionTooOld(BlockIndex),
Processing,
Other {
error_code: u64,
error_message: String,
},
}
6 changes: 6 additions & 0 deletions backend/canisters/escrow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

- Avoid usages of `make_c2c_call` and use macro instead ([#5252](https://github.com/open-chat-labs/open-chat/pull/5252))

## [[2.0.1020](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1020-escrow)] - 2024-01-24

### Changed

- Include `created_by` on `SwapStatusChange` messages ([#5230](https://github.com/open-chat-labs/open-chat/pull/5230))
- Simplify timer jobs + make them more efficient ([#5233](https://github.com/open-chat-labs/open-chat/pull/5233))

Expand Down
21 changes: 10 additions & 11 deletions backend/canisters/escrow/impl/src/jobs/notify_status_change.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{mutate_state, read_state, RuntimeState};
use canister_client::make_c2c_call;
use escrow_canister::SwapStatusChange;
use ic_cdk_timers::TimerId;
use std::cell::Cell;
Expand Down Expand Up @@ -55,19 +54,19 @@ fn get_next(state: &mut RuntimeState) -> Option<(CanisterId, SwapStatusChange)>
async fn notify_swap_status(canister_id: CanisterId, notification: SwapStatusChange) {
let swap_id = notification.swap_id;

if make_c2c_call(
canister_id,
"c2c_notify_p2p_swap_status_change_msgpack",
notification,
msgpack::serialize,
|r| msgpack::deserialize::<()>(r),
)
.await
.is_err()
{
if c2c_notify_p2p_swap_status_change(canister_id, &notification).await.is_err() {
mutate_state(|state| {
state.data.notify_status_change_queue.push(swap_id);
start_job_if_required(state);
});
}
}

canister_client::generate_c2c_call!(c2c_notify_p2p_swap_status_change);

mod c2c_notify_p2p_swap_status_change {
use super::*;

pub type Args = SwapStatusChange;
pub type Response = ();
}
3 changes: 0 additions & 3 deletions backend/canisters/escrow/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ impl RuntimeState {

#[derive(Serialize, Deserialize)]
struct Data {
#[serde(default)]
pub swaps: Swaps,
pub pending_payments_queue: PendingPaymentsQueue,
#[serde(default)]
pub notify_status_change_queue: NotifyStatusChangeQueue,
#[serde(default)]
timer_jobs: TimerJobs<TimerJob>,
pub cycles_dispenser_canister_id: CanisterId,
pub rng_seed: [u8; 32],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::VecDeque;

#[derive(Serialize, Deserialize, Default)]
pub struct NotifyStatusChangeQueue {
#[serde(default)]
swaps: VecDeque<u32>,
}

Expand Down
1 change: 0 additions & 1 deletion backend/canisters/escrow/impl/src/model/swaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub struct Swap {
pub token0_transfer_out: Option<CompletedCryptoTransaction>,
pub token1_transfer_out: Option<CompletedCryptoTransaction>,
pub refunds: Vec<CompletedCryptoTransaction>,
#[serde(default)]
pub additional_admins: Vec<Principal>,
pub canister_to_notify: Option<CanisterId>,
}
Expand Down
6 changes: 6 additions & 0 deletions backend/canisters/group/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

- Implement ability to update user principals ([#5220](https://github.com/open-chat-labs/open-chat/pull/5220))

## [[2.0.1022](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1022-group)] - 2024-01-24

### Changed

- Simplify timer jobs + make them more efficient ([#5233](https://github.com/open-chat-labs/open-chat/pull/5233))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};
use types::{UpdateUserPrincipalArgs, UpdateUserPrincipalResponse};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub old_principal: Principal,
pub new_principal: Principal,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success,
UserNotFound,
}
pub type Args = UpdateUserPrincipalArgs;
pub type Response = UpdateUserPrincipalResponse;
Loading

0 comments on commit 455bfcb

Please sign in to comment.