4

Context:

i'm building a "sub-treasury" pallet, and for it, i'd like to start from the existing substrate's pallet_treasury.

Problem:

In Cargo.toml, there is relative paths (like sp-io = {version=...... path="../../sp-io"} Obviously had to change it, but then in lib.rs, i had a loooooot of errors.

those errors are mainly "the trait frame_support::[something i can't use]::[the trait] is not implemented for [Proposal<...> or #[pallet::call]]

for example purpose, here is the first error given by cargo:

error[E0277]: the trait bound `pallet::Call<T, I>: frame_support::parity_scale_codec::WrapperTypeEncode` is not satisfied
   --> pallets/sub_treasury/src/lib.rs:296:12
    |
296 |     #[pallet::call]
    |               ^^^^ the trait `frame_support::parity_scale_codec::WrapperTypeEncode` is not implemented for `pallet::Call<T, I>`
    |
...
note: required by a bound in `frame_support::Callable::Call`
   --> /home/erudyx/.cargo/git/checkouts/substrate-7e08433d4c370a21/19162e4/frame/support/src/dispatch.rs:56:38
    |
56  |     type Call: UnfilteredDispatchable + Codec + Clone + PartialEq + Eq;
    |                                         ^^^^^ required by this bound in `frame_support::Callable::Call`

Question:

I'd like to know if there is a proper way to fork a pallet. Is there a specific branch to fork from ? A specific repo ? Is there a place where the procedure is documented ?

2
  • Please paste here the first compiler error exactly as it appears.
    – Shawn Tabrizi
    May 5, 2022 at 11:20
  • To have a correct format, i added the first error on the OP
    – Nathan
    May 5, 2022 at 11:27

2 Answers 2

3

I tested these steps and they work just fine:

  1. Copy the pallet folder you want to a new location. (I used my desktop)
  2. Navigate to the copied pallet folder.
  3. Modify Cargo.toml replacing path = "..." with git = "https://github.com/paritytech/substrate.git"
    • You can use the regular expression path = "[\S]+" to match on the path string.
  4. Run cargo build in the folder.

If you run into any compiler issues, make sure to update your rust compiler:

  • rustup update

EDIT:

As noted by the author, it is critical if you are building a forked crate in a larger Substrate project, that all versions / references to Substrate must be the same. You can quickly run into compiler errors if you have one crate which depends on one version of Substrate, and another crate depend on a different version.

1
  • The problem was unmatching version. I'm accepting your answer because it clearly answer to the title question, but could you please note on your response to be careful of which version of the pallet we're taking, so people wont do the same mistake as me ? Thanks :D
    – Nathan
    May 5, 2022 at 13:34
1

Okey follow this steps

  1. in the src/cargo.toml include the pallet ( its repo and which version you want to use)

  2. Then include the pallet into workspace project/ cargo.toml -> There is workspace vector , include the path to your pallet

  3. Then include it in the runtime/cargo.toml

  4. Then import it in the runtime/src -> Then implement the neccessary trait require by the pallet. You can see example from balances pallet how its implemented in the runtime and Then Include it in the construct_runtime!

7
  • I followed your steps (i already did 1 and 2), but i still have the errors. I made some clarification in the OP about the errors i encounter
    – Nathan
    May 5, 2022 at 10:58
  • You are getting error from your pallet as per the error message and not from importing the pallet. So checkout your code inside pallet treasury. Or you can share your repo for more clarification. May 5, 2022 at 11:39
  • i didn't change anything in pallet_treasury code, I only copied it, pasted in /pallet/sub-treasury and renamed as it should. I have this version: github.com/paritytech/substrate/tree/master/frame/treasury
    – Nathan
    May 5, 2022 at 11:44
  • yes but the errors are from sub_treasury pallet. So the treasury pallet is fine May 5, 2022 at 11:48
  • 1
    sadly it's a closed source. But i understood my problem, the treasury version i took was on master, and the version of substrate i was using was 0.9.16, so a different one. i just took the treasury code from polkadot-v0.9.16 branch on substrate, and now it's working just fine :)
    – Nathan
    May 5, 2022 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.