From 0b396c517ef1697bd670dd853ea7acb2a556f5d8 Mon Sep 17 00:00:00 2001 From: henda07 <96376694+henda07@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:01:35 +0100 Subject: [PATCH] Update stream.move --- sources/stream.move | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/sources/stream.move b/sources/stream.move index 96a21ad..9888147 100644 --- a/sources/stream.move +++ b/sources/stream.move @@ -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 @@ -186,10 +189,40 @@ module overmind::streams { // Helper functions - Add your helper functions here (if any) //============================================================================================== + fun calculate_amount_claimable( + stream: &Stream, + 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 //============================================================================================== @@ -1999,4 +2032,4 @@ module overmind::streams { }; test_scenario::end(scenario_val); } -} \ No newline at end of file +}