Skip to content

Commit

Permalink
rework: Fix various issues in resource interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Sep 28, 2024
1 parent 1a1408d commit d499922
Show file tree
Hide file tree
Showing 12 changed files with 1,860 additions and 2,191 deletions.
9 changes: 9 additions & 0 deletions radix-common/src/math/bnum_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ macro_rules! op_impl {
}
}

impl SaturatingAdd for $t
{
type Output = $t;

fn saturating_add(self, other: Self) -> Self::Output {
Self(self.0.saturating_add(other.0))
}
}

impl CheckedSub for $t
{
type Output = $t;
Expand Down
9 changes: 9 additions & 0 deletions radix-common/src/math/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ impl CheckedAdd<Decimal> for Decimal {
}
}

impl SaturatingAdd<Decimal> for Decimal {
type Output = Self;

#[inline]
fn saturating_add(self, other: Self) -> Self::Output {
Self(self.0.saturating_add(other.0))
}
}

impl CheckedSub<Decimal> for Decimal {
type Output = Self;

Expand Down
8 changes: 8 additions & 0 deletions radix-common/src/math/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ pub trait CheckedAdd<Rhs = Self> {
Self: Sized;
}

pub trait SaturatingAdd<Rhs = Self> {
type Output;

fn saturating_add(self, other: Rhs) -> Self::Output
where
Self: Sized;
}

pub trait CheckedSub<Rhs = Self> {
type Output;

Expand Down
9 changes: 9 additions & 0 deletions radix-common/src/types/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ impl EntityType {
matches!(self, EntityType::GlobalPackage)
}

pub const fn is_global_account(&self) -> bool {
matches!(
self,
EntityType::GlobalAccount
| EntityType::GlobalPreallocatedSecp256k1Account
| EntityType::GlobalPreallocatedEd25519Account
)
}

pub const fn is_global_consensus_manager(&self) -> bool {
matches!(self, EntityType::GlobalConsensusManager)
}
Expand Down
4 changes: 4 additions & 0 deletions radix-common/src/types/node_and_substate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ impl NodeId {
matches!(self.entity_type(), Some(t) if t.is_global_component())
}

pub const fn is_global_account(&self) -> bool {
matches!(self.entity_type(), Some(t) if t.is_global_account())
}

pub const fn is_global_package(&self) -> bool {
matches!(self.entity_type(), Some(t) if t.is_global_package())
}
Expand Down
Loading

0 comments on commit d499922

Please sign in to comment.