Skip to content

Commit

Permalink
Add example for env::block_number()
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Sep 23, 2021
1 parent 99c406e commit 21426e8
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions crates/lang/src/env_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,25 +517,32 @@ where
/// # Example
///
/// ```
/// # use ink_lang as ink;
/// # #[ink::contract]
/// # pub mod my_contract {
/// # #[ink(storage)]
/// # pub struct MyContract { }
/// #
/// # impl MyContract {
/// # #[ink(constructor)]
/// # pub fn new() -> Self {
/// # Self {}
/// # }
/// #
/// #[ink(message)]
/// pub fn block_number(&self) -> BlockNumber {
/// self.env().block_number()
/// use ink_lang as ink;
///
/// #[ink::contract]
/// pub mod my_contract {
/// #[ink(storage)]
/// pub struct MyContract {
/// last_invocation: BlockNumber
/// }
///
/// impl MyContract {
/// #[ink(constructor)]
/// pub fn new() -> Self {
/// Self {
/// last_invocation: Self::env().block_number()
/// }
/// }
///
/// /// The function can be executed at most once every 100 blocks.
/// #[ink(message)]
/// pub fn execute_me(&mut self) {
/// let now = self.env().block_number();
/// assert!(now - self.last_invocation > 100);
/// self.last_invocation = now;
/// }
/// }
/// }
/// #
/// # }
/// # }
/// ```
///
/// # Note
Expand Down

0 comments on commit 21426e8

Please sign in to comment.