Created
February 15, 2023 19:26
-
-
Save brunopgalvao/6ed297a10c4d9b94f13e60fe303247b8 to your computer and use it in GitHub Desktop.
BalanceOf<T> as explained by Kian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo; | |
struct Kian; | |
struct Shawn; | |
trait Bar { | |
type Buzz; | |
} | |
impl Bar for Foo { | |
type Buzz = u32; | |
} | |
impl Bar for Kian { | |
type Buzz = u16; | |
} | |
impl Bar for Shawn { | |
type Buzz = u8; | |
} | |
type BuzzFoo = <Foo as Bar>::Buzz; | |
type BuzzKian = <Kian as Bar>::Buzz; | |
type BuzzShawn = <Shawn as Bar>::Buzz; | |
type BuzzOf<T> = <T as Bar>::Buzz; | |
// BuzzOf<Foo> | |
// BuzzOf<Kian> | |
// BuzzOf<Shawn> | |
// <Type as Trait>::AssociatedType; | |
// BalanceOf<Runtimes> // u128 / type Balance = u128 | |
// BalanceOf<T>; | |
type BalanceOf<T> = | |
< | |
// The given T implements the config trait of my pallet. | |
<T as Config>::Currency | |
as | |
// The "currency associated type" of my config, implements traits::Currency. | |
frame_support::traits::Currency<<T as frame_system::Config>::AccountId> | |
// which MUST HAVE an associated type called Balance, regardless. | |
>::Balance; | |
// BalanceOf<T::Currency> | |
type BalanceOf<C> = <C as Currency<_>>::Balance; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment