Skip to content

Pull Request: Support for "Gifted" Subscriptions (#57, #14) - #78

Merged
elizabetheonoja-art merged 2 commits into
SubStream-Protocol:mainfrom
JerryIdoko:feature/gifted-subscriptions-57-14
Mar 25, 2026
Merged

Pull Request: Support for "Gifted" Subscriptions (#57, #14)#78
elizabetheonoja-art merged 2 commits into
SubStream-Protocol:mainfrom
JerryIdoko:feature/gifted-subscriptions-57-14

Conversation

@JerryIdoko

Copy link
Copy Markdown
Contributor

📝 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

@drips-wave

drips-wave Bot commented Mar 25, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@elizabetheonoja-art
elizabetheonoja-art merged commit fbe863a into SubStream-Protocol:main Mar 25, 2026
1 check failed
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.

#14 Support for "Gifted" Subscriptions (Payer vs. Beneficiary) #14 Support for "Gifted" Subscriptions

2 participants