forked from JoshOrndorff/substrate-node-template
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
37 improve reputation #116
Open
f-gate
wants to merge
19
commits into
universal-develop
Choose a base branch
from
37-improve-reputation
base: universal-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
caf9dce
added traits for profile
f-gate f4f8bc7
started reputation pallet added trait to pallet profile
f-gate d7a2804
added basic pallet structure
f-gate b4d680e
dancing with compiler, add generic params to rep traits
f-gate d7586fa
linking up traits fixing errs
f-gate 692d640
added rep struct
f-gate 05a0f63
moved struc to impls
f-gate c942876
improving the traits, adding the reputationhandler to pallet profile
f-gate 3a01ef0
fixed impls, modified traits, added rate entity function
f-gate f917f41
added events for reputation
f-gate 8d3ebfc
fixed compile issues, readablility imporved
f-gate 86bfc24
tests, mock, simple impl
f-gate 841616b
fixed test
f-gate ad8a949
added documentation and commetns for pallet-reputaton
f-gate 1b49754
added pallet reputation to profile and tasks
f-gate 1cc8459
plumbing the reputation into the pallets, fixing up test environment
f-gate 8782305
fixed tests for profile, dao, task
f-gate dc8f848
fixed failing test
f-gate a45e492
fix benchmarks
f-gate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,5 +153,6 @@ fn testnet_genesis( | |
}, | ||
transaction_payment: Default::default(), | ||
treasury: Default::default(), | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,10 @@ frame_support::construct_runtime!( | |
NodeBlock = Block, | ||
UncheckedExtrinsic = UncheckedExtrinsic, | ||
{ | ||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, | ||
Profile: pallet_profile::{Pallet, Call, Storage, Event<T>}, | ||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>}, | ||
System: frame_system, | ||
Profile: pallet_profile, | ||
Balances: pallet_balances, | ||
Reputation: pallet_reputation, | ||
} | ||
); | ||
|
||
|
@@ -97,6 +98,21 @@ impl pallet_balances::Config for Test { | |
type WeightInfo = (); | ||
} | ||
|
||
parameter_types! { | ||
#[derive(TypeInfo, MaxEncodedLen, Encode)] | ||
pub MaximumRatingsPer: u32 = 5; | ||
|
||
pub DefaultReputation: i32 = 0; | ||
} | ||
|
||
impl pallet_reputation::Config for Test { | ||
type Event = Event; | ||
type ReputationHandler = pallet_reputation::impls::ReputationHandler; | ||
type DefaultReputation = DefaultReputation; | ||
type MaximumRatingsPer = MaximumRatingsPer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we need max ratings? |
||
} | ||
|
||
|
||
// Build genesis storage according to the mock runtime. | ||
pub(crate) fn new_test_ext() -> sp_io::TestExternalities { | ||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[package] | ||
name = "pallet-reputation" | ||
version = "0.7.0" | ||
description = "FRAME pallet for deriving the reputation of a given entity." | ||
authors = ["UNIVERSALDOT FOUNDATION <https://github.com/UniversalDot>"] | ||
homepage = "https://universaldot.foundation" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
publish = false | ||
repository = "https://github.com/UniversalDot/pallets" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [ | ||
"derive", | ||
] } | ||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } | ||
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
|
||
[dev-dependencies] | ||
sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
] | ||
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] | ||
try-runtime = ["frame-support/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
use crate::{ | ||
pallet::{CredibilityUnit, ReputationUnit, Reputable, Rating}, | ||
traits::{HasReputation, HasCredibility, HasAccountId} | ||
|
||
}; | ||
use frame_support::{ | ||
pallet_prelude::*, | ||
inherent::Vec, | ||
BoundedVec | ||
}; | ||
|
||
pub struct ReputationHandler; | ||
|
||
impl<T> crate::traits::ReputationHandler<T> for ReputationHandler | ||
where T: frame_system::Config + crate::Config | ||
{ | ||
|
||
fn calculate_credibility<N>(entity: &N, ratings: &BoundedVec<Rating, T::MaximumRatingsPer>) -> CredibilityUnit | ||
where N: HasCredibility | ||
{ | ||
CredibilityUnit::default() | ||
} | ||
|
||
fn calculate_reputation<N>(entity: &N, ratings: &BoundedVec<Rating, T::MaximumRatingsPer>) -> ReputationUnit | ||
where N: HasCredibility + HasReputation + HasAccountId<T> | ||
{ | ||
let mut rep = entity.get_reputation(); | ||
|
||
let _: Vec<_> = ratings.iter().map(|r|{ | ||
let diff: i32 = *r as i32 - 3i32; | ||
rep += diff; | ||
}).collect::<_>(); | ||
|
||
rep.try_into().expect("input vec is bounded, output is same length; qed") | ||
} | ||
} | ||
|
||
|
||
impl<T> HasCredibility for Reputable<T> | ||
where T: frame_system::Config | ||
{ | ||
fn get_credibility(&self) -> CredibilityUnit { | ||
self.credibility | ||
} | ||
|
||
} | ||
|
||
impl<T> HasReputation for Reputable<T> | ||
where T: frame_system::Config | ||
{ | ||
fn get_reputation(&self) -> ReputationUnit { | ||
self.reputation | ||
} | ||
} | ||
|
||
impl<T> HasAccountId<T> for Reputable<T> | ||
where T: frame_system::Config | ||
{ | ||
fn get_account_id(&self) -> &T::AccountId { | ||
&self.account | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to keep the
reputation
as part of the profile struct.