Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Use H160 as AccountId #230

Merged
merged 7 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
131 changes: 121 additions & 10 deletions Cargo.lock

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

12 changes: 8 additions & 4 deletions modules/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub mod pallet {
/// A type which can be turned into an AccountId from a 256-bit hash.
///
/// Used when deriving target chain AccountIds from source chain AccountIds.
type AccountIdConverter: sp_runtime::traits::Convert<sp_core::hash::H256, Self::AccountId>;
type AccountIdConverter: sp_runtime::traits::Convert<sp_core::hash::H160, Self::AccountId>;
/// The type is used to customize the dispatch call origin.
type IntoDispatchOrigin: IntoDispatchOrigin<
Self::AccountId,
Expand Down Expand Up @@ -489,7 +489,7 @@ mod tests {
use frame_support::{parameter_types, weights::Weight};
use frame_system::{mocking::*, EventRecord, Phase};
use scale_info::TypeInfo;
use sp_core::H256;
use sp_core::{H160, H256};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -530,8 +530,8 @@ mod tests {
}

pub struct AccountIdConverter;
impl sp_runtime::traits::Convert<H256, AccountId> for AccountIdConverter {
fn convert(hash: H256) -> AccountId {
impl sp_runtime::traits::Convert<H160, AccountId> for AccountIdConverter {
fn convert(hash: H160) -> AccountId {
hash.to_low_u64_ne()
}
}
Expand Down Expand Up @@ -926,17 +926,20 @@ mod tests {
#[test]
fn should_emit_event_for_unpaid_calls() {
new_test_ext().execute_with(|| {
println!("111");
let id = [0; 4];
let relayer_account = 1;

let mut message =
prepare_root_message(RuntimeCall::System(frame_system::Call::remark {
remark: vec![1, 2, 3],
}));

let weight = message.weight;
message.dispatch_fee_payment = DispatchFeePayment::AtTargetChain;

System::set_block_number(1);
println!("222");
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
let result = Dispatch::dispatch(
SOURCE_CHAIN_ID,
TARGET_CHAIN_ID,
Expand All @@ -945,6 +948,7 @@ mod tests {
Ok(message),
|_, _| Err(()),
);
println!("333");
assert_eq!(result.unspent_weight, weight);
assert!(!result.dispatch_result);

Expand Down
6 changes: 3 additions & 3 deletions modules/fee-market/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use frame_support::{
};
use frame_system::mocking::*;
use pallet_bridge_messages::outbound_lane;
use sp_core::H256;
use sp_core::{H160, H256};
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup, UniqueSaturatedInto},
Expand Down Expand Up @@ -399,8 +399,8 @@ impl MessageDispatch<AccountId, TestMessageFee> for TestMessageDispatch {
}

pub struct AccountIdConverter;
impl sp_runtime::traits::Convert<H256, AccountId> for AccountIdConverter {
fn convert(hash: H256) -> AccountId {
impl sp_runtime::traits::Convert<H160, AccountId> for AccountIdConverter {
fn convert(hash: H160) -> AccountId {
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
hash.to_low_u64_ne()
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use bp_messages::{
use bp_runtime::{BasicOperatingMode, ChainId, OwnedBridgeModule, Size};
// paritytech
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, log, traits::Get};
use sp_core::H256;
use sp_core::H160;
use sp_runtime::traits::Convert;
use sp_std::{cell::RefCell, marker::PhantomData, prelude::*};

Expand Down Expand Up @@ -167,7 +167,7 @@ pub mod pallet {
/// A type which can be turned into an AccountId from a 256-bit hash.
///
/// Used when deriving the shared relayer fund account.
type AccountIdConverter: sp_runtime::traits::Convert<sp_core::hash::H256, Self::AccountId>;
type AccountIdConverter: sp_runtime::traits::Convert<sp_core::hash::H160, Self::AccountId>;

// Types that are used by outbound_lane (on source chain).

Expand Down Expand Up @@ -692,7 +692,7 @@ pub use pallet::*;
/// This account is passed to `MessageDeliveryAndDispatchPayment` trait, and depending
/// on the implementation it can be used to store relayers rewards.
/// See [`InstantCurrencyPayments`] for a concrete implementation.
pub fn relayer_fund_account_id<AccountId, AccountIdConverter: Convert<H256, AccountId>>(
pub fn relayer_fund_account_id<AccountId, AccountIdConverter: Convert<H160, AccountId>>(
) -> AccountId {
let encoded_id = bp_runtime::derive_relayer_fund_account_id(bp_runtime::NO_INSTANCE_ID);
AccountIdConverter::convert(encoded_id)
Expand Down
4 changes: 2 additions & 2 deletions modules/messages/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub struct TestPayload {
}

pub struct AccountIdConverter;
impl sp_runtime::traits::Convert<H256, AccountId> for AccountIdConverter {
fn convert(hash: H256) -> AccountId {
impl sp_runtime::traits::Convert<H160, AccountId> for AccountIdConverter {
fn convert(hash: H160) -> AccountId {
hash.to_low_u64_ne()
}
}
Expand Down
4 changes: 4 additions & 0 deletions primitives/darwinia-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ version = "0.1.0"
# crates.io
parity-scale-codec = { version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
# moonbeam
account = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" }
# paritytech
bp-messages = { default-features = false, path = "../messages" }
bp-runtime = { default-features = false, path = "../runtime" }
Expand All @@ -25,6 +27,8 @@ std = [
# crates.io
"parity-scale-codec/std",
"scale-info/std",
# moonbeam
"account/std",
# paritytech
"bp-messages/std",
"bp-runtime/std",
Expand Down
Loading