-
Notifications
You must be signed in to change notification settings - Fork 47
feat: add deposits for DIP provider pallet #574
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
03d40fd
Update pallet-dip-provider to allow generic hooks
ntn-x2 ba54dab
WIP implementation for commitment storage deposit manager
ntn-x2 80c909e
Minor tweaks
ntn-x2 bde05bf
New pallet-deposit-storage compiling
ntn-x2 8d9a2bc
Provider runtime compiling
ntn-x2 8deb833
Remove temp file
ntn-x2 52af061
Cleanup
ntn-x2 e93d5c5
Add reclaim_deposit extrinsic
ntn-x2 f80e2d4
Minor chores
ntn-x2 8041942
Fix compilation issues
ntn-x2 8c749b1
Add extrinsic to add deposit
ntn-x2 ee31f76
Compiling
ntn-x2 841a138
Cleanups
ntn-x2 b305769
Half-way through deposit reclaiming hooks
ntn-x2 16f4a6f
Compiling
ntn-x2 68d6053
Cleanup
ntn-x2 66cbcbc
Make limits configurable by the runtime
ntn-x2 634c1c1
Replace Namespace with configurable type
ntn-x2 169c1ee
Fix provider runtime template
ntn-x2 24cb5ac
Simplify runtime API implementation
ntn-x2 f73778d
Open PR comments
ntn-x2 1841f0f
Remove unused constant
ntn-x2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| // If you feel like getting in touch with us, you can do so at [email protected] | ||
|
|
||
| use did::{DidRawOrigin, EnsureDidOrigin, KeyIdOf}; | ||
| use frame_system::EnsureSigned; | ||
| use pallet_did_lookup::linkable_account::LinkableAccountId; | ||
| use pallet_dip_provider::{traits::IdentityProvider, IdentityCommitmentVersion}; | ||
| use parity_scale_codec::{Decode, Encode}; | ||
|
|
@@ -25,24 +26,114 @@ use runtime_common::dip::{ | |
| merkle::{DidMerkleProofError, DidMerkleRootGenerator}, | ||
| }; | ||
| use scale_info::TypeInfo; | ||
| use sp_core::ConstU32; | ||
| use sp_std::vec::Vec; | ||
|
|
||
| use crate::{AccountId, DidIdentifier, Hash, Runtime, RuntimeEvent}; | ||
| use crate::{ | ||
| deposit::{DepositHooks, DepositNamespaces}, | ||
| AccountId, Balances, DidIdentifier, Hash, Runtime, RuntimeEvent, RuntimeHoldReason, | ||
| }; | ||
|
|
||
| pub mod runtime_api { | ||
| use super::*; | ||
|
|
||
| #[derive(Encode, Decode, TypeInfo)] | ||
| pub struct DipProofRequest { | ||
| pub(crate) identifier: DidIdentifier, | ||
| pub(crate) version: IdentityCommitmentVersion, | ||
| pub(crate) keys: Vec<KeyIdOf<Runtime>>, | ||
| pub(crate) accounts: Vec<LinkableAccountId>, | ||
| pub(crate) should_include_web3_name: bool, | ||
| } | ||
|
|
||
| #[derive(Encode, Decode, TypeInfo)] | ||
| pub enum DipProofError { | ||
| IdentityNotFound, | ||
| IdentityProviderError(<LinkedDidInfoProviderOf<Runtime> as IdentityProvider<DidIdentifier>>::Error), | ||
| MerkleProofError(DidMerkleProofError), | ||
| } | ||
| } | ||
|
|
||
| pub mod deposit { | ||
| use super::*; | ||
|
|
||
| use crate::{Balance, UNIT}; | ||
|
|
||
| use frame_support::traits::Get; | ||
| use pallet_deposit_storage::{ | ||
| traits::DepositStorageHooks, DepositEntryOf, DepositKeyOf, FixedDepositCollectorViaDepositsPallet, | ||
| }; | ||
| use parity_scale_codec::MaxEncodedLen; | ||
| use sp_core::{ConstU128, RuntimeDebug}; | ||
|
|
||
| #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Eq, RuntimeDebug)] | ||
| pub enum DepositNamespaces { | ||
| DipProvider, | ||
| } | ||
|
|
||
| #[derive(Encode, Decode, TypeInfo)] | ||
| pub struct RuntimeApiDipProofRequest { | ||
| pub(crate) identifier: DidIdentifier, | ||
| pub(crate) version: IdentityCommitmentVersion, | ||
| pub(crate) keys: Vec<KeyIdOf<Runtime>>, | ||
| pub(crate) accounts: Vec<LinkableAccountId>, | ||
| pub(crate) should_include_web3_name: bool, | ||
| pub struct DipProviderDepositNamespace; | ||
|
|
||
| impl Get<DepositNamespaces> for DipProviderDepositNamespace { | ||
| fn get() -> DepositNamespaces { | ||
| DepositNamespaces::DipProvider | ||
| } | ||
| } | ||
|
|
||
| pub const DEPOSIT_AMOUNT: Balance = 2 * UNIT; | ||
|
|
||
| pub type DepositCollectorHooks = | ||
| FixedDepositCollectorViaDepositsPallet<DipProviderDepositNamespace, ConstU128<DEPOSIT_AMOUNT>>; | ||
|
|
||
| pub enum CommitmentDepositRemovalHookError { | ||
| DecodeKey, | ||
| Internal, | ||
| } | ||
|
|
||
| impl From<CommitmentDepositRemovalHookError> for u16 { | ||
| fn from(value: CommitmentDepositRemovalHookError) -> Self { | ||
| match value { | ||
| CommitmentDepositRemovalHookError::DecodeKey => 0, | ||
| CommitmentDepositRemovalHookError::Internal => u16::MAX, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct DepositHooks; | ||
|
|
||
| impl DepositStorageHooks<Runtime> for DepositHooks { | ||
| type Error = CommitmentDepositRemovalHookError; | ||
|
|
||
| fn on_deposit_reclaimed( | ||
| _namespace: &<Runtime as pallet_deposit_storage::Config>::Namespace, | ||
| key: &DepositKeyOf<Runtime>, | ||
| _deposit: DepositEntryOf<Runtime>, | ||
| ) -> Result<(), Self::Error> { | ||
| let (identifier, commitment_version) = <(DidIdentifier, IdentityCommitmentVersion)>::decode(&mut &key[..]) | ||
| .map_err(|_| CommitmentDepositRemovalHookError::DecodeKey)?; | ||
| pallet_dip_provider::Pallet::<Runtime>::delete_identity_commitment_storage_entry( | ||
| &identifier, | ||
| commitment_version, | ||
| ) | ||
| .map_err(|_| { | ||
| log::error!( | ||
| "Should not fail to remove commitment for identifier {:#?} and version {commitment_version}", | ||
| identifier | ||
| ); | ||
| CommitmentDepositRemovalHookError::Internal | ||
| })?; | ||
| Ok(()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Encode, Decode, TypeInfo)] | ||
| pub enum RuntimeApiDipProofError { | ||
| IdentityNotFound, | ||
| IdentityProviderError(<LinkedDidInfoProviderOf<Runtime> as IdentityProvider<DidIdentifier>>::Error), | ||
| MerkleProofError(DidMerkleProofError), | ||
| impl pallet_deposit_storage::Config for Runtime { | ||
| type CheckOrigin = EnsureSigned<AccountId>; | ||
| type Currency = Balances; | ||
| type DepositHooks = DepositHooks; | ||
| type MaxKeyLength = ConstU32<256>; | ||
| type Namespace = DepositNamespaces; | ||
| type RuntimeEvent = RuntimeEvent; | ||
| type RuntimeHoldReason = RuntimeHoldReason; | ||
| } | ||
|
|
||
| impl pallet_dip_provider::Config for Runtime { | ||
|
|
@@ -54,5 +145,6 @@ impl pallet_dip_provider::Config for Runtime { | |
| type IdentityCommitmentGeneratorError = DidMerkleProofError; | ||
| type IdentityProvider = LinkedDidInfoProviderOf<Runtime>; | ||
| type IdentityProviderError = <LinkedDidInfoProviderOf<Runtime> as IdentityProvider<DidIdentifier>>::Error; | ||
| type ProviderHooks = deposit::DepositCollectorHooks; | ||
| type RuntimeEvent = RuntimeEvent; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| [package] | ||
| authors.workspace = true | ||
| documentation.workspace = true | ||
| edition.workspace = true | ||
| homepage.workspace = true | ||
| license-file.workspace = true | ||
| readme.workspace = true | ||
| repository.workspace = true | ||
| version.workspace = true | ||
| name = "pallet-deposit-storage" | ||
| description = "Stores all deposits under a single pallet, with suport for namespacing different deposit contexts." | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| # Substrate dependencies | ||
| frame-support.workspace = true | ||
| frame-system.workspace = true | ||
| kilt-support.workspace = true | ||
| pallet-dip-provider.workspace = true | ||
| parity-scale-codec = {workspace = true, features = ["derive"]} | ||
| scale-info = {workspace = true, features = ["derive"]} | ||
| sp-runtime.workspace = true | ||
| sp-std.workspace = true | ||
|
|
||
| log.workspace = true | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "kilt-support/std", | ||
| "pallet-dip-provider/std", | ||
| "parity-scale-codec/std", | ||
| "scale-info/std", | ||
| "sp-runtime/std", | ||
| "sp-std/std", | ||
| "log/std", | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.