Skip to content
Snippets Groups Projects
lib.rs 1.97 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bryan Chen's avatar
    Bryan Chen committed
    #![cfg_attr(not(feature = "std"), no_std)]
    
    
    wangjj9219's avatar
    wangjj9219 committed
    use codec::{Decode, Encode};
    use sp_runtime::{DispatchResult, RuntimeDebug};
    
    Shaopeng Wang's avatar
    Shaopeng Wang committed
    use sp_std::{
    
    Shaopeng Wang's avatar
    Shaopeng Wang committed
    	cmp::{Eq, PartialEq},
    
    Ermal Kaleci's avatar
    Ermal Kaleci committed
    	prelude::Vec,
    
    Shaopeng Wang's avatar
    Shaopeng Wang committed
    
    
    pub use auction::{Auction, AuctionHandler, AuctionInfo, OnNewBidResult};
    
    wangjj9219's avatar
    wangjj9219 committed
    pub use currency::{
    	BalanceStatus, BasicCurrency, BasicCurrencyExtended, BasicLockableCurrency, BasicReservableCurrency,
    	LockIdentifier, MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency, MultiReservableCurrency,
    	OnDustRemoval, OnReceived,
    };
    
    wangjj9219's avatar
    wangjj9219 committed
    pub mod arithmetic;
    pub mod auction;
    pub mod currency;
    
    Xiliang Chen's avatar
    Xiliang Chen committed
    #[impl_trait_for_tuples::impl_for_tuples(30)]
    
    pub trait OnNewData<AccountId, Key, Value> {
    	fn on_new_data(who: &AccountId, key: &Key, value: &Value);
    
    Xiliang Chen's avatar
    Xiliang Chen committed
    }
    
    pub trait DataProvider<Key, Value> {
    	fn get(key: &Key) -> Option<Value>;
    }
    
    
    pub trait DataProviderExtended<Key, Value, AccountId>: DataProvider<Key, Value> {
    	fn feed_value(who: AccountId, key: Key, value: Value) -> DispatchResult;
    }
    
    
    Xiliang Chen's avatar
    Xiliang Chen committed
    pub trait PriceProvider<CurrencyId, Price> {
    	fn get_price(base: CurrencyId, quote: CurrencyId) -> Option<Price>;
    }
    
    Ermal Kaleci's avatar
    Ermal Kaleci committed
    
    /// Combine data provided by operators
    pub trait CombineData<Key, TimestampedValue> {
    	/// Combine data provided by operators
    	fn combine_data(
    		key: &Key,
    		values: Vec<TimestampedValue>,
    		prev_value: Option<TimestampedValue>,
    	) -> Option<TimestampedValue>;
    }
    
    #[impl_trait_for_tuples::impl_for_tuples(30)]
    pub trait OnRedundantCall<AccountId> {
    	fn multiple_calls_per_block(who: &AccountId);
    }
    
    wangjj9219's avatar
    wangjj9219 committed
    #[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug)]
    pub enum DelayedDispatchTime<BlockNumber> {
    	At(BlockNumber),
    	After(BlockNumber),
    }
    
    pub type DispatchId = u32;
    
    pub trait Scheduler<BlockNumber> {
    	type Origin;
    	type Call;
    
    	fn schedule(origin: Self::Origin, call: Self::Call, when: DelayedDispatchTime<BlockNumber>) -> DispatchId;
    	fn cancel(id: DispatchId);
    
    
    #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug)]
    pub enum Change<Value> {
    	/// No change.
    	NoChange,
    	/// Changed to new value.
    	NewValue(Value),
    }