This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Documentation for example module #1947
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6a5ad5f
WIP: SRML Example Module README
ltfschoen 781c849
add newlines
ltfschoen 5b3530e
review-fix: Change const to let. Explain generic usage more
ltfschoen 9dc0c40
refactor: Remove example steps 2 and 3. User can refer to other examp…
ltfschoen 968ef57
fix: Update to incorporate approved approach of staking module docs i…
ltfschoen 37a1b3b
fix: Move into expandable Details arrow and fix syntax so appears cor…
ltfschoen aa07ade
fix: Fix linting
ltfschoen 371a8cc
docs: Add Public Dispatchable functions
ltfschoen 16e32d7
fix: Rearrange to use Simple Code Snippet and Examples from SRML
ltfschoen 7864a3b
fix: Remove duplicate Dispatchable Functions section
ltfschoen 2d96ac0
fix: Remove Implementation Details as requested by Gav
ltfschoen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // IMPORTANT NOTES: | ||
| // | ||
| // * Documentation comments (i.e. `/// comment`) - should accompany module functions and be restricted to the module interface, not the internals of the module implementation. Only state inputs, outputs, and a brief description that mentions whether calling it requires root, but without repeating the source code details. Capitalise the first word of each documentation comment and end it with a full stop. Generic example of annotating source code with documentation comments: https://github.com/paritytech/substrate#72-contributing-to-documentation-for-substrate-packages | ||
| // * Self-documenting code - Try to refactor code to be self-documenting. | ||
| // * Code comments - Supplement complex code with a brief explanation, not every line of code. | ||
| // * Identifiers - surround by backticks (i.e. `INHERENT_IDENTIFIER`, `InherentType`, `u64`) | ||
| // * Usage scenarios - should be simple doctests. The compiler should ensure they stay valid. | ||
| // * Extended tutorials - should be moved to external files and refer to. | ||
|
|
||
| // EXAMPLE CUSTOM MODULE README | ||
|
|
||
| // Add custom module name | ||
| # <INSERT_MODULE_NAME> Module | ||
|
|
||
| // Simple description | ||
|
|
||
| ## Overview | ||
|
|
||
| // Description | ||
| // What this module is for. | ||
| // What functionality the module provides. | ||
| // When to use the module (use case examples) | ||
| // How it is used. | ||
| // Inputs it uses and the source of each input. | ||
| // Outputs it produces. | ||
|
|
||
| ## Public Interface | ||
|
|
||
| ### Supported Origins | ||
|
|
||
| // What origins are used and supported in this module (root, signed, inherent) | ||
| // i.e. root when `ensure_root` used | ||
| // i.e. inherent when `ensure_inherent` used | ||
| // i.e. signed when `ensure_signed` used | ||
| * inherent - <INSERT_DESCRIPTION> | ||
|
|
||
| ### Types | ||
|
|
||
| // Type aliases | ||
| * `ExampleType` - <INSERT_DESCRIPTION> | ||
|
|
||
| // IMPORTANT: Reference documentation of aspects such as `storageItems` and `dispatchable` functions should only be included in the https://docs.rs Rustdocs for Substrate and not repeated in the README file. | ||
|
|
||
| ### Public Inspection functions - Immutable (getters) | ||
|
|
||
| // Insert a heading for each getter function signature | ||
| #### `example_getter_name()` | ||
|
|
||
| // What it returns | ||
| // Why, when, and how often to call it | ||
| // When it could panic or error | ||
| // When safety issues to consider | ||
|
|
||
| ### Public Mutable functions (changing state) | ||
|
|
||
| // Insert a heading for each setter function signature | ||
| #### `example_setter_name(origin, parameter_name: T::ExampleType)` | ||
|
|
||
| // What state it changes | ||
| // Why, when, and how often to call it | ||
| // When it could panic or error | ||
| // When safety issues to consider | ||
| // What parameter values are valid and why | ||
|
|
||
| ### Storage Items | ||
|
|
||
| // Explain any storage items included in this module | ||
|
|
||
| ### Digest Items | ||
|
|
||
| // Explain any digest items included in this module | ||
|
|
||
| ### Inherent Data | ||
|
|
||
| // Explain what inherent data (if any) is defined in the module and any other related types | ||
|
|
||
| ##### Events: | ||
|
|
||
| // Insert events for this module if any | ||
|
|
||
| ##### Errors: | ||
|
|
||
| // Explain what generates errors | ||
|
|
||
| ## Usage | ||
|
|
||
| // Insert examples, and code snippets for module usage | ||
|
|
||
| // The following example shows how to use the <INSERT_MODULE_NAME> module in your custom module to <INSERT_USAGE_SUMMARY>. | ||
|
|
||
| 1. Import the `INSERT_MODULE_NAME` module and derive your module configuration trait with the `INSERT_MODULE_NAME` trait. | ||
|
|
||
| ``` | ||
| use <INSERT_MODULE_NAME>; | ||
|
|
||
| pub trait Trait: <INSERT_MODULE_NAME>::Trait { } | ||
| ``` | ||
|
|
||
| 2. In your module call the `INSERT_MODULE_NAME` module's `example_getter_name()` function to get <EXPLAIN_WHAT_IT_RETURNS>. | ||
|
|
||
| ``` | ||
| const example_value = <INSERT_MODULE_NAME>::Module<T>>::example_getter_name(); | ||
| ``` | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### Module configuration trait | ||
|
|
||
| // Explain implementation details that look important or distinguish the module | ||
|
|
||
| The module configuration trait of the `INSERT_MODULE_NAME` module derives from the `INSERT_MODULE_NAME` module and it defines the `ExampleType` type to represent <EXPLAIN_WHAT_IT_REPRESENTS>. | ||
|
|
||
| ### Other implemented traits | ||
|
|
||
| // Explain other implementation trait details | ||
|
|
||
| ## Extensibility | ||
|
|
||
| // Explain how to modify or customise the module to make it their own | ||
|
|
||
| ## Dependencies | ||
|
|
||
| // Dependencies on other SRML modules | ||
| // Genesis configuration modifications that may be made to incorporate this module | ||
| // Interaction with other modules | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you want to tell us here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a commit to try an make it clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you just want to show standard rust syntax for calling methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, i'm not sure what change you're implying
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bkchr I've pushed a commit that removes the steps that show a user how to call getter and setter methods and just left a comment there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example you showed was just about "how to call a function".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was a dismal example. I'm going to try and approach it similar to the example that's evolving in #1943