Skip to main content
11 votes
Accepted

Should events only be emitted in extrinsics?

Yes it is okay, and yes it definitely makes sense. The most common example of this pattern can be found in the Balances pallet, where Balances events are emitted every time the Currency trait is ...
Shawn Tabrizi's user avatar
  • 16.1k
4 votes
Accepted

pallet loose-coupling+tight-coupling, and missing traits

The problem is that you are never doing any "loose coupling". Loose coupling is when you bridge two pallets through a shared trait interface. You need to define a trait like: pub trait ...
Shawn Tabrizi's user avatar
  • 16.1k
4 votes
Accepted

How to create dex pallet?

Adam Wierzbicki has created just this. It is based on Uniswap V1. You can find his pallet here: https://github.com/Wiezzel/substrate-dex. The pallet is not production ready, but is very useful for ...
Peter - R0GUE's user avatar
3 votes
Accepted

How do I get access to AssetDetails (Assets Pallet) info from a Custom Pallet?

The idea is to create a call/function that can be called only by the creator of an Asset/Token. Use this function to get the owner. https://github.com/paritytech/substrate/blob/...
AurevoirXavier's user avatar
  • 10.7k
3 votes
Accepted

How to properly use pallet coupling

In your minimal example, making a single pallet makes sense. To be honest, it is not clear what question you are asking, or what problem you are running into. Loose coupling makes sense when there are ...
Shawn Tabrizi's user avatar
  • 16.1k
3 votes

Should events only be emitted in extrinsics?

There are also examples for events that are not tied to extrinsics, or rather those submitted much earlier. For instance the scheduler can perform an upgrade for a runtime approved via democracy. In ...
Luna's user avatar
  • 321
2 votes
Accepted

Transactional macro cross pallet transaction

Putting it above fn foo only should be fine in this case. Basically the transactional macro needs to wrap all logic that should be reverted if it fails. Since the logic in pallet A is inside of fn foo,...
Shawn Tabrizi's user avatar
  • 16.1k
2 votes
Accepted

Loose coupling with T::AccountId

Well, you set a trait bound for the associated type TypeA which requires it to implement trait TraitInPalletA. Then you attempt to assign to it a type Balances which doesn't implement that trait. ¯\_(...
Adam Wierzbicki's user avatar
2 votes

How to call methods on Collective pallet from a custom pallet?

If the target pallet doesn't provide a trait. You can do: pub trait Config: pallet_collective::Config { ... } ... let council_members = pallet_collective::Members::get(); or // in your pallet pub ...
AurevoirXavier's user avatar
  • 10.7k
2 votes

Efficiently limit NFT transfers to members of a group

FRAME has the NFTs pallet with the logic to deal with Nfts, it is highly configurable to adjust it to the logic you want when adding it into your chain. For example with the Pallet-level feature flags ...
Alex Bean's user avatar
  • 5,757
1 vote

How to access functions of pallet-assets from custom pallet?

loosely couple Assets pallet with your custom pallet using fungibles::Unbalanced trait. Then, simply T::Assets::decrease_balance() inside your pallet.
dastansam's user avatar
  • 591
1 vote
Accepted

Efficiently limit NFT transfers to members of a group

Collating information here that (eventually, in the fullness of time, etc.) should address the use case. Open questions will reflect the state of play. You define the group multiple ways, e.g. off-...
Begley Brothers Inc's user avatar
1 vote

How to loose couple trait with config?

Rather than making your trait generic over T: Config, you should make it generic over AccountId, and you probably should not include Origin anywhere in your interface. Then, rather than passing Self, ...
Shawn Tabrizi's user avatar
  • 16.1k
1 vote

Recommended layout for testing integration of pallets

Any pallet is just a Rust crate. Adding the "real" pallet1 as a dependency to Cargo.toml will make it available to be imported anywhere in your project.
Bernardo Rodrigues's user avatar
1 vote
Accepted

How pass Balance in loosely coupled pallet?

You need to pass Balance = BalanceOf<Self>. In the context of the trait there is no generic parameter T defined, so you can not use it. Your BalanceOf is written in a way that it assumes that T ...
bkchr's user avatar
  • 11.6k
1 vote
Accepted

When should I split a pallet in two or more?

This is a question that is hard to give a specific answer to. In general, splitting up pallets is useful when you expect the pallets to be modular, reusable, and potentially interchangeable. In the ...
Shawn Tabrizi's user avatar
  • 16.1k

Only top scored, non community-wiki answers of a minimum length are eligible