Skip to content

Commit

Permalink
Simplify prize winner messages to reduce size (part 1) (#6449)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Sep 23, 2024
1 parent f16bd48 commit a56e5a7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions backend/libraries/chat_events/src/chat_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
41 changes: 25 additions & 16 deletions backend/libraries/chat_events/src/message_content_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,20 +661,6 @@ pub struct CryptoContentInternal {
pub caption: Option<String>,
}

impl From<CryptoContent> 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;

Expand Down Expand Up @@ -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")]
Expand All @@ -874,10 +879,14 @@ pub struct PrizeWinnerContentInternal {
pub prize_message: MessageIndex,
}

impl From<PrizeWinnerContent> for PrizeWinnerContentInternal {
fn from(value: PrizeWinnerContent) -> Self {
impl From<PrizeWinnerContentInternalPrevious> 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,
}
Expand Down

0 comments on commit a56e5a7

Please sign in to comment.