feat(escrow): add player-level balance history with historical snapshot queries (#953)#1015
Merged
famvilianity-eng merged 2 commits intoJul 1, 2026
Conversation
…ot queries Adds the ability to query historical escrow balances for a player via get_balance_at_timestamp(env, player, timestamp) -> i128. Player-level snapshots are recorded on every deposit, payout, cancel refund, and expire refund using a per-player ring buffer (MAX_PLAYER_SNAPSHOTS = 32) with a monotonic counter (PlayerBalanceSnapshotCount) so callers can detect pruned entries. Closes StellarCheckMate#953
|
@Osifowora Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements player-level historical balance queries for the escrow contract. Adds the ability to ask "what was player X's escrow balance at ledger N?" via
get_balance_at_timestamp, and records a snapshot on every balance-changing event.This closes issue #953:
Tasks from #953
DataKey::PlayerBalanceSnapshot(player, u64)andDataKey::PlayerBalanceSnapshotCount(player)to store per-player balance history.get_balance_at_timestamp(env, player, timestamp) -> i128which walks the per-player ring buffer newest-first and returns0when no snapshot is recorded at or beforetimestamp.deposit-> records for the depositing playersubmit_result-> records for both players (balance -> 0)cancel_match-> records for refunded depositors only (non-depositors had balance 0 and would not change)expire_match-> records for refunded depositors onlycontracts/escrow/src/tests/player_balance_history.rscovering no-history zeros, deposit cumulation, payout-zero, cancel-zero, expire-zero, multi-match cross-match timelines, pre-history queries returning 0, and ring-buffer-overwrite behavior.Implementation notes
DataKey::PlayerBalanceSnapshot(player, slot)whereslot = index % MAX_PLAYER_SNAPSHOTS(32).DataKey::PlayerBalanceSnapshotCount(player)tracks the monotonic counter soget_balance_at_timestampcan detect pruned entries and return0for queries before the surviving window.i128= sum ofstake_amountover every non-terminal match the player has deposited in. Identifies the depositing side viaplayer{1,2}_depositedflags.MAX_SNAPSHOTS_PER_MATCH), so behavior is consistent across both operational and analytical read paths.get_balance_at_timestampis read-only and unauthenticated - only an aggregate escrow total is exposed, no per-match stake amounts.(Symbol::new(env, "player"), symbol_short!("snapshot"), (player, index, balance))on each new snapshot, so off-chain indexers can stream player history easily.Files changed
contracts/escrow/src/lib.rs- added helpers, query function, hooks (+177 lines)contracts/escrow/src/types.rs- added 2 DataKey variants +PlayerBalanceSnapshotstruct (+37 lines)contracts/escrow/src/tests/player_balance_history.rs- new test module (8 tests)contracts/escrow/src/tests/mod.rs- registered the new module (+1)Closes #953