feat(scout_access): optional cross-contract player validation on pay_to_contact#1
Merged
Merged
Conversation
…to_contact
- Add ScoutAccessError::PlayerNotFound = 13
- Add DataKey::RegistrationContract to types
- Add set_registration_contract(env, addr) admin function that stores the
registration contract address in DataKey::RegistrationContract
- In pay_to_contact: when RegistrationContract is set, call
registration_contract::Client::try_get_player before collecting any fee;
return PlayerNotFound and abort if the lookup fails; skip validation
entirely when the address is not configured (preserves existing behaviour)
- Add mod registration_contract { contractimport!(...) } for the cross-
contract client (mirrors the existing progress_contract pattern)
- Add missing PERSISTENT_TTL_MIN / PERSISTENT_TTL_MAX constants and
mod progress_contract { contractimport!(...) } that were referenced but
never declared in the original file
- Add scoutchain-registration as a dev-dependency so tests can register
the contract directly with env.register_contract
- Add two unit tests:
test_pay_to_contact_without_registration_contract_skips_validation
test_pay_to_contact_with_registration_contract_rejects_unknown_player
- Fix CI: move WASM build step before cargo test because contractimport!
reads the WASM at compile time
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
Adds an optional cross-contract player existence check to
pay_to_contact. When the registration contract address is configured via the newset_registration_contractadmin function, the scout access contract validates that the targetplayer_idexists before collecting any fee or creating a contact record. When the address is not set the existing behaviour is fully preserved.Changes
contracts/scout_access/src/errors.rsPlayerNotFound = 13toScoutAccessErrorcontracts/scout_access/src/types.rsDataKey::RegistrationContractvariantcontracts/scout_access/src/lib.rsPERSISTENT_TTL_MIN/PERSISTENT_TTL_MAXconstants (were referenced but never declared — pre-existing bug fixed)mod progress_contract { contractimport!(...) }(same pre-existing missing declaration fixed)mod registration_contract { contractimport!(...) }for the new cross-contract clientset_registration_contract(env, addr)admin function — stores the registration contract address inDataKey::RegistrationContract(admin auth required)pay_to_contact: after the duplicate-contact guard, optionally callsregistration_contract::Client::try_get_player(&player_id); returnsPlayerNotFoundand aborts before any XLM transfer if the lookup fails; skips the check entirely when no address is storedtest_pay_to_contact_without_registration_contract_skips_validation— no registration contract set; contact with a non-existent player_id succeedstest_pay_to_contact_with_registration_contract_rejects_unknown_player— registration contract wired; contact with a non-existent player_id panics withPlayerNotFoundcontracts/scout_access/Cargo.tomlscoutchain-registration = { path = "../registration" }as a dev-dependency so tests can register the contract directly viaenv.register_contract.github/workflows/contract-ci.ymlcargo test—contractimport!reads the WASM at compile time so tests cannot compile without the artefacts presentValidation logic
Testing
test_pay_to_contact_without_registration_contract_skips_validationtest_pay_to_contact_with_registration_contract_rejects_unknown_playerAll existing tests are unaffected — no production logic outside
pay_to_contactwas changed.