Skip to content

Commit

Permalink
Add Ownable to Farm
Browse files Browse the repository at this point in the history
  • Loading branch information
deuszx committed May 20, 2024
1 parent 0bd1da4 commit acabd19
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion farm/contract/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod farm {
type TokenId = AccountId;
type UserId = AccountId;
use amm_helpers::{ensure, math::casted_mul, types::WrappedU256};
use farm_trait::{Farm, FarmDetails, FarmError};
use farm_trait::{Farm, FarmDetails, FarmError, Ownable};
use ink::{codegen::EmitEvent, contract_ref, reflect::ContractEventBase, storage::Mapping};

use ink::prelude::{vec, vec::Vec};
Expand Down Expand Up @@ -511,6 +511,21 @@ mod farm {
}
}

impl Ownable for FarmContract {
#[ink(message)]
fn owner(&self) -> AccountId {
self.owner
}

#[ink(message)]
fn set_owner(&mut self, new_owner: AccountId) -> Result<(), FarmError> {
ensure!(self.env().caller() == self.owner, FarmError::CallerNotOwner);
ensure!(!self.is_active, FarmError::FarmIsRunning);
self.owner = new_owner;
Ok(())
}
}

pub fn rewards_per_share_in_time_interval(
reward_rate: U256,
total_shares: u128,
Expand Down
9 changes: 9 additions & 0 deletions farm/trait/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,12 @@ pub trait Farm {
#[ink(message)]
fn view_farm_details(&self) -> FarmDetails;
}

#[ink::trait_definition]
pub trait Ownable {
#[ink(message)]
fn set_owner(&mut self, new_owner: AccountId) -> Result<(), FarmError>;

#[ink(message)]
fn owner(&self) -> AccountId;
}

0 comments on commit acabd19

Please sign in to comment.