Skip to content

Commit

Permalink
fix: remove unnecessary api functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Jul 30, 2024
1 parent d4f7f99 commit 6f4da18
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 196 deletions.
39 changes: 0 additions & 39 deletions pallets/api/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type AssetIdParameterOf<T> = <T as pallet_assets::Config<AssetsInstanceOf<T>>>::
type AssetsOf<T> = pallet_assets::Pallet<T, AssetsInstanceOf<T>>;
type AssetsInstanceOf<T> = <T as Config>::AssetsInstance;
type AssetsWeightInfoOf<T> = <T as pallet_assets::Config<AssetsInstanceOf<T>>>::WeightInfo;
type RemoveItemsLimitOf<T> = <T as pallet_assets::Config<AssetsInstanceOf<T>>>::RemoveItemsLimit;
type BalanceOf<T> = <pallet_assets::Pallet<T, AssetsInstanceOf<T>> as Inspect<
<T as frame_system::Config>::AccountId,
>>::Balance;
Expand Down Expand Up @@ -209,44 +208,6 @@ pub mod pallet {
AssetsOf::<T>::start_destroy(origin, id.into())
}

/// Destroy all accounts associated with a token with a given asset ID.
///
/// # Parameters
/// - `id` - The ID of the asset.
// TODO: weight function
#[pallet::call_index(13)]
#[pallet::weight(AssetsWeightInfoOf::<T>::destroy_accounts(RemoveItemsLimitOf::<T>::get() / 6))]
pub fn destroy_accounts(
origin: OriginFor<T>,
id: AssetIdOf<T>,
) -> DispatchResultWithPostInfo {
AssetsOf::<T>::destroy_accounts(origin, id.into())
}

/// Destroy all approvals associated with a token with a given asset ID.
///
/// # Parameters
/// - `id` - The ID of the asset.
// TODO: weight function
#[pallet::call_index(14)]
#[pallet::weight(AssetsWeightInfoOf::<T>::destroy_approvals(RemoveItemsLimitOf::<T>::get() / 4))]
pub fn destroy_approvals(
origin: OriginFor<T>,
id: AssetIdOf<T>,
) -> DispatchResultWithPostInfo {
AssetsOf::<T>::destroy_approvals(origin, id.into())
}

/// Complete the process of destroying a token with a given asset ID.
///
/// # Parameters
/// - `id` - The ID of the asset.
#[pallet::call_index(15)]
#[pallet::weight(AssetsWeightInfoOf::<T>::finish_destroy())]
pub fn finish_destroy(origin: OriginFor<T>, id: AssetIdOf<T>) -> DispatchResult {
AssetsOf::<T>::finish_destroy(origin, id.into())
}

/// Set the metadata for a token with a given asset ID.
///
/// # Parameters
Expand Down
5 changes: 1 addition & 4 deletions pallets/api/src/fungibles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ fn create_works() {
}

#[test]
fn destroy_asset_works() {
fn start_destroy_works() {
new_test_ext().execute_with(|| {
create_asset(ALICE, ASSET, 100);
assert_ok!(Fungibles::start_destroy(signed(ALICE), ASSET));
assert_ok!(Fungibles::destroy_accounts(signed(ALICE), ASSET));
assert_ok!(Fungibles::destroy_approvals(signed(ALICE), ASSET));
assert_ok!(Fungibles::finish_destroy(signed(ALICE), ASSET));
});
}

Expand Down
15 changes: 0 additions & 15 deletions pop-api/integration-tests/contracts/fungibles/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,6 @@ mod fungibles {
api::start_destroy(id)
}

#[ink(message)]
pub fn destroy_accounts(&self, id: AssetId) -> Result<()> {
api::destroy_accounts(id)
}

#[ink(message)]
pub fn destroy_approvals(&self, id: AssetId) -> Result<()> {
api::destroy_approvals(id)
}

#[ink(message)]
pub fn finish_destroy(&self, id: AssetId) -> Result<()> {
api::finish_destroy(id)
}

#[ink(message)]
pub fn set_metadata(
&self,
Expand Down
87 changes: 0 additions & 87 deletions pop-api/integration-tests/src/local_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,6 @@ fn start_destroy(addr: AccountId32, asset_id: AssetId) -> ExecReturnValue {
result
}

fn destroy_accounts(addr: AccountId32, asset_id: AssetId) -> ExecReturnValue {
let function = function_selector("destroy_accounts");
let params = [function, asset_id.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
result
}

fn destroy_approvals(addr: AccountId32, asset_id: AssetId) -> ExecReturnValue {
let function = function_selector("destroy_approvals");
let params = [function, asset_id.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
result
}

fn finish_destroy(addr: AccountId32, asset_id: AssetId) -> ExecReturnValue {
let function = function_selector("finish_destroy");
let params = [function, asset_id.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
result
}

fn set_metadata(
addr: AccountId32,
asset_id: AssetId,
Expand Down Expand Up @@ -605,72 +584,6 @@ fn start_destroy_works() {
});
}

#[test]
fn destroy_accounts_works() {
new_test_ext().execute_with(|| {
let _ = env_logger::try_init();
let addr = instantiate(CONTRACT, INIT_VALUE, vec![2]);
// Asset does not exist.
assert_eq!(
decoded::<Error>(destroy_accounts(addr.clone(), ASSET_ID)),
Ok(Module { index: 52, error: 3 }),
);
let asset = create_asset(addr.clone(), ASSET_ID, 1);
// The destroy process hasn't been started.
assert_eq!(
decoded::<Error>(destroy_accounts(addr.clone(), asset)),
Ok(Module { index: 52, error: 17 }),
);
start_destroy_asset(addr.clone(), asset);
let result = destroy_accounts(addr.clone(), asset);
assert!(!result.did_revert(), "Contract reverted!");
});
}

#[test]
fn destroy_approvals_works() {
new_test_ext().execute_with(|| {
let _ = env_logger::try_init();
let addr = instantiate(CONTRACT, INIT_VALUE, vec![2]);
// Asset does not exist.
assert_eq!(
decoded::<Error>(destroy_approvals(addr.clone(), ASSET_ID)),
Ok(Module { index: 52, error: 3 }),
);
let asset = create_asset(addr.clone(), ASSET_ID, 1);
// The destroy process hasn't been started.
assert_eq!(
decoded::<Error>(destroy_approvals(addr.clone(), asset)),
Ok(Module { index: 52, error: 17 }),
);
start_destroy_asset(addr.clone(), asset);
let result = destroy_approvals(addr.clone(), asset);
assert!(!result.did_revert(), "Contract reverted!");
});
}

#[test]
fn finish_destroy_works() {
new_test_ext().execute_with(|| {
let _ = env_logger::try_init();
let addr = instantiate(CONTRACT, INIT_VALUE, vec![2]);
// Asset does not exist.
assert_eq!(
decoded::<Error>(finish_destroy(addr.clone(), ASSET_ID)),
Ok(Module { index: 52, error: 3 }),
);
let asset = create_asset(addr.clone(), ASSET_ID, 1);
// The destroy process hasn't been started.
assert_eq!(
decoded::<Error>(finish_destroy(addr.clone(), asset)),
Ok(Module { index: 52, error: 17 }),
);
start_destroy_asset(addr.clone(), asset);
let result = finish_destroy(addr.clone(), asset);
assert!(!result.did_revert(), "Contract reverted!");
});
}

#[test]
fn set_metadata_works() {
new_test_ext().execute_with(|| {
Expand Down
48 changes: 0 additions & 48 deletions pop-api/src/v0/assets/fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ mod constants {
/// 3. Asset Management:
pub(super) const CREATE: u8 = 11;
pub(super) const START_DESTROY: u8 = 12;
pub(super) const DESTROY_ACCOUNTS: u8 = 13;
pub(super) const DESTROY_APPROVALS: u8 = 14;
pub(super) const FINISH_DESTROY: u8 = 15;
pub(super) const SET_METADATA: u8 = 16;
pub(super) const CLEAR_METADATA: u8 = 17;
}
Expand Down Expand Up @@ -287,51 +284,6 @@ pub mod asset_management {
.call(&(id))
}

/// Destroy all accounts associated with a token with a given asset ID.
///
/// # Parameters
/// - `id` - The ID of the asset.
///
/// # Returns
/// Returns `Ok(())` if successful, or an error if the operation fails.
pub fn destroy_accounts(id: AssetId) -> Result<()> {
build_dispatch(DESTROY_ACCOUNTS)
.input::<AssetId>()
.output::<Result<()>, true>()
.handle_error_code::<StatusCode>()
.call(&(id))
}

/// Destroy all approvals associated with a token with a given asset ID.
///
/// # Parameters
/// - `id` - The ID of the asset.
///
/// # Returns
/// Returns `Ok(())` if successful, or an error if the operation fails.
pub fn destroy_approvals(id: AssetId) -> Result<()> {
build_dispatch(DESTROY_APPROVALS)
.input::<AssetId>()
.output::<Result<()>, true>()
.handle_error_code::<StatusCode>()
.call(&(id))
}

/// Complete the process of destroying a token with a given asset ID.
///
/// # Parameters
/// - `id` - The ID of the asset.
///
/// # Returns
/// Returns `Ok(())` if successful, or an error if the operation fails.
pub fn finish_destroy(id: AssetId) -> Result<()> {
build_dispatch(FINISH_DESTROY)
.input::<AssetId>()
.output::<Result<()>, true>()
.handle_error_code::<StatusCode>()
.call(&(id))
}

/// Set the metadata for a token with a given asset ID.
///
/// # Parameters
Expand Down
3 changes: 0 additions & 3 deletions runtime/devnet/src/config/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ impl Contains<RuntimeCall> for AllowedApiCalls {
| approve { .. } | increase_allowance { .. }
| create { .. } | set_metadata { .. }
| start_destroy { .. }
| destroy_accounts { .. }
| destroy_approvals { .. }
| finish_destroy { .. }
| clear_metadata { .. }
)
)
Expand Down

0 comments on commit 6f4da18

Please sign in to comment.