Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Dynamic*Address types in the ManifestInput models #1992

Merged
merged 7 commits into from
Nov 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TAKE_FROM_WORKTOP
```
*/

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DynamicGlobalAddress {
Static(GlobalAddress),
Named(ManifestNamedAddress),
Expand Down Expand Up @@ -214,7 +214,7 @@ impl TryFrom<ManifestAddress> for DynamicGlobalAddress {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DynamicPackageAddress {
Static(PackageAddress),
Named(ManifestNamedAddress),
Expand Down Expand Up @@ -339,7 +339,7 @@ impl TryFrom<ManifestAddress> for DynamicPackageAddress {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DynamicComponentAddress {
Static(ComponentAddress),
Named(ManifestNamedAddress),
Expand Down Expand Up @@ -441,7 +441,7 @@ impl TryFrom<ManifestAddress> for DynamicComponentAddress {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DynamicResourceAddress {
Static(ResourceAddress),
Named(ManifestNamedAddress),
Expand Down
2 changes: 2 additions & 0 deletions radix-common/src/data/manifest/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod manifest_address_reservation;
mod manifest_blob;
mod manifest_bucket;
mod manifest_decimal;
mod manifest_dynamic_addresses;
mod manifest_expression;
mod manifest_non_fungible_local_id;
mod manifest_precise_decimal;
Expand All @@ -14,6 +15,7 @@ pub use manifest_address_reservation::*;
pub use manifest_blob::*;
pub use manifest_bucket::*;
pub use manifest_decimal::*;
pub use manifest_dynamic_addresses::*;
pub use manifest_expression::*;
pub use manifest_non_fungible_local_id::*;
pub use manifest_precise_decimal::*;
Expand Down
85 changes: 67 additions & 18 deletions radix-engine-interface/src/blueprints/account/invocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ pub struct AccountWithdrawInput {
pub amount: Decimal,
}

pub type AccountWithdrawManifestInput = AccountWithdrawInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountWithdrawManifestInput {
pub resource_address: DynamicResourceAddress,
pub amount: Decimal,
}

pub type AccountWithdrawOutput = Bucket;

Expand All @@ -176,7 +180,11 @@ pub struct AccountWithdrawNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountWithdrawNonFungiblesManifestInput = AccountWithdrawNonFungiblesInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountWithdrawNonFungiblesManifestInput {
pub resource_address: DynamicResourceAddress,
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountWithdrawNonFungiblesOutput = Bucket;

Expand All @@ -193,7 +201,12 @@ pub struct AccountLockFeeAndWithdrawInput {
pub amount: Decimal,
}

pub type AccountLockFeeAndWithdrawManifestInput = AccountLockFeeAndWithdrawInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountLockFeeAndWithdrawManifestInput {
pub amount_to_lock: Decimal,
pub resource_address: DynamicResourceAddress,
pub amount: Decimal,
}

pub type AccountLockFeeAndWithdrawOutput = Bucket;

Expand All @@ -211,8 +224,12 @@ pub struct AccountLockFeeAndWithdrawNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountLockFeeAndWithdrawNonFungiblesManifestInput =
AccountLockFeeAndWithdrawNonFungiblesInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountLockFeeAndWithdrawNonFungiblesManifestInput {
pub amount_to_lock: Decimal,
pub resource_address: DynamicResourceAddress,
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountLockFeeAndWithdrawNonFungiblesOutput = Bucket;

Expand All @@ -228,7 +245,11 @@ pub struct AccountCreateProofOfAmountInput {
pub amount: Decimal,
}

pub type AccountCreateProofOfAmountManifestInput = AccountCreateProofOfAmountInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountCreateProofOfAmountManifestInput {
pub resource_address: DynamicResourceAddress,
pub amount: Decimal,
}

pub type AccountCreateProofOfAmountOutput = Proof;

Expand All @@ -244,7 +265,11 @@ pub struct AccountCreateProofOfNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountCreateProofOfNonFungiblesManifestInput = AccountCreateProofOfNonFungiblesInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountCreateProofOfNonFungiblesManifestInput {
pub resource_address: DynamicResourceAddress,
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountCreateProofOfNonFungiblesOutput = Proof;

Expand Down Expand Up @@ -275,7 +300,11 @@ pub struct AccountSetResourcePreferenceInput {
pub resource_preference: ResourcePreference,
}

pub type AccountSetResourcePreferenceManifestInput = AccountSetResourcePreferenceInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountSetResourcePreferenceManifestInput {
pub resource_address: DynamicResourceAddress,
pub resource_preference: ResourcePreference,
}

pub type AccountSetResourcePreferenceOutput = ();

Expand All @@ -290,7 +319,10 @@ pub struct AccountRemoveResourcePreferenceInput {
pub resource_address: ResourceAddress,
}

pub type AccountRemoveResourcePreferenceManifestInput = AccountRemoveResourcePreferenceInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountRemoveResourcePreferenceManifestInput {
pub resource_address: DynamicResourceAddress,
}

pub type AccountRemoveResourcePreferenceOutput = ();

Expand All @@ -309,7 +341,7 @@ pub struct AccountTryDepositOrRefundInput {
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountTryDepositOrRefundManifestInput {
pub bucket: ManifestBucket,
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
}

pub type AccountTryDepositOrRefundOutput = Option<Bucket>;
Expand All @@ -329,7 +361,7 @@ pub struct AccountTryDepositBatchOrRefundInput {
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountTryDepositBatchOrRefundManifestInput {
pub buckets: BucketBatch,
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
}

pub type AccountTryDepositBatchOrRefundOutput = Option<Vec<Bucket>>;
Expand All @@ -349,7 +381,7 @@ pub struct AccountTryDepositOrAbortInput {
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountTryDepositOrAbortManifestInput {
pub bucket: ManifestBucket,
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
}

pub type AccountTryDepositOrAbortOutput = ();
Expand All @@ -369,7 +401,7 @@ pub struct AccountTryDepositBatchOrAbortInput {
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountTryDepositBatchOrAbortManifestInput {
pub buckets: BucketBatch,
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
}

pub type AccountTryDepositBatchOrAbortOutput = ();
Expand All @@ -386,7 +418,11 @@ pub struct AccountBurnInput {
pub amount: Decimal,
}

pub type AccountBurnManifestInput = AccountBurnInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountBurnManifestInput {
pub resource_address: DynamicResourceAddress,
pub amount: Decimal,
}

pub type AccountBurnOutput = ();

Expand All @@ -402,7 +438,11 @@ pub struct AccountBurnNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountBurnNonFungiblesManifestInput = AccountBurnNonFungiblesInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountBurnNonFungiblesManifestInput {
pub resource_address: DynamicResourceAddress,
pub ids: IndexSet<NonFungibleLocalId>,
}

pub type AccountBurnNonFungiblesOutput = ();

Expand All @@ -417,7 +457,10 @@ pub struct AccountAddAuthorizedDepositorInput {
pub badge: ResourceOrNonFungible,
}

pub type AccountAddAuthorizedDepositorManifestInput = AccountAddAuthorizedDepositorInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountAddAuthorizedDepositorManifestInput {
pub badge: ManifestResourceOrNonFungible,
}

pub type AccountAddAuthorizedDepositorOutput = ();

Expand All @@ -432,7 +475,10 @@ pub struct AccountRemoveAuthorizedDepositorInput {
pub badge: ResourceOrNonFungible,
}

pub type AccountRemoveAuthorizedDepositorManifestInput = AccountRemoveAuthorizedDepositorInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountRemoveAuthorizedDepositorManifestInput {
pub badge: ManifestResourceOrNonFungible,
}

pub type AccountRemoveAuthorizedDepositorOutput = ();

Expand All @@ -447,7 +493,10 @@ pub struct AccountBalanceInput {
pub resource_address: ResourceAddress,
}

pub type AccountBalanceManifestInput = AccountBalanceInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountBalanceDynamicInput {
pub resource_address: DynamicResourceAddress,
}

pub type AccountBalanceOutput = Decimal;

Expand Down
24 changes: 12 additions & 12 deletions radix-engine-interface/src/blueprints/locker/invocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ define_invocation! {
},
output: type (),
manifest_input: struct {
claimant: ComponentAddress,
claimant: DynamicComponentAddress,
bucket: ManifestBucket,
try_direct_send: bool
}
Expand All @@ -77,7 +77,7 @@ define_invocation! {
},
output: type Option<Bucket>,
manifest_input: struct {
claimants: IndexMap<ComponentAddress, ResourceSpecifier>,
claimants: IndexMap<DynamicComponentAddress, ResourceSpecifier>,
bucket: ManifestBucket,
try_direct_send: bool
}
Expand All @@ -97,8 +97,8 @@ define_invocation! {
},
output: type Bucket,
manifest_input: struct {
claimant: ComponentAddress,
resource_address: ResourceAddress,
claimant: DynamicComponentAddress,
resource_address: DynamicResourceAddress,
amount: Decimal
}
}
Expand All @@ -113,8 +113,8 @@ define_invocation! {
},
output: type Bucket,
manifest_input: struct {
claimant: ComponentAddress,
resource_address: ResourceAddress,
claimant: DynamicComponentAddress,
resource_address: DynamicResourceAddress,
ids: IndexSet<NonFungibleLocalId>
}
}
Expand All @@ -133,8 +133,8 @@ define_invocation! {
},
output: type Bucket,
manifest_input: struct {
claimant: ComponentAddress,
resource_address: ResourceAddress,
claimant: DynamicComponentAddress,
resource_address: DynamicResourceAddress,
amount: Decimal
}
}
Expand All @@ -149,8 +149,8 @@ define_invocation! {
},
output: type Bucket,
manifest_input: struct {
claimant: ComponentAddress,
resource_address: ResourceAddress,
claimant: DynamicComponentAddress,
resource_address: DynamicResourceAddress,
ids: IndexSet<NonFungibleLocalId>
}
}
Expand Down Expand Up @@ -183,8 +183,8 @@ define_invocation! {
},
output: type IndexSet<NonFungibleLocalId>,
manifest_input: struct {
claimant: ComponentAddress,
resource_address: ResourceAddress,
claimant: DynamicComponentAddress,
resource_address: DynamicResourceAddress,
limit: u32
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define_invocation! {
manifest_input: struct {
owner_role: OwnerRole,
pool_manager_rule: AccessRule,
resource_addresses: IndexSet<ResourceAddress>,
resource_addresses: IndexSet<DynamicResourceAddress>,
address_reservation: Option<ManifestAddressReservation>
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ define_invocation! {
},
output: type Bucket,
manifest_input: struct {
resource_address: ResourceAddress,
resource_address: DynamicResourceAddress,
amount: Decimal,
withdraw_strategy: WithdrawStrategy
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define_invocation! {
manifest_input: struct {
owner_role: OwnerRole,
pool_manager_rule: AccessRule,
resource_address: ResourceAddress,
resource_address: DynamicResourceAddress,
address_reservation: Option<ManifestAddressReservation>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define_invocation! {
manifest_input: struct {
owner_role: OwnerRole,
pool_manager_rule: AccessRule,
resource_addresses: (ResourceAddress, ResourceAddress),
resource_addresses: (DynamicResourceAddress, DynamicResourceAddress),
address_reservation: Option<ManifestAddressReservation>
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ define_invocation! {
},
output: type Bucket,
manifest_input: struct {
resource_address: ResourceAddress,
resource_address: DynamicResourceAddress,
amount: Decimal,
withdraw_strategy: WithdrawStrategy
}
Expand Down
19 changes: 19 additions & 0 deletions radix-engine-interface/src/blueprints/resource/proof_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ pub enum ResourceOrNonFungible {
Resource(ResourceAddress),
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, ManifestSbor)]
pub enum ManifestResourceOrNonFungible {
NonFungible(NonFungibleGlobalId),
0xOmarA marked this conversation as resolved.
Show resolved Hide resolved
Resource(DynamicResourceAddress),
}

impl From<ResourceOrNonFungible> for ManifestResourceOrNonFungible {
fn from(value: ResourceOrNonFungible) -> Self {
match value {
ResourceOrNonFungible::NonFungible(non_fungible_global_id) => {
Self::NonFungible(non_fungible_global_id)
}
ResourceOrNonFungible::Resource(resource_address) => {
Self::Resource(DynamicResourceAddress::Static(resource_address))
}
}
}
}

impl Describe<ScryptoCustomTypeKind> for ResourceOrNonFungible {
const TYPE_ID: RustTypeId =
RustTypeId::WellKnown(well_known_scrypto_custom_types::RESOURCE_OR_NON_FUNGIBLE_TYPE);
Expand Down
Loading
Loading