feat: add get_contract_config single-read configuration snapshot#133
Merged
mikewheeleer merged 1 commit intoJun 29, 2026
Merged
Conversation
Add ContractConfig #[contracttype] carrying all nine global settings and a get_contract_config(env) read that returns them in one call. Each field is populated by calling the existing per-field getter, so defaults and storage keys cannot drift. The getter is a pure read with no require_auth and no pause gate, consistent with the other read-only entrypoints. Add ten tests covering: fresh-contract defaults, field-by-field getter agreement after config changes, pause/allowlist/strict-registration toggles, per-call bounds and rate-limit window, readability while paused, admin=None before init, admin reflection after rotation, and idempotency. Document the snapshot in README.md.
Contributor
|
thanks for the effort @Tijesunimi004! 🙏 i can't tie this to an issue assigned to you, and we merge from the assigned contributor to keep the campaign fair. please claim an open unassigned issue first, then open your PR. closing for now — hope to see it back 🙌 |
Contributor
|
good stuff — thanks for picking it up 🙌 |
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.
What
Add a
ContractConfigstruct and aget_contract_config(env)read entrypoint that returns all nine global settings in a single call, resolving issue #111.Why
Fetching the contract's global state currently requires nine separate ledger reads (
is_paused,is_allowlist_enabled,is_service_registration_required,get_max_requests_per_call,get_min_requests_per_call,get_max_requests_per_window,get_rate_window_seconds,get_schema_version,get_admin). These reads can be inconsistent across ledgers when the contract state changes between calls. A dashboard or health check panel now works with one call instead of nine.Implementation
ContractConfigis a#[contracttype]struct with nine fields, each field carrying the same default as the corresponding per-field getter when the storage slot is absent.get_contract_configis implemented by calling the nine existing getters internally viaSelf::getter(env.clone()), so the defaults and storage key logic cannot drift.require_auth, no pause gate. It is callable beforeinit(returnsadmin: None) and while paused.Tests
Ten new tests in
contracts/escrow/src/test.rs:test_get_contract_config_defaults_on_fresh_contract— all fields at their defaults afterinittest_get_contract_config_matches_individual_getters— every field equals its per-field getter after config changestest_get_contract_config_reflects_pause_toggle— pause/unpause reflectedtest_get_contract_config_reflects_allowlist_toggle— allowlist toggle reflectedtest_get_contract_config_reflects_strict_registration_toggle— strict-registration toggle reflectedtest_get_contract_config_reflects_bounds_and_window— per-call bounds and rate-limit window reflectedtest_get_contract_config_readable_while_paused— pure read, no pause gatetest_get_contract_config_before_init_admin_is_none—admin: Noneand numeric defaults beforeinittest_get_contract_config_reflects_admin_after_rotation— new admin reflected after two-step handovertest_get_contract_config_is_idempotent— two consecutive reads return identical structsSecurity notes
get_contract_configperforms no writes and calls no auth check; it cannot be used to bypass any access control.