Skip to content

Commit 689bbd6

Browse files
authored
Merge pull request #329 from Devdave-0x/fix/issue-265-delegate-withdrawal
fix(streaming): wire delegate authorization in withdraw() and document auth model
2 parents 3a73b76 + a915b3d commit 689bbd6

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

contracts/streaming/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,21 @@ impl StreamingContract {
819819

820820
/// Withdraw unlocked tokens from a stream.
821821
///
822-
/// Either the recipient or the registered delegate (if set via `set_delegate`)
823-
/// may authorize a withdrawal. Pass the exact amount to withdraw (must be ≤ withdrawable amount).
824-
/// Use `get_withdrawable` to query first.
822+
/// Authorization rules:
823+
/// - If no delegate is registered, the stream's **recipient** must authorize.
824+
/// - If a delegate is registered via [`set_delegate`], the **delegate** must
825+
/// authorize instead. The delegate withdraws on behalf of the recipient
826+
/// (tokens are still sent to the recipient's address). The recipient is
827+
/// locked out while a delegate is active; call [`remove_delegate`] first to
828+
/// restore direct-recipient access.
829+
///
830+
/// Pass the exact amount to withdraw (must be ≤ the withdrawable amount).
831+
/// Use [`get_withdrawable`] to query the available amount first.
825832
pub fn withdraw(env: Env, stream_id: u64, amount: i128) -> Result<(), StreamError> {
826833
let mut stream = Self::load_stream(&env, stream_id)?;
827834

835+
// Delegate, when registered, has exclusive withdrawal authority.
836+
// If no delegate is set the recipient authorises directly.
828837
if let Some(delegate) = Self::get_delegate(env.clone(), stream_id) {
829838
delegate.require_auth();
830839
} else {

0 commit comments

Comments
 (0)