Pull Request: Support for "Gifted" Subscriptions (#57, #14) - #78
Merged
elizabetheonoja-art merged 2 commits intoMar 25, 2026
Conversation
|
@JerryIdoko Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
📝 Description
This PR refactors the core subscription logic to decouple the account providing the funds (Payer) from the account receiving the service (Beneficiary). This enables "Gifting" workflows where a sponsor can pay for another user's access while maintaining control over the financial lifecycle of the stream.
🎯 Key Changes
Struct Refactor: Updated the Subscription struct to include both payer_address and beneficiary_address.
Permission Logic: * Payer Only: Can fund, top-up, or cancel the subscription stream.
Beneficiary Only: Recognized by the content-gating middleware as the "Active" subscriber.
New Storage Mapping: Implemented a GiftsReceived map (Map<Address, Vec>) to allow beneficiaries to query and display all active sponsorships on their personal dashboard.
Middleware Compatibility: Updated the is_active_subscriber view function to check the beneficiary field, ensuring seamless integration with existing gated-access tools.
💻 Implementation Detail: Data Structure Update
The core state change involves shifting from a single owner to a dual-address model:
Rust
pub struct Subscription {
pub id: u64,
pub payer: Address, // The entity paying the XLM/Asset
pub beneficiary: Address, // The entity receiving access
pub start_time: u64,
pub end_time: u64,
pub rate_per_sec: i128,
}
✅ Acceptance Criteria Checklist
[x] Separation of Concerns: Verified that payer controls the money and beneficiary gets the access.
[x] Dashboard Support: The new GiftsReceived mapping correctly indexes subscriptions by the beneficiary's address.
[x] Security: Only the payer can trigger a cancel_subscription call to prevent beneficiaries from "stealing" or prematurely ending a stream they don't fund.
[x] Gating Logic: The access-check function now correctly validates the beneficiary address against the current ledger timestamp.
🚀 How to Verify
Unit Tests:
Bash
cargo test test_gift_subscription_access
cargo test test_payer_only_cancellation
Storage Inspection:
Deploy to a local sandbox and use soroban contract read to verify the GiftsReceived entry for a test beneficiary address.
🔗 Linked Issues
Closes #57
Closes #14