diff --git a/logion-shared/Cargo.toml b/logion-shared/Cargo.toml index 8a281d8..49065a4 100644 --- a/logion-shared/Cargo.toml +++ b/logion-shared/Cargo.toml @@ -14,8 +14,10 @@ keywords = ['logion'] targets = ['x86_64-unknown-linux-gnu'] [dependencies] +codec = { package = "parity-scale-codec", version = "3.2.1", default-features = false, features = ["derive", "max-encoded-len"] } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.41" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.41" } +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-std = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.41" } [features] diff --git a/logion-shared/src/lib.rs b/logion-shared/src/lib.rs index 10bd0ef..0792c4a 100644 --- a/logion-shared/src/lib.rs +++ b/logion-shared/src/lib.rs @@ -5,7 +5,9 @@ use frame_support::{ Parameter, traits::{EnsureOrigin, UnfilteredDispatchable, Imbalance}, }; +use frame_support::codec::{Decode, Encode}; use frame_support::dispatch::DispatchResultWithPostInfo; +use frame_support::scale_info::TypeInfo; use frame_support::sp_runtime::Percent; use frame_support::traits::tokens::Balance; use frame_system::{ensure_signed, RawOrigin}; @@ -137,10 +139,16 @@ pub trait RewardDistributor, B: Balance> { pub type EuroCent = u32; +#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo, Copy)] +pub enum Beneficiary { + Treasury, + LegalOfficer(AccountId), +} + pub trait LegalFee, B: Balance, LocType, AccountId> { fn get_legal_fee(loc_type: LocType) -> EuroCent; /// Determine, distribute to, and return the beneficiary of Legal fee. - fn distribute(amount: I, loc_type: LocType, loc_owner: AccountId) -> AccountId; + fn distribute(amount: I, loc_type: LocType, loc_owner: AccountId) -> Beneficiary; } diff --git a/pallet-logion-loc/src/lib.rs b/pallet-logion-loc/src/lib.rs index 0d49554..2ea493b 100644 --- a/pallet-logion-loc/src/lib.rs +++ b/pallet-logion-loc/src/lib.rs @@ -252,7 +252,7 @@ pub mod pallet { }; use codec::HasCompact; use frame_support::traits::{Currency}; - use logion_shared::{LocQuery, LocValidity, IsLegalOfficer, RewardDistributor, DistributionKey, LegalFee, EuroCent}; + use logion_shared::{LocQuery, LocValidity, IsLegalOfficer, RewardDistributor, DistributionKey, LegalFee, EuroCent, Beneficiary}; use super::*; pub use crate::weights::WeightInfo; @@ -438,8 +438,8 @@ pub mod pallet { SponsorshipCreated(T::SponsorshipId, T::AccountId, SupportedAccountId), /// Issued when a sponsorship was successfully withdrawn [sponsorship_id, sponsor, sponsored_account] SponsorshipWithdrawn(T::SponsorshipId, T::AccountId, SupportedAccountId), - /// Issued when Legal Fee is withdrawn. [payerAccountId, beneficiaryAccountId, legalFee] - LegalFeeWithdrawn(T::AccountId, T::AccountId, BalanceOf), + /// Issued when Legal Fee is withdrawn. [payerAccountId, beneficiary, legalFee] + LegalFeeWithdrawn(T::AccountId, Beneficiary, BalanceOf), } #[pallet::error] diff --git a/pallet-logion-loc/src/mock.rs b/pallet-logion-loc/src/mock.rs index 9de4054..c6f0422 100644 --- a/pallet-logion-loc/src/mock.rs +++ b/pallet-logion-loc/src/mock.rs @@ -1,5 +1,5 @@ use crate::{self as pallet_loc, LocType, NegativeImbalanceOf, RequesterOf}; -use logion_shared::{DistributionKey, EuroCent, IsLegalOfficer, LegalFee, RewardDistributor}; +use logion_shared::{Beneficiary, DistributionKey, EuroCent, IsLegalOfficer, LegalFee, RewardDistributor}; use sp_core::hash::H256; use frame_support::{construct_runtime, parameter_types, traits::{EnsureOrigin, Currency}}; use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header, Percent}; @@ -161,13 +161,13 @@ impl LegalFee, Balance, LocType, AccountId> for LegalF } } - fn distribute(amount: NegativeImbalanceOf, loc_type: LocType, loc_owner: AccountId) -> AccountId { + fn distribute(amount: NegativeImbalanceOf, loc_type: LocType, loc_owner: AccountId) -> Beneficiary { - let beneficiary = match loc_type { - LocType::Identity => TREASURY_ACCOUNT_ID, - _ => loc_owner, + let (beneficiary, target) = match loc_type { + LocType::Identity => (Beneficiary::Treasury, TREASURY_ACCOUNT_ID), + _ => (Beneficiary::LegalOfficer(loc_owner), loc_owner), }; - Balances::resolve_creating(&beneficiary, amount); + Balances::resolve_creating(&target, amount); beneficiary } } diff --git a/pallet-logion-loc/src/tests.rs b/pallet-logion-loc/src/tests.rs index 386c0ec..3cf8640 100644 --- a/pallet-logion-loc/src/tests.rs +++ b/pallet-logion-loc/src/tests.rs @@ -6,7 +6,7 @@ use sp_core::{H256, H160}; use sp_runtime::traits::BlakeTwo256; use sp_runtime::traits::Hash; -use logion_shared::{LocQuery, LocValidity}; +use logion_shared::{Beneficiary, LocQuery, LocValidity}; use crate::{Error, File, LegalOfficerCase, LocLink, LocType, MetadataItem, CollectionItem, CollectionItemFile, CollectionItemToken, mock::*, TermsAndConditionsElement, TokensRecordFile, UnboundedTokensRecordFileOf, VerifiedIssuer, Config, OtherAccountId, SupportedAccountId, MetadataItemParams, FileParams}; use crate::Requester::{Account, OtherAccount}; @@ -381,11 +381,15 @@ fn check_storage_fees(num_of_files: u32, tot_size: &u32, payer: AccountId) { })); } -fn check_legal_fees(expected_fees: Balance, payer: AccountId, beneficiary: AccountId) { - let credited_fees: Balance = get_free_balance(beneficiary) - BALANCE_OK_FOR_LOC_CREATION; +fn check_legal_fees(expected_fees: Balance, payer: AccountId, beneficiary_account: AccountId) { + let credited_fees: Balance = get_free_balance(beneficiary_account) - BALANCE_OK_FOR_LOC_CREATION; assert_eq!(credited_fees, expected_fees); let debited_fees: Balance = BALANCE_OK_FOR_LOC_CREATION - get_free_balance(payer); assert_eq!(debited_fees, expected_fees); + let beneficiary = match beneficiary_account { + TREASURY_ACCOUNT_ID => Beneficiary::Treasury, + _ => Beneficiary::LegalOfficer(beneficiary_account) + }; if expected_fees > 0 { System::assert_has_event(RuntimeEvent::LogionLoc(crate::Event::LegalFeeWithdrawn { 0: payer,