Skip to content

Commit

Permalink
added the skeleton traits for raising a dispute
Browse files Browse the repository at this point in the history
  • Loading branch information
mshankarrao committed Aug 14, 2023
1 parent fc2c8cf commit 63efe28
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 122 deletions.
64 changes: 23 additions & 41 deletions pallets/disputes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
/// <https://docs.substrate.io/reference/frame-pallets/>
pub use pallet::*;

#[cfg(test)]
mod mock;

#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod traits;
pub mod weights;
pub use weights::*;

Expand All @@ -25,6 +17,10 @@ pub mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(_);

pub(crate) type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub(crate) type DisputeKey = u32;
pub(crate) type ProjectKey = u32;

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
Expand All @@ -37,19 +33,16 @@ pub mod pallet {
// The pallet's runtime storage items.
// https://docs.substrate.io/main-docs/build/runtime-storage/
#[pallet::storage]
#[pallet::getter(fn something)]
// Learn more about declaring storage items:
// https://docs.substrate.io/main-docs/build/runtime-storage/#declaring-storage-items
pub type Something<T> = StorageValue<_, u32>;
pub type Disputes<T> =
StorageMap<_, Blake2_128Concat, ProjectKey, AccountIdOf<T>, OptionQuery>;

// Pallets use events to inform users when important changes are made.
// https://docs.substrate.io/main-docs/build/events-errors/
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event documentation should end with an array that provides descriptive names for event
/// parameters. [something, who]
SomethingStored { something: u32, who: T::AccountId },
DisputeRaised {who: AccountIdOf<T> },
}

// Errors inform users that something went wrong.
Expand All @@ -70,39 +63,28 @@ pub mod pallet {
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::do_something())]
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
pub fn handle_dispute(
origin: OriginFor<T>,
who: AccountIdOf<T>,
projectKey: ProjectKey) -> DispatchResult {
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
// https://docs.substrate.io/main-docs/build/origins/
let who = ensure_signed(origin)?;
let origin = ensure_signed(origin)?;
Disputes::<T>::insert(projectKey,who.clone());

// Update storage.
<Something<T>>::put(something);

// Emit an event.
Self::deposit_event(Event::SomethingStored { something, who });
// Return a successful DispatchResultWithPostInfo
Self::deposit_event(Event::<T>::DisputeRaised {who: who.clone()});
Ok(())
}

/// An example dispatchable that may throw a custom error.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::cause_error())]
pub fn cause_error(origin: OriginFor<T>) -> DispatchResult {
let _who = ensure_signed(origin)?;

// Read a value from storage.
match <Something<T>>::get() {
// Return an error if the value has not been set.
None => return Err(Error::<T>::NoneValue.into()),
Some(old) => {
// Increment the value read from storage; will error in the event of overflow.
let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;
// Update the value in storage with the incremented result.
<Something<T>>::put(new);
Ok(())
},
}
}
}

#[derive(Encode, Decode, PartialEq, Eq, Copy, Clone, Debug, MaxEncodedLen)]
pub enum Jury {
Fellowship,
Contributors,
Canonical,
}

}
54 changes: 0 additions & 54 deletions pallets/disputes/src/mock.rs

This file was deleted.

27 changes: 0 additions & 27 deletions pallets/disputes/src/tests.rs

This file was deleted.

15 changes: 15 additions & 0 deletions pallets/disputes/src/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use sp_runtime::DispatchError;

pub trait DisputeRaiser<AccountId>{

fn raise_dispute(
who: &AccountId,
reason: &str,
project_id: u32,

) -> Result<(), DispatchError>;
}

pub trait JurySelector{
fn select_jury()-> Result<(), DispatchError>;
}

0 comments on commit 63efe28

Please sign in to comment.