Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make Documentation Examples Compile #2310

Merged
merged 19 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions srml/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,6 @@
//!
//! - `slot_duration` - Determine the Aura slot-duration based on the Timestamp module configuration.
//!
//! ## Usage
//!
//! ### Prerequisites
//!
//! Use of this module implies selection of the Aura algorithm.
//!
//! ### Simple Code Snippet
//!
//! Instantiate a report of skipped authorities:
//!
//! ```rust,ignore
//! let mut report = AuraReport {
//! start_slot: 6, // The first skipped slot
//! skipped: 3, // The number of authorities skipped
//! }
//! ```
//!
//! See the `tests.rs` file in this module's directory for other simple code snippets that may make this module's
//! functionalities clearer.
//!
//! ## Related Modules
//!
//! - [Staking](../srml_staking/index.html): The Staking module is called in Aura to enforce slashing
Expand Down
55 changes: 28 additions & 27 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,13 @@
//!
//! The following examples show how to use the Balances module in your custom module.
//!
//! ### Example from the SRML
//! ### Examples from the SRML
//!
//! The Contract module uses the `Currency` trait to handle gas.
//! The Contract module uses the `Currency` trait to handle gas payment, and its types inherit from `Currency`:
//!
//! [(lib.rs)](https://github.com/paritytech/substrate/blob/master/srml/contract/src/lib.rs):
//!
//! ```ignore
//! # extern crate srml_support;
//! ```
//! use srml_support::traits::Currency;
//! # pub trait Trait: balances::Trait {
//! # pub trait Trait: system::Trait {
//! # type Currency: Currency<Self::AccountId>;
//! # }
//!
Expand All @@ -110,29 +107,33 @@
//! # fn main() {}
//!```
//!
//! [(gas.rs)](https://github.com/paritytech/substrate/blob/master/srml/contract/src/gas.rs):
//! The Staking module uses the `LockableCurrency` trait to lock a stash account's funds:
//!
//! ```ignore
//! use srml_support::traits::Currency;
//! # pub trait Trait: system::Trait {}
//! ```
//! use srml_support::traits::{WithdrawReasons, LockableCurrency};
//! use primitives::traits::Bounded;
//! pub trait Trait: system::Trait {
//! type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
//! }
//! # struct StakingLedger<T: Trait> {
//! # stash: <T as system::Trait>::AccountId,
//! # total: <<T as Trait>::Currency as srml_support::traits::Currency<<T as system::Trait>::AccountId>>::Balance,
//! # phantom: std::marker::PhantomData<T>,
//! # }
//! # const STAKING_ID: [u8; 8] = *b"staking ";
//!
//! pub fn refund_unused_gas<T: Trait>(
//! transactor: &T::AccountId,
//! gas_meter: GasMeter<T>,
//! imbalance: NegativeImbalanceOf<T>,
//! fn update_ledger<T: Trait>(
//! controller: &T::AccountId,
//! ledger: &StakingLedger<T>
//! ) {
//! let gas_spent = gas_meter.spent();
//! let gas_left = gas_meter.gas_left();
//!
//! // Increase total spent gas.
//! <GasSpent<T>>::mutate(|block_gas_spent| *block_gas_spent += gas_spent);
//!
//! // Refund gas left by the price it was bought at.
//! let refund = <T::Gas as As<BalanceOf<T>>>::as_(gas_left) * gas_meter.gas_price;
//! let refund_imbalance = T::Currency::deposit_creating(transactor, refund);
//! if let Ok(imbalance) = imbalance.offset(refund_imbalance) {
//! T::GasPayment::on_unbalanced(imbalance);
//! }
//! T::Currency::set_lock(
//! STAKING_ID,
//! &ledger.stash,
//! ledger.total,
//! T::BlockNumber::max_value(),
//! WithdrawReasons::all()
//! );
//! // <Ledger<T>>::insert(controller, ledger); // Commented out as we don't have access to Staking's storage here.
//! }
//! # fn main() {}
//! ```
Expand Down
57 changes: 31 additions & 26 deletions srml/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,50 @@
//!
//! ## Usage
//!
//! ### Prerequisites
//!
//! To use functionality from the consensus module, implement the specific Trait or function that you are invoking
//! from the module:
//!
//! ```rust,ignore
//! impl<T> for consensus::SomeTrait for Module<T> {
//! /// required functions and types for trait included here
//! /// more comprehensive example included below
//! }
//! ```
//!
//! Alternatively, to set the authorities:
//!
//! ```rust,ignore
//! consensus::set_authorities(&[<authorities>]) // example included below
//! ```
//!
//! ### Simple Code Snippet
//!
//! Set authorities:
//!
//! ```rust,ignore
//! <consensus::Module<T>>::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)])
//! ```
//! # use srml_consensus as consensus;
//! # fn not_executed<T: consensus::Trait>() {
//! # let authority1 = T::SessionKey::default();
//! # let authority2 = T::SessionKey::default();
//! <consensus::Module<T>>::set_authorities(&[authority1, authority2])
//! # }
//! ```
//!
//! Log changes in the authorities set:
//!
//! ```rust,ignore
//! <consensus::Module<T>>::on_finalize(5); // finalize UintAuthorityId(5)
//! ```
//! # use srml_consensus as consensus;
//! # use primitives::traits::Zero;
//! # use primitives::traits::OnFinalize;
//! # fn not_executed<T: consensus::Trait>() {
//! <consensus::Module<T>>::on_finalize(T::BlockNumber::zero());
//! # }
//! ```
//!
//! ### Example from SRML
//!
//! In the staking module, the `consensus::OnOfflineReport` is implemented to monitor offline
//! reporting among validators:
//!
//! ```rust,ignore
//! ```
//! # use srml_consensus as consensus;
//! # trait Trait: consensus::Trait {
//! # }
//! #
//! # srml_support::decl_module! {
//! # pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! # }
//! # }
//! #
//! impl<T: Trait> consensus::OnOfflineReport<Vec<u32>> for Module<T> {
//! fn handle_report(reported_indices: Vec<u32>) {
//! for validator_index in reported_indices {
//! let v = <session::Module<T>>::validators()[validator_index as usize].clone();
//! Self::on_offline_validator(v, 1);
//! // Get validator from session module
//! // Process validator
//! }
//! }
//! }
Expand All @@ -97,11 +98,15 @@
//! In the GRANDPA module, we use `srml-consensus` to get the set of `next_authorities` before changing
//! this set according to the consensus algorithm (which does not rotate sessions in the *normal* way):
//!
//! ```rust,ignore
//! ```
//! # use srml_consensus as consensus;
//! # use consensus::Trait;
//! # fn not_executed<T: consensus::Trait>() {
//! let next_authorities = <consensus::Module<T>>::authorities()
//! .into_iter()
//! .map(|key| (key, 1)) // evenly-weighted.
//! .collect::<Vec<(<T as Trait>::SessionKey, u64)>>();
//! # }
//! ```
//!
//! ## Related Modules
Expand Down
11 changes: 10 additions & 1 deletion srml/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@
//!
//! `Executive` type declaration from the node template.
//!
//! ```ignore
//! ```
//! # use primitives::generic;
//! # use srml_executive as executive;
//! # pub struct UncheckedExtrinsic {};
//! # pub struct Header {};
//! # type Context = system::ChainContext<Runtime>;
//! # pub type Block = generic::Block<Header, UncheckedExtrinsic>;
//! # pub type Balances = u64;
//! # pub type AllModules = u64;
//! # pub enum Runtime {};
//! /// Executive: handles dispatch to the various modules.
//! pub type Executive = executive::Executive<Runtime, Block, Context, Balances, AllModules>;
//! ```
Expand Down
37 changes: 1 addition & 36 deletions srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,7 @@
//!
//! ## Usage
//!
//! ### Snippet: Bonding and Accepting Roles
//!
//! An arbitrary account pair, given that the associated stash has the required funds,
//! can become stakers via the following call:
//!
//! ```rust,ignore
//! // Bond account 3 as stash.
//! // Account 4 as controller.
//! // Stash value of 1500 units.
//! // Rewards get transferred to the controller account.
//! Staking::bond(Origin::signed(3), 4, 1500, RewardDestination::Controller);
//! ```
//!
//! To state desire to become a validator:
//!
//! ```rust,ignore
//! // Controller account 4 states desire for validation with the given preferences.
//! Staking::validate(Origin::signed(4), ValidatorPrefs::default());
//! ```
//!
//! Similarly, to state desire in nominating:
//!
//! ```rust,ignore
//! // Controller account 4 nominates for accounts 10 and 20.
//! Staking::nominate(Origin::signed(4), vec![20, 10]);
//! ```
//!
//! Finally, account 4 can withdraw from any of the above roles via
//!
//! ```rust,ignore
//! Staking::chill(Origin::signed(4));
//! ```
//!
//! You can find the equivalent of the above calls in your [Substrate UI](https://substrate-ui.parity.io).
//!
//! ### Snippet: Reporting Misbehavior
//! ### Example: Reporting Misbehavior
//!
//! ```
//! use srml_support::{decl_module, dispatch::Result};
Expand Down
6 changes: 4 additions & 2 deletions srml/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
//!
//! ### Get current timestamp
//!
//! ```ignore
//! use support::{decl_module, dispatch::Result};
//! ```
//! use srml_support::{decl_module, dispatch::Result};
//! # use srml_timestamp as timestamp;
//! use system::ensure_signed;
//!
//! pub trait Trait: timestamp::Trait {}
Expand All @@ -72,6 +73,7 @@
//! }
gui1117 marked this conversation as resolved.
Show resolved Hide resolved
//! }
//! }
//! # fn main() {}
//! ```
//!
//! ### Example from the SRML
Expand Down