Skip to content
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

fix(kreivo-runtime): let accounts execute transactions #362

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pallets/communities/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where

let decision_method = maybe_decision_method.unwrap_or(DecisionMethod::Rank);
let admin_origin: OriginFor<T> = Origin::<T>::new(community_id).into();
let admin_origin_caller = admin_origin.clone().into_caller();
let admin_origin_caller: PalletsOriginOf<T> = admin_origin.clone().into_caller();

(community_id, decision_method, admin_origin, admin_origin_caller)
}
Expand Down Expand Up @@ -138,7 +138,6 @@ where
where
T: frame_system::Config + crate::Config,
OriginFor<T>: From<Origin<T>>,
<T as Config>::RuntimeEvent: From<frame_system::Event<T>>,
MembershipIdOf<T>: From<u32>,
BlockNumberFor<T>: From<u32>
)]
Expand Down
34 changes: 17 additions & 17 deletions pallets/communities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub mod pallet {
+ From<frame_system::Origin<Self>>
+ From<Origin<Self>>
+ Clone
+ OriginTrait<Call = RuntimeCallFor<Self>, AccountId = Self::AccountId>;
+ OriginTrait<Call = RuntimeCallFor<Self>, AccountId = Self::AccountId, PalletsOrigin = PalletsOriginOf<Self>>;

/// The overarching hold reason.
type RuntimeHoldReason: From<HoldReason>;
Expand Down Expand Up @@ -532,21 +532,21 @@ pub mod pallet {
Self::do_dispatch_as_community_account(&community_id, *call)
}

/// Dispatch a callable as the community account
#[cfg(any(test, feature = "testnet"))]
#[pallet::call_index(12)]
#[pallet::weight({
let di = call.get_dispatch_info();
let weight = T::WeightInfo::dispatch_as_account()
.saturating_add(T::DbWeight::get().reads_writes(1, 1))
.saturating_add(di.weight);
(weight, di.class)
})]
pub fn dispatch_as_origin(origin: OriginFor<T>, call: Box<RuntimeCallFor<T>>) -> DispatchResultWithPostInfo {
let community_id = T::MemberMgmtOrigin::ensure_origin(origin)?;
let origin = crate::Origin::<T>::new(community_id);
let post = call.dispatch(origin.into()).map_err(|e| e.error)?;
Ok(post)
}
// /// Dispatch a callable as the community account
// #[pallet::call_index(12)]
// #[pallet::weight({
// let di = call.get_dispatch_info();
// let weight = T::WeightInfo::dispatch_as_account()
// .saturating_add(T::DbWeight::get().reads_writes(1, 1))
// .saturating_add(di.weight);
// (weight, di.class)
// })]
// // #[cfg(any(test, feature = "testnet"))]
// pub fn dispatch_as_origin(origin: OriginFor<T>, call: Box<RuntimeCallFor<T>>)
// -> DispatchResultWithPostInfo { let community_id =
// T::MemberMgmtOrigin::ensure_origin(origin)?; let origin =
// crate::Origin::<T>::new(community_id); let post =
// call.dispatch(origin.into()).map_err(|e| e.error)?; Ok(post)
// }
}
}
3 changes: 2 additions & 1 deletion pallets/communities/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub type VoteOf<T> = Vote<AssetIdOf<T>, AssetBalanceOf<T>, NativeBalanceOf<T>>;
pub type DecisionMethodFor<T> = DecisionMethod<AssetIdOf<T>>;
pub type PollIndexOf<T> = <<T as Config>::Polls as Polling<Tally<T>>>::Index;
pub type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
pub type PalletsOriginOf<T> = <<T as Config>::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
pub type PalletsOriginOf<T> =
<<T as frame_system::Config>::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
pub type MembershipIdOf<T> = <T as Config>::MembershipId;
pub type RuntimeCallFor<T> = <T as Config>::RuntimeCall;
pub type RuntimeOriginFor<T> = <T as Config>::RuntimeOrigin;
Expand Down
16 changes: 11 additions & 5 deletions runtime/kreivo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, ConvertedConcreteId,
CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, LocalMint, MintLocation, NativeAsset,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SovereignSignedViaLocation, StartsWith, TakeWeightCredit, UsingComponents,
WeightInfoBounds, WithComputedOrigin,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith, TakeWeightCredit,
UsingComponents, WeightInfoBounds, WithComputedOrigin,
};
use xcm_executor::traits::JustTry;
use xcm_executor::XcmExecutor;
Expand Down Expand Up @@ -235,7 +235,13 @@ impl xcm_executor::Config for XcmConfig {
}

/// Only communities are allowed to dispatch xcm messages
pub type ConvertCommunityOrigin = pallet_communities::Origin<Runtime>;
pub type CanSendXcmMessages = pallet_communities::Origin<Runtime>;

/// Only signed origins are allowed to execute xcm transactions
pub type CanExecuteXcmTransactions = (
pallet_communities::Origin<Runtime>,
SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,
);

/// The means for routing XCM messages which are not for local execution into
/// the right message queues.
Expand All @@ -248,9 +254,9 @@ pub type XcmRouter = (

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ConvertCommunityOrigin>;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, CanSendXcmMessages>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ConvertCommunityOrigin>;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, CanExecuteXcmTransactions>;
type XcmExecuteFilter = Nothing;
// ^ Disable dispatchable execute on the XCM pallet.
type XcmExecutor = XcmExecutor<XcmConfig>;
Expand Down