Skip to content
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

MESH-1166/Scope of Claim refactor #560

Merged
merged 29 commits into from Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7d38a99
first go
CJP10 Aug 25, 2020
a8fd841
Merge branch 'develop' into MESH-1166
CJP10 Aug 26, 2020
f929152
Update base.rs
CJP10 Aug 26, 2020
5e4928f
Merge branch 'develop' into MESH-1166
CJP10 Aug 26, 2020
8e6a851
Merge branch 'develop' into MESH-1166
CJP10 Aug 27, 2020
163ec91
fix non-settlement tests
CJP10 Aug 27, 2020
10b97ae
Merge branch 'develop' into MESH-1166
CJP10 Aug 28, 2020
a3b5b7d
Merge branch 'develop' into MESH-1166
CJP10 Aug 31, 2020
479b0ed
Merge branch 'develop' into MESH-1166
CJP10 Aug 31, 2020
ffdb56d
Merge branch 'develop' into MESH-1166
CJP10 Aug 31, 2020
605fb0f
first go at upgrade
CJP10 Sep 2, 2020
fa3c705
first go at upgrade
CJP10 Sep 2, 2020
ff45d98
fix bad submodule
CJP10 Sep 2, 2020
e2eb512
formatting
CJP10 Sep 2, 2020
3ac1166
fix bad merge
CJP10 Sep 2, 2020
d90abf7
formatting
CJP10 Sep 2, 2020
49a5e84
submodule bump
CJP10 Sep 2, 2020
ee1b78c
Update primitives/src/identity_claim.rs
CJP10 Sep 3, 2020
b96b371
Merge branch 'develop' into MESH-1166
CJP10 Sep 3, 2020
d862ff2
upgrade compliance manager storage
CJP10 Sep 3, 2020
9e45f1e
update schema
CJP10 Sep 3, 2020
64fd1ab
Merge branch 'develop' into MESH-1166
adamdossa Sep 7, 2020
35a263b
Merge branch 'develop' into MESH-1166
CJP10 Sep 7, 2020
575c15c
Merge branch 'develop' into MESH-1166
CJP10 Sep 8, 2020
9a586ea
wip
CJP10 Sep 8, 2020
c57a270
Merge branch 'MESH-1166' of github.com:PolymathNetwork/Polymesh into …
CJP10 Sep 8, 2020
3c20bcf
wip
CJP10 Sep 8, 2020
f8bbe6a
Merge branch 'develop' into MESH-1166
CJP10 Sep 8, 2020
3feffee
Merge branch 'develop' into MESH-1166
CJP10 Sep 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion external/cryptography
7 changes: 4 additions & 3 deletions pallets/compliance-manager/src/lib.rs
Expand Up @@ -95,9 +95,10 @@ use polymesh_common_utilities::{
Context,
};
use polymesh_primitives::{
proposition, Claim, ClaimType, Condition, ConditionType, IdentityId, Ticker,
proposition, Claim, ClaimType, Condition, ConditionType, IdentityId, Scope, Ticker,
};
use polymesh_primitives_derive::Migrate;

#[cfg(feature = "std")]
use sp_runtime::{Deserialize, Serialize};
use sp_std::{
Expand Down Expand Up @@ -601,7 +602,7 @@ impl<T: Trait> Module<T> {
issuers
.iter()
.flat_map(|issuer| {
<identity::Module<T>>::fetch_claim(target, claim_type, *issuer, scope)
<identity::Module<T>>::fetch_claim(target, claim_type, *issuer, scope.clone())
Centril marked this conversation as resolved.
Show resolved Hide resolved
.map(|id_claim| id_claim.claim)
})
.collect::<Vec<_>>()
Expand All @@ -612,7 +613,7 @@ impl<T: Trait> Module<T> {
fn fetch_confidential_claims(id: IdentityId, ticker: &Ticker) -> Vec<Claim> {
let claim_type = ClaimType::InvestorZKProof;
// NOTE: Ticker lenght is less by design that IdentityId.
let asset_scope = IdentityId::try_from(ticker.as_slice()).unwrap_or_default();
let asset_scope = Scope::from(*ticker);

<identity::Module<T>>::fetch_claim(id, claim_type, id, Some(asset_scope))
.into_iter()
Expand Down
17 changes: 16 additions & 1 deletion pallets/identity/src/lib.rs
Expand Up @@ -146,6 +146,12 @@ pub struct Claim2ndKey {
pub scope: Option<Scope>,
}

#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, PartialOrd, Ord)]
pub struct Claim2ndKeyOld {
maxsam4 marked this conversation as resolved.
Show resolved Hide resolved
pub issuer: IdentityId,
pub scope: Option<IdentityId>,
}

#[derive(Encode, Decode, Clone, PartialEq, Eq, Default, Debug)]
pub struct BatchAddClaimItem<M> {
pub target: IdentityId,
Expand Down Expand Up @@ -267,6 +273,15 @@ decl_module! {
fn deposit_event() = default;

fn on_runtime_upgrade() -> Weight {
use frame_support::migration::{StorageIterator, put_storage_value};
// Covert old scopes to new scopes
for (key, value) in StorageIterator::<Claim2ndKeyOld>::new(b"Identity", b"Claims").drain() {
let new = Claim2ndKey {
issuer: value.issuer,
scope: value.scope.map(|scope| Scope::Identity(scope)),
};
put_storage_value(b"Identity", b"Claims", &key, new);
CJP10 marked this conversation as resolved.
Show resolved Hide resolved
}
// Rename "master" to "primary".
<CddAuthForPrimaryKeyRotation>::put(<CddAuthForMasterKeyRotation>::take());

Expand Down Expand Up @@ -1817,7 +1832,7 @@ impl<T: Trait> Module<T> {
let claim_type = claim.claim_type();
let scope = claim.as_scope().cloned();
let last_update_date = <pallet_timestamp::Module<T>>::get().saturated_into::<u64>();
let issuance_date = Self::fetch_claim(target, claim_type, issuer, scope)
let issuance_date = Self::fetch_claim(target, claim_type, issuer, scope.clone())
.map_or(last_update_date, |id_claim| id_claim.issuance_date);

let expiry = expiry.into_iter().map(|m| m.saturated_into::<u64>()).next();
Expand Down
26 changes: 13 additions & 13 deletions pallets/runtime/tests/src/asset_test.rs
Expand Up @@ -2073,23 +2073,23 @@ fn test_weights_for_is_valid_transfer() {
ticker,
vec![
Condition {
condition_type: ConditionType::IsPresent(Claim::Accredited(ticker_id)),
condition_type: ConditionType::IsPresent(Claim::Accredited(ticker_id.into())),
issuers: vec![eve_did]
},
Condition {
condition_type: ConditionType::IsAbsent(Claim::BuyLockup(ticker_id)),
condition_type: ConditionType::IsAbsent(Claim::BuyLockup(ticker_id.into())),
issuers: vec![eve_did]
}
],
vec![
Condition {
condition_type: ConditionType::IsPresent(Claim::Accredited(ticker_id)),
condition_type: ConditionType::IsPresent(Claim::Accredited(ticker_id.into())),
issuers: vec![eve_did]
},
Condition {
condition_type: ConditionType::IsAnyOf(vec![
Claim::BuyLockup(ticker_id),
Claim::KnowYourCustomer(ticker_id)
Claim::BuyLockup(ticker_id.into()),
Claim::KnowYourCustomer(ticker_id.into())
]),
issuers: vec![eve_did]
}
Expand All @@ -2098,14 +2098,14 @@ fn test_weights_for_is_valid_transfer() {

// Providing claim to sender and receiver
// For Alice
assert_add_claim!(eve_signed.clone(), alice_did, Claim::Accredited(alice_did));
assert_add_claim!(eve_signed.clone(), alice_did, Claim::BuyLockup(ticker_id));
assert_add_claim!(eve_signed.clone(), alice_did, Claim::Accredited(alice_did.into()));
assert_add_claim!(eve_signed.clone(), alice_did, Claim::BuyLockup(ticker_id.into()));
// For Bob
assert_add_claim!(eve_signed.clone(), bob_did, Claim::Accredited(ticker_id));
assert_add_claim!(eve_signed.clone(), bob_did, Claim::Accredited(ticker_id.into()));
assert_add_claim!(
eve_signed.clone(),
bob_did,
Claim::KnowYourCustomer(ticker_id)
Claim::KnowYourCustomer(ticker_id.into())
);

// Add Tms
Expand Down Expand Up @@ -2147,8 +2147,8 @@ fn test_weights_for_is_valid_transfer() {
.1;
assert!(matches!(result, weight_from_verify_transfer)); // Only sender rules are processed.

assert_revoke_claim!(eve_signed.clone(), alice_did, Claim::BuyLockup(ticker_id));
assert_add_claim!(eve_signed.clone(), alice_did, Claim::Accredited(ticker_id));
assert_revoke_claim!(eve_signed.clone(), alice_did, Claim::BuyLockup(ticker_id.into()));
assert_add_claim!(eve_signed.clone(), alice_did, Claim::Accredited(ticker_id.into()));

let result =
Asset::_is_valid_transfer(&ticker, alice, Some(alice_did), Some(bob_did), 100)
Expand All @@ -2172,11 +2172,11 @@ fn test_weights_for_is_valid_transfer() {
alice_signed.clone(),
ticker,
vec![Condition {
condition_type: ConditionType::IsPresent(Claim::Exempted(ticker_id)),
condition_type: ConditionType::IsPresent(Claim::Exempted(ticker_id.into())),
issuers: vec![eve_did]
}],
vec![Condition {
condition_type: ConditionType::IsPresent(Claim::Blocked(ticker_id)),
condition_type: ConditionType::IsPresent(Claim::Blocked(ticker_id.into())),
issuers: vec![eve_did]
}]
));
Expand Down