Skip to content

feat: Sync player level updates from progress contract#198

Merged
Petah1 merged 2 commits into
scout-off:mainfrom
gracious01-tech:feat/player-level-sync
Jun 1, 2026
Merged

feat: Sync player level updates from progress contract#198
Petah1 merged 2 commits into
scout-off:mainfrom
gracious01-tech:feat/player-level-sync

Conversation

@gracious01-tech
Copy link
Copy Markdown

Description

Implemented external player level synchronization for the registration contract to ensure PlayerProfile.updated_at remains accurate when player progression is updated outside of update_profile.

Previously, when the progress contract advanced a player's level, the registration contract's updated_at field remained stale because it was only refreshed during profile updates.

This PR introduces a secure synchronization flow between the progress contract and registration contract.


Related Issue

Closes #27


Type of Change

  • New feature
  • Smart contract synchronization improvement
  • Authorization enhancement
  • Bug fix
  • Refactor
  • Documentation

Changes Included

  • Added set_player_level(env, player_id, level) function
  • Added DataKey::ProgressContract
  • Added admin-only set_progress_contract(env, addr) function
  • Restricted level synchronization calls to the configured progress contract
  • Updated player level and updated_at atomically
  • Added player_level_synced event emission
  • Added authorization and synchronization unit tests

Problem Solved

Previously:

  • updated_at only changed during update_profile
  • External level changes left registration metadata stale
  • Player profile timestamps became inaccurate

This PR ensures external progression updates correctly synchronize registration state.


Security Impact

  • Added authorization enforcement for progress contract calls
  • Prevents unauthorized external level mutations
  • Improves consistency between contracts

No payment or admin ownership logic changed beyond authorized configuration updates.


Testing

  • Added unit tests for authorized synchronization
  • Added tests rejecting unauthorized callers
  • Verified updated_at refreshes correctly
  • Verified level updates persist successfully
  • Verified player_level_synced event emission
  • Existing tests remain green

Manual Testing Steps

  • Configured progress contract address
  • Called set_player_level from authorized progress contract
  • Verified:
    • player level updates successfully
    • updated_at timestamp refreshes
    • sync event emits correctly
  • Attempted unauthorized call
  • Verified transaction is rejected

Acceptance Criteria Coverage

  • set_player_level updates both level and updated_at
  • Unauthorized callers are rejected
  • Unit tests mock progress contract and verify updates

Breaking Changes

No breaking changes.

Adds optional synchronization support between contracts.


Checklist

  • Code builds successfully
  • Tests pass
  • Follows project conventions
  • No sensitive data exposed
  • Existing functionality preserved

Additional Context

This synchronization mechanism improves data consistency across the ecosystem by ensuring profile metadata accurately reflects externally-driven progression updates.

The implementation keeps contract coupling minimal by using a configurable authorized progress contract address.


Reviewer Notes

Please focus on:

  • Authorization correctness for progress contract calls
  • Proper timestamp refresh behavior
  • Event emission consistency
  • Cross-contract synchronization safety
  • Backward compatibility with existing profile flows

- Add DataKey::ProgressContract to registration types
- Add set_progress_contract(env, addr) admin function — stores the
  progress contract address in DataKey::ProgressContract
- Add set_player_level(env, player_id, level) — only callable by the
  registered progress contract address (require_auth enforced); updates
  profile.level and profile.updated_at, emits player_level_synced event;
  returns Unauthorized when no progress contract is configured
- Add player_level_synced event to events.rs
- Add three unit tests:
    test_set_player_level_updates_level_and_timestamp
    test_set_player_level_emits_event
    test_set_player_level_rejects_unauthorized_caller
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

@gracious01-tech 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! 🚀

Learn more about application limits

@Petah1 Petah1 merged commit 24dccd7 into scout-off:main Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PlayerProfile.updated_at is not refreshed when level changes externally

2 participants