Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stream.move #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion sources/stream.move
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module overmind::streams {
//==============================================================================================
// Constants - Add your constants here (if any)
//==============================================================================================

const MAX_DURATION_SECONDS: u64 = 31536000; // Maximum duration for a stream (1 year in seconds)
const DEFAULT_PAYMENT_AMOUNT: u64 = 100; // Default payment amount if not specified

//==============================================================================================
// Error codes - DO NOT MODIFY
Expand Down Expand Up @@ -186,10 +189,40 @@ module overmind::streams {
// Helper functions - Add your helper functions here (if any)
//==============================================================================================

fun calculate_amount_claimable<PaymentCoin>(
stream: &Stream<PaymentCoin>,
clock: &Clock
) -> u64 {
let now = clock.now_seconds();
let elapsed_seconds = now - stream.last_timestamp_claimed_seconds;
(stream.amount.value() * elapsed_seconds) / stream.duration_in_seconds
}

//==============================================================================================
// Validation functions - Add your validation functions here (if any)
//==============================================================================================

fun validate_payment_amount(payment: u64) -> u64 {
if payment == 0 {
return EPaymentMustBeGreaterThanZero;
}
return 0; // No error
}

fun validate_duration(duration: u64) -> u64 {
if duration == 0 {
return EDurationMustBeGreaterThanZero;
}
return 0; // No error
}

fun validate_sender_receiver(sender: address, receiver: address) -> u64 {
if sender == receiver {
return ESenderCannotBeReceiver;
}
return 0; // No error
}

//==============================================================================================
// Tests - DO NOT MODIFY
//==============================================================================================
Expand Down Expand Up @@ -1999,4 +2032,4 @@ module overmind::streams {
};
test_scenario::end(scenario_val);
}
}
}