Skip to content

Commit

Permalink
Latest Substrate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardo-xxnet committed Oct 13, 2022
1 parent b98d1fd commit 9b743e6
Show file tree
Hide file tree
Showing 27 changed files with 947 additions and 871 deletions.
812 changes: 508 additions & 304 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions chainbridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use sp_std::prelude::*;

use frame_support::{
decl_error, decl_event, decl_module, decl_storage,
dispatch::DispatchResult,
dispatch::{DispatchResult, GetDispatchInfo, Pays},
ensure,
traits::{EnsureOrigin, Get},
weights::{GetDispatchInfo, Pays, Weight},
weights::{Weight},
PalletId, Parameter,
};

Expand Down Expand Up @@ -102,11 +102,11 @@ impl<AccountId, BlockNumber: Default> Default for ProposalVotes<AccountId, Block
pub trait Config: system::Config {
/// The ChainBridge's module id, used for deriving account ID
type PalletId: Get<PalletId>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self>> + Into<<Self as frame_system::Config>::RuntimeEvent>;
/// Origin used to administer the pallet
type AdminOrigin: EnsureOrigin<Self::Origin>;
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// Proposed dispatchable call
type Proposal: Parameter + Dispatchable<Origin = Self::Origin> + EncodeLike + GetDispatchInfo;
type Proposal: Parameter + Dispatchable<RuntimeOrigin = Self::RuntimeOrigin> + EncodeLike + GetDispatchInfo;
/// The identifier for this chain.
/// This must be unique and must not collide with existing IDs within a set of bridged chains.
type ChainId: Get<ChainId>;
Expand Down Expand Up @@ -207,7 +207,7 @@ decl_storage! {
}

decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
type Error = Error<T>;

const ChainIdentity: ChainId = T::ChainId::get();
Expand Down Expand Up @@ -342,7 +342,7 @@ decl_module! {
impl<T: Config> Module<T> {
// *** Utility methods ***

pub fn ensure_admin(o: T::Origin) -> DispatchResult {
pub fn ensure_admin(o: T::RuntimeOrigin) -> DispatchResult {
T::AdminOrigin::try_origin(o)
.map(|_| ())
.or_else(ensure_root)?;
Expand Down Expand Up @@ -609,22 +609,22 @@ impl<T: Config> Module<T> {

/// Simple ensure origin for the bridge account
pub struct EnsureBridge<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> EnsureOrigin<T::Origin> for EnsureBridge<T> {
impl<T: Config> EnsureOrigin<T::RuntimeOrigin> for EnsureBridge<T> {
type Success = T::AccountId;
fn try_origin(o: T::Origin) -> Result<Self::Success, T::Origin> {
fn try_origin(o: T::RuntimeOrigin) -> Result<Self::Success, T::RuntimeOrigin> {
let bridge_id = <Module<T>>::account_id();
o.into().and_then(|o| match o {
frame_system::RawOrigin::Signed(who) if who == bridge_id => Ok(bridge_id),
r => Err(T::Origin::from(r)),
r => Err(T::RuntimeOrigin::from(r)),
})
}

/// Returns an outer origin capable of passing `try_origin` check.
///
/// ** Should be used for benchmarking only!!! **
#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> T::Origin {
T::Origin::from(
fn successful_origin() -> T::RuntimeOrigin {
T::RuntimeOrigin::from(
frame_system::RawOrigin::Signed(<Module<T>>::account_id())
)
}
Expand Down
12 changes: 6 additions & 6 deletions chainbridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ parameter_types! {

impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Call = Call;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
Expand All @@ -61,7 +61,7 @@ ord_parameter_types! {
impl pallet_balances::Config for Test {
type Balance = u64;
type DustRemoval = ();
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type MaxLocks = MaxLocks;
Expand All @@ -79,9 +79,9 @@ parameter_types! {
}

impl Config for Test {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Proposal = Call;
type Proposal = RuntimeCall;
type ChainId = TestChainId;
type ProposalLifetime = ProposalLifetime;
type PalletId = ChainbridgePalletId;
Expand Down
Loading

0 comments on commit 9b743e6

Please sign in to comment.