Skip to content

Commit

Permalink
refactor: enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Jul 25, 2024
1 parent 77711ec commit b50830c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pallets/api/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ pub mod pallet {

match key {
TotalSupply(id) => AssetsOf::<T>::total_supply(id).encode(),
BalanceOf(id, owner) => AssetsOf::<T>::balance(id, owner).encode(),
Allowance(id, owner, spender) => {
BalanceOf { id, owner } => AssetsOf::<T>::balance(id, owner).encode(),
Allowance { id, owner, spender } => {
AssetsOf::<T>::allowance(id, &owner, &spender).encode()
},
TokenName(id) => {
Expand Down
4 changes: 2 additions & 2 deletions pallets/api/src/fungibles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn balance_of_works() {
create_asset_and_mint_to(ALICE, ASSET, ALICE, 100);
assert_eq!(
Assets::balance(ASSET, ALICE).encode(),
Fungibles::read_state(BalanceOf(ASSET, ALICE))
Fungibles::read_state(BalanceOf { id: ASSET, owner: ALICE })
);
});
}
Expand All @@ -82,7 +82,7 @@ fn allowance_works() {
create_asset_mint_and_approve(ALICE, ASSET, BOB, 100, ALICE, 50);
assert_eq!(
Assets::allowance(ASSET, &ALICE, &BOB).encode(),
Fungibles::read_state(Allowance(ASSET, ALICE, BOB))
Fungibles::read_state(Allowance { id: ASSET, owner: ALICE, spender: BOB })
);
});
}
Expand Down
8 changes: 4 additions & 4 deletions runtime/devnet/src/config/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ impl Contains<RuntimeCall> for AllowedApiCalls {
}
}

impl<T: fungibles::Config> Contains<RuntimeStateKeys<T>> for AllowedApiCalls {
impl<T: fungibles::Config> Contains<RuntimeRead<T>> for AllowedApiCalls {
/// Allowed state queries from the API.
fn contains(c: &RuntimeStateKeys<T>) -> bool {
fn contains(c: &RuntimeRead<T>) -> bool {
use fungibles::Read::*;
matches!(
c,
RuntimeStateKeys::Fungibles(
RuntimeRead::Fungibles(
TotalSupply(..)
| BalanceOf(..) | Allowance(..)
| BalanceOf { .. } | Allowance { .. }
| TokenName(..) | TokenSymbol(..)
| TokenDecimals(..)
)
Expand Down
7 changes: 2 additions & 5 deletions runtime/devnet/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use crate::{
api::{AllowedApiCalls, RuntimeRead},
assets::TrustBackedAssetsInstance,
},
fungibles::{
self,
Read::{self, *},
},
fungibles::{self},
AccountId, RuntimeCall, RuntimeOrigin,
};
use codec::{Decode, Encode};
Expand Down Expand Up @@ -183,7 +180,7 @@ where
VersionedStateRead::V0(key) => {
ensure!(AllowedApiCalls::contains(&key), DispatchError::Other("UnknownCall"));
match key {
RuntimeStateKeys::Fungibles(key) => fungibles::Pallet::<T>::read_state(key),
RuntimeRead::Fungibles(key) => fungibles::Pallet::<T>::read_state(key),
}
},
};
Expand Down
1 change: 0 additions & 1 deletion runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod weights;
// Public due to integration tests crate.
pub mod config;

use codec::{Decode, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
use smallvec::smallvec;
Expand Down

0 comments on commit b50830c

Please sign in to comment.