@@ -51,6 +51,7 @@ use frame_support::{
51
51
traits:: UnixTime ,
52
52
} ;
53
53
use frame_system:: ensure_root;
54
+ use pallet_base:: { try_next_pre, Error :: CounterOverflow } ;
54
55
pub use polymesh_common_utilities:: traits:: checkpoint:: { Event , WeightInfo } ;
55
56
use polymesh_common_utilities:: traits:: checkpoint:: { ScheduleId , StoredSchedule } ;
56
57
use polymesh_common_utilities:: {
@@ -189,12 +190,12 @@ decl_module! {
189
190
/// Creates a single checkpoint at the current time.
190
191
///
191
192
/// # Arguments
192
- /// - `origin` is a signer that has permissions to act as owner of `ticker`.
193
+ /// - `origin` is a signer that has permissions to act as an agent of `ticker`.
193
194
/// - `ticker` to create the checkpoint for.
194
195
///
195
196
/// # Errors
196
197
/// - `UnauthorizedAgent` if the DID of `origin` isn't a permissioned agent for `ticker`.
197
- /// - `CheckpointOverflow ` if the total checkpoint counter would overflow.
198
+ /// - `CounterOverflow ` if the total checkpoint counter would overflow.
198
199
#[ weight = T :: CPWeightInfo :: create_checkpoint( ) ]
199
200
pub fn create_checkpoint( origin, ticker: Ticker ) {
200
201
let owner = <ExternalAgents <T >>:: ensure_perms( origin, ticker) ?. for_event( ) ;
@@ -231,8 +232,7 @@ decl_module! {
231
232
/// - `UnauthorizedAgent` if the DID of `origin` isn't a permissioned agent for `ticker`.
232
233
/// - `ScheduleDurationTooShort` if the schedule duration is too short.
233
234
/// - `InsufficientAccountBalance` if the protocol fee could not be charged.
234
- /// - `ScheduleOverflow` if the schedule ID counter would overflow.
235
- /// - `CheckpointOverflow` if the total checkpoint counter would overflow.
235
+ /// - `CounterOverflow` if the schedule ID or total checkpoint counters would overflow.
236
236
/// - `FailedToComputeNextCheckpoint` if the next checkpoint for `schedule` is in the past.
237
237
///
238
238
/// # Permissions
@@ -288,10 +288,6 @@ decl_module! {
288
288
289
289
decl_error ! {
290
290
pub enum Error for Module <T : Config > {
291
- /// An overflow while calculating the checkpoint ID.
292
- CheckpointOverflow ,
293
- /// An overflow while calculating the checkpoint schedule ID.
294
- ScheduleOverflow ,
295
291
/// A checkpoint schedule does not exist for the asset.
296
292
NoSuchSchedule ,
297
293
/// A checkpoint schedule is not removable as `ref_count(schedule_id) > 0`.
@@ -488,8 +484,8 @@ impl<T: Config> Module<T> {
488
484
. filter ( |& c| c <= SchedulesMaxComplexity :: get ( ) )
489
485
. ok_or ( Error :: < T > :: SchedulesTooComplex ) ?;
490
486
491
- // Compute next schedule ID.
492
- let id = Self :: next_schedule_id ( & ticker) ?;
487
+ // Compute the next checkpoint schedule ID. Will store it later .
488
+ let id = try_next_pre :: < T , _ > ( & mut ScheduleIdSequence :: get ( ticker) ) ?;
493
489
494
490
// If start is now, we'll create the first checkpoint immediately later at (1).
495
491
let infinite = remaining == 0 ;
@@ -592,21 +588,12 @@ impl<T: Config> Module<T> {
592
588
needed : u64 ,
593
589
) -> Result < ( CheckpointId , impl Iterator < Item = CheckpointId > ) , DispatchError > {
594
590
let CheckpointId ( id) = CheckpointIdSequence :: get ( ticker) ;
595
- id. checked_add ( needed)
596
- . ok_or ( Error :: < T > :: CheckpointOverflow ) ?;
591
+ id. checked_add ( needed) . ok_or ( CounterOverflow :: < T > ) ?;
597
592
let end = CheckpointId ( id + needed) ;
598
593
let seq = ( 0 ..needed) . map ( move |offset| CheckpointId ( id + 1 + offset) ) ;
599
594
Ok ( ( end, seq) )
600
595
}
601
596
602
- /// Compute the next checkpoint schedule ID without changing storage.
603
- /// ID of first schedule is 1 rather than 0, which means that no schedules have been made yet.
604
- fn next_schedule_id ( ticker : & Ticker ) -> Result < ScheduleId , DispatchError > {
605
- let ScheduleId ( id) = ScheduleIdSequence :: get ( ticker) ;
606
- let id = id. checked_add ( 1 ) . ok_or ( Error :: < T > :: ScheduleOverflow ) ?;
607
- Ok ( ScheduleId ( id) )
608
- }
609
-
610
597
/// Ensure that `id` exists in `schedules` and return `id`'s index.
611
598
pub fn ensure_schedule_exists (
612
599
schedules : & [ StoredSchedule ] ,
0 commit comments