Skip to content

feat: add get_contract_config single-read configuration snapshot#133

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Tijesunimi004:feature/contracts-get-contract-config
Jun 29, 2026
Merged

feat: add get_contract_config single-read configuration snapshot#133
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Tijesunimi004:feature/contracts-get-contract-config

Conversation

@Tijesunimi004

Copy link
Copy Markdown
Contributor

What

Add a ContractConfig struct and a get_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

  • ContractConfig is 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_config is implemented by calling the nine existing getters internally via Self::getter(env.clone()), so the defaults and storage key logic cannot drift.
  • The function is a pure read: no require_auth, no pause gate. It is callable before init (returns admin: None) and while paused.
  • No existing getter is modified; the change is purely additive.

Tests

Ten new tests in contracts/escrow/src/test.rs:

  • test_get_contract_config_defaults_on_fresh_contract — all fields at their defaults after init
  • test_get_contract_config_matches_individual_getters — every field equals its per-field getter after config changes
  • test_get_contract_config_reflects_pause_toggle — pause/unpause reflected
  • test_get_contract_config_reflects_allowlist_toggle — allowlist toggle reflected
  • test_get_contract_config_reflects_strict_registration_toggle — strict-registration toggle reflected
  • test_get_contract_config_reflects_bounds_and_window — per-call bounds and rate-limit window reflected
  • test_get_contract_config_readable_while_paused — pure read, no pause gate
  • test_get_contract_config_before_init_admin_is_noneadmin: None and numeric defaults before init
  • test_get_contract_config_reflects_admin_after_rotation — new admin reflected after two-step handover
  • test_get_contract_config_is_idempotent — two consecutive reads return identical structs
test result: ok. 181 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Security notes

  • get_contract_config performs no writes and calls no auth check; it cannot be used to bypass any access control.
  • Fields are populated by calling the existing getters, so their values are always consistent with what those getters would return for the same ledger state.
  • The function does not expose any per-agent or per-service state, only global contract settings.

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.
Copilot AI review requested due to automatic review settings June 29, 2026 08:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mikewheeleer

Copy link
Copy Markdown
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 🙌

@mikewheeleer

Copy link
Copy Markdown
Contributor

good stuff — thanks for picking it up 🙌

@mikewheeleer mikewheeleer merged commit b3c8940 into Agentpay-Org:main Jun 29, 2026
2 checks passed
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.

3 participants