lib.rs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. // Ensure we're `no_std` when compiling for Wasm.
  2. #![cfg_attr(not(feature = "std"), no_std)]
  3. pub mod constraints;
  4. pub mod currency;
  5. pub mod origin_validator;
  6. use codec::{Decode, Encode};
  7. #[cfg(feature = "std")]
  8. use serde::{Deserialize, Serialize};
  9. /// Defines time in both block number and substrate time abstraction.
  10. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  11. #[derive(Clone, Encode, Decode, PartialEq, Eq, Debug, Default)]
  12. pub struct BlockAndTime<BlockNumber, Moment> {
  13. /// Defines chain block
  14. pub block: BlockNumber,
  15. /// Defines time
  16. pub time: Moment,
  17. }
  18. /// Gathers current block and time information for the runtime.
  19. /// If this function is used inside a config() at genesis the timestamp will be 0
  20. /// because the timestamp is actually produced by validators.
  21. pub fn current_block_time<T: system::Trait + timestamp::Trait>(
  22. ) -> BlockAndTime<T::BlockNumber, T::Moment> {
  23. BlockAndTime {
  24. block: <system::Module<T>>::block_number(),
  25. time: <timestamp::Module<T>>::now(),
  26. }
  27. }