Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from Sajjon/match_ret
Browse files Browse the repository at this point in the history
Rename DepositorAddress -> ResourceOrNonFungible, which is the name o…
  • Loading branch information
Sajjon authored Feb 9, 2024
2 parents c30fefa + 89fd840 commit 0617ecf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
7 changes: 4 additions & 3 deletions profile/src/v100/entity/account/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ mod tests {

use crate::{
assert_eq_after_json_roundtrip, AssetException,
DepositAddressExceptionRule, DepositRule, DepositorAddress, EntityFlag,
EntityFlags, HasPlaceholder, OnLedgerSettings, ThirdPartyDeposits,
DepositAddressExceptionRule, DepositRule, EntityFlag, EntityFlags,
HasPlaceholder, OnLedgerSettings, ResourceOrNonFungible,
ThirdPartyDeposits,
};
use identified_vec::IsIdentifiedVec;
use radix_engine_common::prelude::HashSet;
Expand Down Expand Up @@ -383,7 +384,7 @@ mod tests {
let new_third_party_dep = ThirdPartyDeposits::with_rule_and_lists(
DepositRule::DenyAll,
[excp1, excp2],
[DepositorAddress::Resource {
[ResourceOrNonFungible::Resource {
value: "resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"
.parse()
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod tests {
DepositRule::DenyAll,
Vec::from_iter([excp1, excp2]),
Vec::from_iter(
[DepositorAddress::Resource {
[ResourceOrNonFungible::Resource {
value: "resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"
.parse()
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod asset_exception;
mod deposit_address_exception_rule;
mod deposit_rule;
mod depositor_address;
mod resource_or_non_fungible;
mod third_party_deposits;

pub use asset_exception::*;
pub use deposit_address_exception_rule::*;
pub use deposit_rule::*;
pub use depositor_address::*;
pub use resource_or_non_fungible::*;
pub use third_party_deposits::*;
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use crate::prelude::*;
uniffi::Enum,
)]
#[serde(tag = "discriminator")]
pub enum DepositorAddress {
pub enum ResourceOrNonFungible {
#[serde(rename = "resourceAddress")]
Resource { value: ResourceAddress },
#[serde(rename = "nonFungibleGlobalID")]
NFGlobalID { value: NonFungibleGlobalId },
NonFungible { value: NonFungibleGlobalId },
}

#[cfg(test)]
Expand All @@ -27,7 +27,7 @@ mod tests {
#[test]
fn json_decode_deny_all_with_exceptions() {
let model =
DepositorAddress::Resource {
ResourceOrNonFungible::Resource {
value: "resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"
.parse()
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ThirdPartyDeposits {

/// Allows certain third-party depositors to deposit assets freely.
/// Note: There is no `deny` counterpart for this.
pub depositors_allow_list: IdentifiedVecVia<DepositorAddress>,
pub depositors_allow_list: IdentifiedVecVia<ResourceOrNonFungible>,
}

impl Default for ThirdPartyDeposits {
Expand All @@ -24,7 +24,7 @@ impl Default for ThirdPartyDeposits {
}
}

impl Identifiable for DepositorAddress {
impl Identifiable for ResourceOrNonFungible {
type ID = Self;

fn id(&self) -> Self::ID {
Expand Down Expand Up @@ -53,7 +53,7 @@ impl ThirdPartyDeposits {
) -> Self
where
I: IntoIterator<Item = AssetException>,
J: IntoIterator<Item = DepositorAddress>,
J: IntoIterator<Item = ResourceOrNonFungible>,
{
Self {
deposit_rule,
Expand Down Expand Up @@ -90,14 +90,17 @@ impl ThirdPartyDeposits {
///
/// If the set did not previously contain an equal value, true is returned.
/// If the set already contained an equal value, false is returned, and the entry is not updated.
pub fn allow_depositor(&mut self, depositor: DepositorAddress) -> bool {
pub fn allow_depositor(
&mut self,
depositor: ResourceOrNonFungible,
) -> bool {
self.depositors_allow_list.append(depositor).0
}

// If the set contains an element equal to `DepositorAddress`, removes it from the set and drops it. Returns whether such an element was present.
pub fn remove_allowed_depositor(
&mut self,
depositor: &DepositorAddress,
depositor: &ResourceOrNonFungible,
) -> bool {
self.depositors_allow_list.remove(depositor).is_some()
}
Expand Down Expand Up @@ -125,7 +128,7 @@ mod tests {
DepositRule::AcceptKnown,
BTreeSet::from_iter([excp1, excp2]),
BTreeSet::from_iter(
[DepositorAddress::NFGlobalID { value: "resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha:<foobar>".parse().unwrap()}],
[ResourceOrNonFungible::NonFungible { value: "resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha:<foobar>".parse().unwrap()}],
),
);

Expand Down Expand Up @@ -215,7 +218,7 @@ mod tests {
)
.unwrap();

let depositor = DepositorAddress::NFGlobalID {
let depositor = ResourceOrNonFungible::NonFungible {
value: "resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha:<foobar>"
.parse()
.unwrap(),
Expand Down

0 comments on commit 0617ecf

Please sign in to comment.