Skip to content

Commit 6b2ef48

Browse files
authored
Merge pull request #1173 from PolymathNetwork/staging
Polymesh v4.1.0 [testnet branch]
2 parents 245b6d0 + ffe0d75 commit 6b2ef48

File tree

107 files changed

+5646
-5424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+5646
-5424
lines changed

Cargo.lock

Lines changed: 124 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "polymesh"
3-
version = "4.0.0"
3+
version = "4.1.0"
44
authors = ["Polymath"]
55
build = "build.rs"
66
edition = "2018"

pallets/asset/src/checkpoint/mod.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use frame_support::{
5151
traits::UnixTime,
5252
};
5353
use frame_system::ensure_root;
54+
use pallet_base::{try_next_pre, Error::CounterOverflow};
5455
pub use polymesh_common_utilities::traits::checkpoint::{Event, WeightInfo};
5556
use polymesh_common_utilities::traits::checkpoint::{ScheduleId, StoredSchedule};
5657
use polymesh_common_utilities::{
@@ -189,12 +190,12 @@ decl_module! {
189190
/// Creates a single checkpoint at the current time.
190191
///
191192
/// # 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`.
193194
/// - `ticker` to create the checkpoint for.
194195
///
195196
/// # Errors
196197
/// - `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.
198199
#[weight = T::CPWeightInfo::create_checkpoint()]
199200
pub fn create_checkpoint(origin, ticker: Ticker) {
200201
let owner = <ExternalAgents<T>>::ensure_perms(origin, ticker)?.for_event();
@@ -231,8 +232,7 @@ decl_module! {
231232
/// - `UnauthorizedAgent` if the DID of `origin` isn't a permissioned agent for `ticker`.
232233
/// - `ScheduleDurationTooShort` if the schedule duration is too short.
233234
/// - `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.
236236
/// - `FailedToComputeNextCheckpoint` if the next checkpoint for `schedule` is in the past.
237237
///
238238
/// # Permissions
@@ -288,10 +288,6 @@ decl_module! {
288288

289289
decl_error! {
290290
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,
295291
/// A checkpoint schedule does not exist for the asset.
296292
NoSuchSchedule,
297293
/// A checkpoint schedule is not removable as `ref_count(schedule_id) > 0`.
@@ -488,8 +484,8 @@ impl<T: Config> Module<T> {
488484
.filter(|&c| c <= SchedulesMaxComplexity::get())
489485
.ok_or(Error::<T>::SchedulesTooComplex)?;
490486

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))?;
493489

494490
// If start is now, we'll create the first checkpoint immediately later at (1).
495491
let infinite = remaining == 0;
@@ -592,21 +588,12 @@ impl<T: Config> Module<T> {
592588
needed: u64,
593589
) -> Result<(CheckpointId, impl Iterator<Item = CheckpointId>), DispatchError> {
594590
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>)?;
597592
let end = CheckpointId(id + needed);
598593
let seq = (0..needed).map(move |offset| CheckpointId(id + 1 + offset));
599594
Ok((end, seq))
600595
}
601596

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-
610597
/// Ensure that `id` exists in `schedules` and return `id`'s index.
611598
pub fn ensure_schedule_exists(
612599
schedules: &[StoredSchedule],

0 commit comments

Comments
 (0)