Skip to content

Instantly share code, notes, and snippets.

@brunopgalvao
Created February 15, 2023 19:26
Show Gist options
  • Save brunopgalvao/6ed297a10c4d9b94f13e60fe303247b8 to your computer and use it in GitHub Desktop.
Save brunopgalvao/6ed297a10c4d9b94f13e60fe303247b8 to your computer and use it in GitHub Desktop.
BalanceOf<T> as explained by Kian
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