Skip to content

Commit 34e0286

Browse files
Soften CDD requirements part II; Add TransferWithMemo event (#1856)
* Soften CDD requirements; Add TransferWithMemo event * Remove clone * Bump version; Remove call permissions for base_remove_paying_key and base_update_polyx_limit * Bump .toml version * Update cargo.lock
1 parent e3dce83 commit 34e0286

File tree

10 files changed

+47
-74
lines changed

10 files changed

+47
-74
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "polymesh"
3-
version = "7.3.0"
3+
version = "7.4.0"
44
authors = ["PolymeshAssociation"]
55
build = "build.rs"
66
edition = "2021"
@@ -359,8 +359,8 @@ substrate-build-script-utils = { version = "3.0.0" }
359359
[features]
360360
default = ["std"]
361361
disable_fees = [
362-
"pallet-transaction-payment/disable_fees",
363-
"polymesh-runtime-develop/disable_fees",
362+
"pallet-transaction-payment/disable_fees",
363+
"polymesh-runtime-develop/disable_fees",
364364
"polymesh-runtime-mainnet/disable_fees",
365365
"polymesh-runtime-testnet/disable_fees",
366366
]

pallets/balances/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,13 @@ pub mod pallet {
319319
/// Final argument indicates the destination balance type.
320320
/// \[from, to, balance, destination_status]
321321
ReserveRepatriated(T::AccountId, T::AccountId, Balance, Status),
322+
/// Transfer with memo succeeded.
323+
TransferWithMemo {
324+
from: T::AccountId,
325+
to: T::AccountId,
326+
amount: Balance,
327+
memo: Option<Memo>,
328+
},
322329
}
323330

324331
#[pallet::pallet]
@@ -878,6 +885,13 @@ impl<T: Config> Pallet<T> {
878885
let transactor_id = T::IdentityFn::get_identity(transactor);
879886
let dest_id = T::IdentityFn::get_identity(dest);
880887

888+
Self::deposit_event(Event::TransferWithMemo {
889+
from: transactor.clone(),
890+
to: dest.clone(),
891+
amount: value,
892+
memo: memo.clone(),
893+
});
894+
881895
Self::deposit_event(Event::Transfer(
882896
transactor_id,
883897
transactor.clone(),

pallets/relayer/src/lib.rs

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ use frame_support::{
5151
weights::Weight,
5252
};
5353
use frame_system::ensure_signed;
54-
use pallet_identity::PermissionedCallOriginData;
5554
use polymesh_primitives::{
5655
extract_auth, traits::SubsidiserTrait, AuthorizationData, Balance, EventDid, IdentityId,
5756
Signatory, TransactionError,
@@ -305,6 +304,8 @@ pub mod pallet {
305304
Overflow,
306305
/// The extrinsic expected a different `AuthorizationType` than what the `data.auth_type()` is.
307306
BadAuthorizationType,
307+
/// The caller's identity was not found.
308+
IdentityNotFound,
308309
}
309310
}
310311

@@ -324,7 +325,7 @@ impl<T: Config> Pallet<T> {
324325
fn base_accept_paying_key(origin: T::RuntimeOrigin, auth_id: u64) -> DispatchResult {
325326
let caller_key = ensure_signed(origin)?;
326327
let user_did =
327-
<Identity<T>>::get_identity(&caller_key).ok_or(Error::<T>::UserKeyCddMissing)?;
328+
<Identity<T>>::get_identity(&caller_key).ok_or(Error::<T>::IdentityNotFound)?;
328329
let signer = Signatory::Account(caller_key.clone());
329330

330331
<Identity<T>>::accept_auth_with(&signer, auth_id, |data, auth_by| -> DispatchResult {
@@ -357,17 +358,15 @@ impl<T: Config> Pallet<T> {
357358
user_key: T::AccountId,
358359
paying_key: T::AccountId,
359360
) -> DispatchResult {
360-
let PermissionedCallOriginData {
361-
sender,
362-
primary_did: sender_did,
363-
..
364-
} = <Identity<T>>::ensure_origin_call_permissions(origin)?;
361+
let caller_key = ensure_signed(origin)?;
362+
let caller_did =
363+
Identity::<T>::get_identity(&caller_key).ok_or(Error::<T>::IdentityNotFound)?;
365364

366365
// Allow: `origin == user_key` or `origin == paying_key`.
367-
if sender != user_key && sender != paying_key {
366+
if caller_key != user_key && caller_key != paying_key {
368367
// Allow: `origin == primary key of user_key's identity`.
369368
ensure!(
370-
<Identity<T>>::get_identity(&user_key) == Some(sender_did),
369+
Identity::<T>::get_identity(&user_key) == Some(caller_did),
371370
Error::<T>::NotAuthorizedForUserKey
372371
);
373372
}
@@ -384,7 +383,7 @@ impl<T: Config> Pallet<T> {
384383
<Subsidies<T>>::remove(&user_key);
385384

386385
Self::deposit_event(Event::RemovedPayingKey(
387-
sender_did.for_event(),
386+
caller_did.for_event(),
388387
user_key,
389388
paying_key,
390389
));
@@ -397,14 +396,12 @@ impl<T: Config> Pallet<T> {
397396
action: UpdateAction,
398397
amount: Balance,
399398
) -> DispatchResult {
400-
let PermissionedCallOriginData {
401-
sender: paying_key,
402-
primary_did: paying_did,
403-
..
404-
} = <Identity<T>>::ensure_origin_call_permissions(origin)?;
399+
let caller_key = ensure_signed(origin)?;
400+
let caller_did =
401+
Identity::<T>::get_identity(&caller_key).ok_or(Error::<T>::IdentityNotFound)?;
405402

406403
// Check if the current paying key matches.
407-
let mut subsidy = Self::ensure_is_paying_key(&user_key, &paying_key)?;
404+
let mut subsidy = Self::ensure_is_paying_key(&user_key, &caller_key)?;
408405

409406
// Update polyx limit.
410407
let old_remaining = subsidy.remaining;
@@ -421,9 +418,9 @@ impl<T: Config> Pallet<T> {
421418
<Subsidies<T>>::insert(&user_key, subsidy);
422419

423420
Self::deposit_event(Event::UpdatedPolyxLimit(
424-
paying_did.for_event(),
421+
caller_did.for_event(),
425422
user_key,
426-
paying_key,
423+
caller_key,
427424
new_remaining,
428425
old_remaining,
429426
));
@@ -457,15 +454,6 @@ impl<T: Config> Pallet<T> {
457454
Ok(auth_id)
458455
}
459456

460-
/// Check if the `key` has a valid CDD.
461-
fn key_has_valid_cdd(key: &T::AccountId) -> bool {
462-
if let Some(did) = <Identity<T>>::get_identity(key) {
463-
<Identity<T>>::has_valid_cdd(did)
464-
} else {
465-
false
466-
}
467-
}
468-
469457
/// Ensure that `paying_key` is the paying key for `user_key`.
470458
fn ensure_is_paying_key(
471459
user_key: &T::AccountId,
@@ -495,16 +483,6 @@ impl<T: Config> Pallet<T> {
495483
Error::<T>::NotAuthorizedForPayingKey
496484
);
497485

498-
// Ensure both user_key and paying_key have valid CDD.
499-
ensure!(
500-
<Identity<T>>::has_valid_cdd(user_did),
501-
Error::<T>::UserKeyCddMissing
502-
);
503-
ensure!(
504-
Self::key_has_valid_cdd(&paying_key),
505-
Error::<T>::PayingKeyCddMissing
506-
);
507-
508486
// Remove existing subsidy for the user_key, if it exists.
509487
if let Some(subsidy) = <Subsidies<T>>::get(&user_key) {
510488
// Decrease old paying key usage.

pallets/runtime/develop/src/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
5555
authoring_version: 1,
5656
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
5757
// N.B. `d` is unpinned from the binary version
58-
spec_version: 7_003_003,
58+
spec_version: 7_004_000,
5959
impl_version: 0,
6060
apis: RUNTIME_API_VERSIONS,
6161
transaction_version: 7,

pallets/runtime/mainnet/src/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
5353
authoring_version: 1,
5454
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
5555
// N.B. `d` is unpinned from the binary version
56-
spec_version: 7_003_003,
56+
spec_version: 7_004_000,
5757
impl_version: 0,
5858
apis: RUNTIME_API_VERSIONS,
5959
transaction_version: 7,

pallets/runtime/testnet/src/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
5555
authoring_version: 1,
5656
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
5757
// N.B. `d` is unpinned from the binary version
58-
spec_version: 7_003_003,
58+
spec_version: 7_004_000,
5959
impl_version: 0,
6060
apis: RUNTIME_API_VERSIONS,
6161
transaction_version: 7,

pallets/runtime/tests/src/relayer_test.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,13 @@ fn do_user_remove_paying_key_test() {
357357
}
358358

359359
#[test]
360-
fn relayer_user_key_missing_cdd_test() {
360+
fn relayer_user_key_without_cdd_test() {
361361
ExtBuilder::default()
362362
.monied(true)
363363
.build()
364-
.execute_with(&do_relayer_user_key_missing_cdd_test);
364+
.execute_with(&do_relayer_user_key_without_cdd_test);
365365
}
366-
fn do_relayer_user_key_missing_cdd_test() {
366+
fn do_relayer_user_key_without_cdd_test() {
367367
let alice = User::new(AccountKeyring::Alice);
368368
let bob_acc = AccountKeyring::Bob.to_account_id();
369369
let (bob_sign, _) = make_account_without_cdd(bob_acc.clone()).unwrap();
@@ -377,20 +377,17 @@ fn do_relayer_user_key_missing_cdd_test() {
377377

378378
// Bob tries to accept the paying key, without having a CDD.
379379
let auth_id = get_last_auth_id(&Signatory::Account(bob_acc.clone()));
380-
assert_eq!(
381-
Relayer::accept_paying_key(bob_sign, auth_id),
382-
Err(Error::UserKeyCddMissing.into()),
383-
);
380+
assert_ok!(Relayer::accept_paying_key(bob_sign, auth_id),);
384381
}
385382

386383
#[test]
387-
fn relayer_paying_key_missing_cdd_test() {
384+
fn relayer_paying_key_without_cdd_test() {
388385
ExtBuilder::default()
389386
.monied(true)
390387
.build()
391-
.execute_with(&do_relayer_paying_key_missing_cdd_test);
388+
.execute_with(&do_relayer_paying_key_without_cdd_test);
392389
}
393-
fn do_relayer_paying_key_missing_cdd_test() {
390+
fn do_relayer_paying_key_without_cdd_test() {
394391
let alice = User::new(AccountKeyring::Alice);
395392
let bob_acc = AccountKeyring::Bob.to_account_id();
396393
let (bob_sign, _) = make_account_without_cdd(bob_acc.clone()).unwrap();
@@ -401,10 +398,7 @@ fn do_relayer_paying_key_missing_cdd_test() {
401398
// Alice tries to accept the paying key, but the paying key
402399
// is without a CDD.
403400
let auth_id = get_last_auth_id(&Signatory::Account(alice.acc()));
404-
assert_eq!(
405-
Relayer::accept_paying_key(alice.origin(), auth_id),
406-
Err(Error::PayingKeyCddMissing.into()),
407-
);
401+
assert_ok!(Relayer::accept_paying_key(alice.origin(), auth_id),);
408402
}
409403

410404
#[test]

pallets/runtime/tests/src/utility_test.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ fn batch_optimistic_failures_listed() {
164164
);
165165
// skip Balances::Transfer event.
166166
events.pop().unwrap();
167+
events.pop().unwrap();
168+
167169
assert_eq!(
168170
events.pop().unwrap().event,
169171
EventTest::Utility(Event::ItemFailed { error: ERROR })
@@ -284,16 +286,6 @@ fn _relay_unhappy_cases() {
284286
Error::InvalidSignature
285287
);
286288

287-
assert_noop!(
288-
Utility::relay_tx(
289-
origin.clone(),
290-
bob.clone(),
291-
AccountKeyring::Bob.sign(&transaction.encode()).into(),
292-
transaction.clone()
293-
),
294-
Error::TargetCddMissing
295-
);
296-
297289
let _ = register_keyring_account_with_balance(AccountKeyring::Bob, 1_000).unwrap();
298290

299291
let transaction = UniqueCall::new(

pallets/utility/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use pallet_balances::Config as BalancesConfig;
8888
use pallet_identity::{Config as IdentityConfig, Context};
8989
use pallet_permissions::with_call_metadata;
9090
use polymesh_common_utilities::identity::AuthorizationNonce;
91-
use polymesh_primitives::{crypto::verify_signature, traits::CheckCdd, IdentityId};
91+
use polymesh_primitives::{crypto::verify_signature, IdentityId};
9292

9393
type Identity<T> = pallet_identity::Pallet<T>;
9494

@@ -362,11 +362,6 @@ pub mod pallet {
362362
Error::<T>::InvalidSignature
363363
);
364364

365-
ensure!(
366-
T::CddChecker::check_key_cdd(&target),
367-
Error::<T>::TargetCddMissing
368-
);
369-
370365
<Nonces<T>>::insert(target.clone(), target_nonce + 1);
371366

372367
let info = call.call.get_dispatch_info();

0 commit comments

Comments
 (0)