mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Make Documentation Examples Compile (#2310)
* opening and closing links * sudo example compiles * add Aura after it was merged to master * Timestamp doc testing passes * Timestamp doc testing works, extraneous lines commented out * balances * remove extern crate line * Removed unneeded code snippet from aura * make consensus compiles * executive compiles * cleanup unnecessary lines * staking (removed examples that are just copies of tests) * Apply suggestions from code review * unindent example
This commit is contained in:
committed by
Bastian Köcher
parent
e31cd26a9e
commit
61e63a04fb
@@ -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>;
|
||||
//! # }
|
||||
//!
|
||||
@@ -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() {}
|
||||
//! ```
|
||||
|
||||
Reference in New Issue
Block a user