Implement an atomic register-and-describe service entrypoint
Description
Standing up a new service today takes three separate admin transactions against contracts/escrow/src/lib.rs: register_service (sets DataKey::ServiceRegistered), set_service_metadata (sets description + owner), and set_service_price. Between those calls the service exists in an inconsistent half-configured state — registered but ownerless, or described but unpriced — and an off-chain indexer that reacts to the registration sees no owner. This issue adds a single admin entrypoint that registers a service and writes its metadata atomically so a service is never observable in a partial state.
Requirements and context
- Repository scope:
Agentpay-Org/Agentpay-contracts only.
- Add
register_service_with_metadata(env, service_id, description, owner) that sets DataKey::ServiceRegistered(service_id) = true and writes DataKey::ServiceMetadata(service_id) in one admin-gated call, honouring the existing Admin + require_auth() pattern.
- Reuse the same length/validation rules applied to
set_service_metadata (do not duplicate logic — factor a shared private helper) so the description cap stays consistent.
- Emit a single event carrying
(service_id, owner) so indexers learn of the registration and its owner together; keep it purely additive.
- Keep the standalone
register_service and set_service_metadata entrypoints unchanged for backward compatibility.
Suggested execution
- Fork the repo and create a branch
git checkout -b feature/contracts-register-with-metadata
- Implement changes
- Write code in:
contracts/escrow/src/lib.rs — register_service_with_metadata plus a shared metadata-write helper.
- Write comprehensive tests in:
contracts/escrow/src/test.rs — assert registration flag, metadata, and owner are all set in one call; is_service_registered and get_service_metadata round-trip; non-admin caller panics.
- Add documentation: document the combined entrypoint in
README.md.
- Include NatSpec-style doc comments (
///) on the new entrypoint, matching the existing style in lib.rs.
- Validate security: only admin can register, no partial write on validation failure.
- Test and commit
Test and commit
- Run
cargo fmt --all -- --check, cargo build, and cargo test.
- Cover edge cases: re-registering an existing service (idempotent overwrite), empty description, non-admin caller, paused contract.
- Include the full
cargo test output and a short security notes section in the PR description.
Example commit message
feat: add register_service_with_metadata for atomic registration
Guidelines
- Minimum 95 percent test coverage for impacted modules.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
- ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.
Implement an atomic register-and-describe service entrypoint
Description
Standing up a new service today takes three separate admin transactions against
contracts/escrow/src/lib.rs:register_service(setsDataKey::ServiceRegistered),set_service_metadata(sets description + owner), andset_service_price. Between those calls the service exists in an inconsistent half-configured state — registered but ownerless, or described but unpriced — and an off-chain indexer that reacts to the registration sees no owner. This issue adds a single admin entrypoint that registers a service and writes its metadata atomically so a service is never observable in a partial state.Requirements and context
Agentpay-Org/Agentpay-contractsonly.register_service_with_metadata(env, service_id, description, owner)that setsDataKey::ServiceRegistered(service_id) = trueand writesDataKey::ServiceMetadata(service_id)in one admin-gated call, honouring the existingAdmin+require_auth()pattern.set_service_metadata(do not duplicate logic — factor a shared private helper) so the description cap stays consistent.(service_id, owner)so indexers learn of the registration and its owner together; keep it purely additive.register_serviceandset_service_metadataentrypoints unchanged for backward compatibility.Suggested execution
git checkout -b feature/contracts-register-with-metadatacontracts/escrow/src/lib.rs—register_service_with_metadataplus a shared metadata-write helper.contracts/escrow/src/test.rs— assert registration flag, metadata, and owner are all set in one call;is_service_registeredandget_service_metadataround-trip; non-admin caller panics.README.md.///) on the new entrypoint, matching the existing style inlib.rs.Test and commit
cargo fmt --all -- --check,cargo build, andcargo test.cargo testoutput and a short security notes section in the PR description.Example commit message
feat: add register_service_with_metadata for atomic registrationGuidelines
Community & contribution rewards