feat: implement subscription metadata storage and limits - #804
Closed
johnbiliyaminu-bit wants to merge 1 commit into
Closed
johnbiliyaminu-bit wants to merge 1 commit into
johnbiliyaminu-bit wants to merge 1 commit into
Conversation
Replace stub metadata functions with bounded persistent storage. Changes: - contracts/Cargo.toml: workspace root for subscription_vault contract - contracts/subscription_vault/Cargo.toml: soroban-sdk 27.0.6 dependency - contracts/subscription_vault/src/lib.rs: DataKey, Subscription, ContractError types and SubscriptionVaultClient with register_subscription + metadata dispatch functions - contracts/subscription_vault/src/metadata.rs: full implementation of set_metadata, get_metadata, delete_metadata, list_metadata_keys backed by persistent Map<Bytes, Bytes>; enforces MAX_METADATA_KEYS=10, MAX_METADATA_KEY_LENGTH=32, MAX_METADATA_VALUE_LENGTH=256 (byte lengths); emits MetadataSetEvent and MetadataDeletedEvent via #[contractevent] macro; requires subscriber-or-merchant auth - contracts/subscription_vault/src/test.rs: 35 tests covering happy paths, boundary inputs (31/32/33-byte keys, 255/256/257-byte values), 10th/11th key cap, delete-frees-slot, update-does-not-count, outsider rejection, merchant access, subscription isolation, event emission, double-delete - docs/subscription_metadata.md: API contract with limits, error codes, auth model, events, storage design, failure modes, and test coverage table - contracts/.gitignore: exclude build artifacts All 35 tests pass: cargo test --all (soroban-sdk 27.0.6)
Author
|
closes #790 |
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.
Closes #790
Summary
Replaces stub metadata functions in
contracts/subscription_vaultwith a fully working bounded persistent storage implementation.Closes #(issue number for this metadata task)
What changed
contracts/Cargo.tomlcontracts/subscription_vault/Cargo.tomlcontracts/subscription_vault/src/lib.rsDataKey,Subscription,ContractErrortypes;SubscriptionVaultcontract withregister_subscription+ metadata dispatchcontracts/subscription_vault/src/metadata.rsset_metadata,get_metadata,delete_metadata,list_metadata_keyscontracts/subscription_vault/src/test.rsdocs/subscription_metadata.mdAcceptance criteria addressed
Map<Bytes, Bytes>stored underDataKey::Metadata(subscription_id)in persistent storage. Each subscription is independent.MAX_METADATA_KEYS = 10,MAX_METADATA_KEY_LENGTH = 32,MAX_METADATA_VALUE_LENGTH = 256. Updating an existing key at capacity is allowed; only new inserts are capped.MetadataSetEventandMetadataDeletedEventemitted via the#[contractevent]macro on every successful write/delete, each carryingsubscription_id,key, andtimestamp.callermust be the registeredsubscriberormerchant. Outsiders are rejected beforerequire_authruns. Read operations are unrestricted.docs/subscription_metadata.mdcovers limits, error codes, auth model, events, storage layout, failure modes, and backward-compatibility notes.Security and failure-mode notes
callerto stored addresses before callingrequire_auth, so invalid callers never consume auth budget.list_metadata_keysreturns an emptyVec(not an error) for unknown subscriptions so read-only callers don't need to handleSubscriptionNotFound.Test results