From a56e5a7e871a6847e9a19b964976af61f33ff7d0 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Mon, 23 Sep 2024 17:39:02 +0100 Subject: [PATCH] Simplify prize winner messages to reduce size (part 1) (#6449) --- backend/canisters/community/CHANGELOG.md | 1 + backend/canisters/group/CHANGELOG.md | 1 + .../canisters/local_user_index/CHANGELOG.md | 1 + .../libraries/chat_events/src/chat_events.rs | 4 ++ .../src/message_content_internal.rs | 41 +++++++++++-------- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/backend/canisters/community/CHANGELOG.md b/backend/canisters/community/CHANGELOG.md index 234ae6244f..03e6fe4b6f 100644 --- a/backend/canisters/community/CHANGELOG.md +++ b/backend/canisters/community/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Increase max stable memory read / write buffer size ([#6440](https://github.com/open-chat-labs/open-chat/pull/6440)) +- Simplify prize winner messages to reduce size (part 1) ([#6449](https://github.com/open-chat-labs/open-chat/pull/6449)) ## [[2.0.1351](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1351-community)] - 2024-09-20 diff --git a/backend/canisters/group/CHANGELOG.md b/backend/canisters/group/CHANGELOG.md index 29058ee2ce..9713b21566 100644 --- a/backend/canisters/group/CHANGELOG.md +++ b/backend/canisters/group/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Increase max stable memory read / write buffer size ([#6440](https://github.com/open-chat-labs/open-chat/pull/6440)) +- Simplify prize winner messages to reduce size (part 1) ([#6449](https://github.com/open-chat-labs/open-chat/pull/6449)) ## [[2.0.1352](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1352-group)] - 2024-09-20 diff --git a/backend/canisters/local_user_index/CHANGELOG.md b/backend/canisters/local_user_index/CHANGELOG.md index 9fc20c6a31..0e28c5cdf3 100644 --- a/backend/canisters/local_user_index/CHANGELOG.md +++ b/backend/canisters/local_user_index/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Increase max stable memory read / write buffer size ([#6440](https://github.com/open-chat-labs/open-chat/pull/6440)) +- Simplify prize winner messages to reduce size (part 1) ([#6449](https://github.com/open-chat-labs/open-chat/pull/6449)) ## [[2.0.1353](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1353-local_user_index)] - 2024-09-20 diff --git a/backend/libraries/chat_events/src/chat_events.rs b/backend/libraries/chat_events/src/chat_events.rs index 31cc26b4fd..03528c894a 100644 --- a/backend/libraries/chat_events/src/chat_events.rs +++ b/backend/libraries/chat_events/src/chat_events.rs @@ -791,6 +791,10 @@ impl ChatEvents { message_id: rng.gen(), content: MessageContentInternal::PrizeWinner(PrizeWinnerContentInternal { winner, + ledger: transaction.ledger_canister_id(), + amount: transaction.units(), + fee: transaction.fee(), + block_index: transaction.index(), transaction, prize_message: message_index, }), diff --git a/backend/libraries/chat_events/src/message_content_internal.rs b/backend/libraries/chat_events/src/message_content_internal.rs index 86aeb7589a..14f1c10632 100644 --- a/backend/libraries/chat_events/src/message_content_internal.rs +++ b/backend/libraries/chat_events/src/message_content_internal.rs @@ -661,20 +661,6 @@ pub struct CryptoContentInternal { pub caption: Option, } -impl From for CryptoContentInternal { - fn from(value: CryptoContent) -> Self { - if let CryptoTransaction::Completed(transfer) = value.transfer { - CryptoContentInternal { - recipient: value.recipient, - transfer, - caption: value.caption, - } - } else { - panic!("Unable to convert from CryptoContent to CryptoContentInternal") - } - } -} - impl MessageContentInternalSubtype for CryptoContentInternal { type ContentType = CryptoContent; @@ -865,7 +851,26 @@ impl MessageContentInternalSubtype for PrizeContentInternal { } #[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(from = "PrizeWinnerContentInternalPrevious")] pub struct PrizeWinnerContentInternal { + #[serde(rename = "w")] + pub winner: UserId, + #[serde(rename = "l")] + pub ledger: CanisterId, + #[serde(rename = "a")] + pub amount: u128, + #[serde(rename = "f")] + pub fee: u128, + #[serde(rename = "i")] + pub block_index: u64, + #[serde(rename = "t")] + pub transaction: CompletedCryptoTransaction, + #[serde(rename = "m")] + pub prize_message: MessageIndex, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct PrizeWinnerContentInternalPrevious { #[serde(rename = "w")] pub winner: UserId, #[serde(rename = "t")] @@ -874,10 +879,14 @@ pub struct PrizeWinnerContentInternal { pub prize_message: MessageIndex, } -impl From for PrizeWinnerContentInternal { - fn from(value: PrizeWinnerContent) -> Self { +impl From for PrizeWinnerContentInternal { + fn from(value: PrizeWinnerContentInternalPrevious) -> Self { PrizeWinnerContentInternal { winner: value.winner, + ledger: value.transaction.ledger_canister_id(), + amount: value.transaction.units(), + fee: value.transaction.fee(), + block_index: value.transaction.index(), transaction: value.transaction, prize_message: value.prize_message, }