Skip to content

Commit

Permalink
Add runtime-api call to get OmniAccount (#3148)
Browse files Browse the repository at this point in the history
* add skeleton

* add runtime api integration

* clippy

* Update parachain/pallets/omni-account/runtime-api/src/lib.rs

Co-authored-by: Francisco Silva <[email protected]>
Signed-off-by: Kai <[email protected]>

* fix compile

---------

Signed-off-by: Kai <[email protected]>
Co-authored-by: Jonathan Alvarez <[email protected]>
Co-authored-by: Francisco Silva <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent bc68f41 commit 17a8a94
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 1 deletion.
13 changes: 13 additions & 0 deletions parachain/Cargo.lock

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

2 changes: 2 additions & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
'pallets/vc-management',
'pallets/xcm-asset-manager',
'pallets/omni-account',
'pallets/omni-account/runtime-api',
'precompiles/*',
'runtime/litentry',
'runtime/rococo',
Expand Down Expand Up @@ -259,6 +260,7 @@ pallet-extrinsic-filter = { path = "pallets/extrinsic-filter", default-features
pallet-group = { path = "pallets/group", default-features = false }
pallet-identity-management = { path = "pallets/identity-management", default-features = false }
pallet-omni-account = { path = "pallets/omni-account", default-features = false }
pallet-omni-account-runtime-api = { path = "pallets/omni-account/runtime-api", default-features = false }
pallet-parachain-staking = { path = "pallets/parachain-staking", default-features = false }
pallet-score-staking = { path = "pallets/score-staking", default-features = false }
pallet-teebag = { path = "pallets/teebag", default-features = false }
Expand Down
23 changes: 23 additions & 0 deletions parachain/pallets/omni-account/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
authors = ['Trust Computing GmbH <[email protected]>']
version = "0.1.0"
edition = "2021"
homepage = 'https://litentry.com'
name = 'pallet-omni-account-runtime-api'
repository = 'https://github.com/litentry/litentry-parachain'

[dependencies]
parity-scale-codec = { workspace = true }
sp-api = { workspace = true }

core-primitives = { workspace = true }
pallet-omni-account = { workspace = true }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"sp-api/std",
"core-primitives/std",
"pallet-omni-account/std",
]
29 changes: 29 additions & 0 deletions parachain/pallets/omni-account/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Litentry is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]

use core_primitives::Identity;
use parity_scale_codec::Codec;

sp_api::decl_runtime_apis! {
pub trait OmniAccountApi<AccountId>
where
AccountId: Codec,
{
fn omni_account(id: Identity) -> AccountId;
}
}
12 changes: 12 additions & 0 deletions parachain/pallets/omni-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
/// Given an `Identity`, get its derived OmniAccount:
/// - if the given Identity is a member Identity of some AccountStore, get its belonged OmniAccount
/// - directly derive it otherwise
pub fn omni_account(identity: Identity) -> T::AccountId {
let hash = identity.hash();
if let Some(account) = MemberAccountHash::<T>::get(hash) {
account
} else {
T::OmniAccountConverter::convert(&identity)
}
}

fn do_create_account_store(identity: Identity) -> Result<MemberAccounts<T>, Error<T>> {
let hash = identity.hash();
let omni_account = T::OmniAccountConverter::convert(&identity);
Expand Down
2 changes: 2 additions & 0 deletions parachain/runtime/litentry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pallet-extrinsic-filter = { workspace = true }
pallet-group = { workspace = true }
pallet-identity-management = { workspace = true }
pallet-omni-account = { workspace = true }
pallet-omni-account-runtime-api = { workspace = true }
pallet-parachain-staking = { workspace = true }
pallet-score-staking = { workspace = true }
pallet-teebag = { workspace = true }
Expand Down Expand Up @@ -257,6 +258,7 @@ std = [
"pallet-extrinsic-filter/std",
"pallet-bitacross/std",
"pallet-omni-account/std",
"pallet-omni-account-runtime-api/std",
"pallet-identity-management/std",
"pallet-score-staking/std",
"pallet-teebag/std",
Expand Down
6 changes: 6 additions & 0 deletions parachain/runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,12 @@ impl_runtime_apis! {
}
}

impl pallet_omni_account_runtime_api::OmniAccountApi<Block, AccountId> for Runtime {
fn omni_account(identity: Identity) -> AccountId {
OmniAccount::omni_account(identity)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down
2 changes: 2 additions & 0 deletions parachain/runtime/paseo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pallet-extrinsic-filter = { workspace = true }
pallet-group = { workspace = true }
pallet-identity-management = { workspace = true }
pallet-omni-account = { workspace = true }
pallet-omni-account-runtime-api = { workspace = true }
pallet-parachain-staking = { workspace = true }
pallet-score-staking = { workspace = true }
pallet-teebag = { workspace = true }
Expand Down Expand Up @@ -268,6 +269,7 @@ std = [
"pallet-group/std",
"pallet-identity-management/std",
"pallet-omni-account/std",
"pallet-omni-account-runtime-api/std",
"pallet-score-staking/std",
"pallet-teebag/std",
"pallet-vc-management/std",
Expand Down
6 changes: 6 additions & 0 deletions parachain/runtime/paseo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,12 @@ impl_runtime_apis! {
}
}

impl pallet_omni_account_runtime_api::OmniAccountApi<Block, AccountId> for Runtime {
fn omni_account(identity: Identity) -> AccountId {
OmniAccount::omni_account(identity)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down
2 changes: 2 additions & 0 deletions parachain/runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pallet-extrinsic-filter = { workspace = true }
pallet-group = { workspace = true }
pallet-identity-management = { workspace = true }
pallet-omni-account = { workspace = true }
pallet-omni-account-runtime-api = { workspace = true }
pallet-parachain-staking = { workspace = true }
pallet-score-staking = { workspace = true }
pallet-teebag = { workspace = true }
Expand Down Expand Up @@ -268,6 +269,7 @@ std = [
"pallet-group/std",
"pallet-identity-management/std",
"pallet-omni-account/std",
"pallet-omni-account-runtime-api/std",
"pallet-score-staking/std",
"pallet-teebag/std",
"pallet-vc-management/std",
Expand Down
6 changes: 6 additions & 0 deletions parachain/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,12 @@ impl_runtime_apis! {
}
}

impl pallet_omni_account_runtime_api::OmniAccountApi<Block, AccountId> for Runtime {
fn omni_account(identity: Identity) -> AccountId {
OmniAccount::omni_account(identity)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down
1 change: 0 additions & 1 deletion tee-worker/bitacross/enclave-runtime/Cargo.lock

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

0 comments on commit 17a8a94

Please sign in to comment.