Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Merge from s2s (#647)
Browse files Browse the repository at this point in the history
* Add pangolin_to_millau_account_ownership_digest

* derive account

* use s2s branch

* anchor `darwinia-v0.11.1`

* optimize import

* optimize import

Co-authored-by: fewensa <[email protected]>
  • Loading branch information
aurexav and fewensa authored May 26, 2021
1 parent 0505dd0 commit 93520b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bin/node/bridge-primitives/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// --- substrate ---
use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState};
use bp_runtime::{ChainId, SourceAccount};
use bp_runtime::{ChainId, SourceAccount, MILLAU_CHAIN_ID};
use frame_support::{weights::Weight, Parameter};
use sp_core::H256;
use sp_runtime::{traits::Convert, RuntimeDebug};
Expand Down Expand Up @@ -111,6 +111,12 @@ impl bp_runtime::Chain for Pangolin {
type Header = Header;
}

/// todo: Reserved for other chains, don't forget change bridge_id
pub fn derive_account_from_pangolin_id(id: SourceAccount<AccountId>) -> AccountId {
let encoded_id = bp_runtime::derive_account_id(PANGOLIN_CHAIN_ID, id);
AccountIdConverter::convert(encoded_id)
}

/// We use this to get the account on Millau (target) which is derived from Pangolin's (source)
/// account. We do this so we can fund the derived account on Millau at Genesis to it can pay
/// transaction fees.
Expand All @@ -119,8 +125,8 @@ impl bp_runtime::Chain for Pangolin {
/// development seed phrase.
///
/// Note that this should only be used for testing.
pub fn derive_account_from_pangolin_id(id: SourceAccount<AccountId>) -> AccountId {
let encoded_id = bp_runtime::derive_account_id(PANGOLIN_CHAIN_ID, id);
pub fn derive_account_from_millau_id(id: SourceAccount<AccountId>) -> AccountId {
let encoded_id = bp_runtime::derive_account_id(MILLAU_CHAIN_ID, id);
AccountIdConverter::convert(encoded_id)
}

Expand Down
21 changes: 21 additions & 0 deletions bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub use pallet_sudo::Call as SudoCall;
// --- crates.io ---
use codec::{Decode, Encode};
// --- substrate ---
use bp_runtime::MILLAU_CHAIN_ID;
use bridge_runtime_common::messages::MessageBridge;
use frame_support::{
traits::{KeyOwnerProofSystem, OnRuntimeUpgrade},
Expand Down Expand Up @@ -230,6 +231,7 @@ use darwinia_staking_rpc_runtime_api::RuntimeDispatchInfo as StakingRuntimeDispa
use drml_primitives::*;
use dvm_rpc_runtime_api::TransactionStatus;
use impls::*;
use pangolin_bridge_primitives::PANGOLIN_CHAIN_ID;

/// The address format for describing accounts.
pub type Address = MultiAddress<AccountId, ()>;
Expand Down Expand Up @@ -855,3 +857,22 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
0
}
}

pub fn pangolin_to_millau_account_ownership_digest<Call, AccountId, SpecVersion>(
millau_call: &Call,
pangolin_account_id: AccountId,
millau_spec_version: SpecVersion,
) -> Vec<u8>
where
Call: Encode,
AccountId: Encode,
SpecVersion: Encode,
{
pallet_bridge_dispatch::account_ownership_digest(
millau_call,
pangolin_account_id,
millau_spec_version,
PANGOLIN_CHAIN_ID,
MILLAU_CHAIN_ID,
)
}

0 comments on commit 93520b8

Please sign in to comment.