mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Add field names to pallet Event variants (#9993)
* convert pallet-assets events to struct types * updated events of a couple pallets * updated pallet event field names * update pallet event field names * updated events in test files * cargo fmt * minorfixes * fix assertion error * minor fix * formatting fix * fmt
This commit is contained in:
@@ -346,7 +346,7 @@ pub mod pallet {
|
||||
|
||||
(account.free, account.reserved)
|
||||
})?;
|
||||
Self::deposit_event(Event::BalanceSet(who, free, reserved));
|
||||
Self::deposit_event(Event::BalanceSet { who, free, reserved });
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
@@ -454,31 +454,33 @@ pub mod pallet {
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config<I>, I: 'static = ()> {
|
||||
/// An account was created with some free balance. \[account, free_balance\]
|
||||
Endowed(T::AccountId, T::Balance),
|
||||
/// An account was created with some free balance.
|
||||
Endowed { account: T::AccountId, free_balance: T::Balance },
|
||||
/// An account was removed whose balance was non-zero but below ExistentialDeposit,
|
||||
/// resulting in an outright loss. \[account, balance\]
|
||||
DustLost(T::AccountId, T::Balance),
|
||||
/// Transfer succeeded. \[from, to, value\]
|
||||
Transfer(T::AccountId, T::AccountId, T::Balance),
|
||||
/// A balance was set by root. \[who, free, reserved\]
|
||||
BalanceSet(T::AccountId, T::Balance, T::Balance),
|
||||
/// Some balance was reserved (moved from free to reserved). \[who, value\]
|
||||
Reserved(T::AccountId, T::Balance),
|
||||
/// Some balance was unreserved (moved from reserved to free). \[who, value\]
|
||||
Unreserved(T::AccountId, T::Balance),
|
||||
/// resulting in an outright loss.
|
||||
DustLost { account: T::AccountId, amount: T::Balance },
|
||||
/// Transfer succeeded.
|
||||
Transfer { from: T::AccountId, to: T::AccountId, amount: T::Balance },
|
||||
/// A balance was set by root.
|
||||
BalanceSet { who: T::AccountId, free: T::Balance, reserved: T::Balance },
|
||||
/// Some balance was reserved (moved from free to reserved).
|
||||
Reserved { who: T::AccountId, amount: T::Balance },
|
||||
/// Some balance was unreserved (moved from reserved to free).
|
||||
Unreserved { who: T::AccountId, amount: T::Balance },
|
||||
/// Some balance was moved from the reserve of the first account to the second account.
|
||||
/// Final argument indicates the destination balance type.
|
||||
/// \[from, to, balance, destination_status\]
|
||||
ReserveRepatriated(T::AccountId, T::AccountId, T::Balance, Status),
|
||||
/// Some amount was deposited into the account (e.g. for transaction fees). \[who,
|
||||
/// deposit\]
|
||||
Deposit(T::AccountId, T::Balance),
|
||||
/// Some amount was withdrawn from the account (e.g. for transaction fees). \[who, value\]
|
||||
Withdraw(T::AccountId, T::Balance),
|
||||
/// Some amount was removed from the account (e.g. for misbehavior). \[who,
|
||||
/// amount_slashed\]
|
||||
Slashed(T::AccountId, T::Balance),
|
||||
ReserveRepatriated {
|
||||
from: T::AccountId,
|
||||
to: T::AccountId,
|
||||
amount: T::Balance,
|
||||
destination_status: Status,
|
||||
},
|
||||
/// Some amount was deposited (e.g. for transaction fees).
|
||||
Deposit { who: T::AccountId, amount: T::Balance },
|
||||
/// Some amount was withdrawn from the account (e.g. for transaction fees).
|
||||
Withdraw { who: T::AccountId, amount: T::Balance },
|
||||
/// Some amount was removed from the account (e.g. for misbehavior).
|
||||
Slashed { who: T::AccountId, amount: T::Balance },
|
||||
}
|
||||
|
||||
/// Old name generated by `decl_event`.
|
||||
@@ -742,7 +744,7 @@ pub struct DustCleaner<T: Config<I>, I: 'static = ()>(
|
||||
impl<T: Config<I>, I: 'static> Drop for DustCleaner<T, I> {
|
||||
fn drop(&mut self) {
|
||||
if let Some((who, dust)) = self.0.take() {
|
||||
Pallet::<T, I>::deposit_event(Event::DustLost(who, dust.peek()));
|
||||
Pallet::<T, I>::deposit_event(Event::DustLost { account: who, amount: dust.peek() });
|
||||
T::DustRemoval::on_unbalanced(dust);
|
||||
}
|
||||
}
|
||||
@@ -939,7 +941,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
});
|
||||
result.map(|(maybe_endowed, maybe_dust, result)| {
|
||||
if let Some(endowed) = maybe_endowed {
|
||||
Self::deposit_event(Event::Endowed(who.clone(), endowed));
|
||||
Self::deposit_event(Event::Endowed { account: who.clone(), free_balance: endowed });
|
||||
}
|
||||
let dust_cleaner = DustCleaner(maybe_dust.map(|dust| (who.clone(), dust)));
|
||||
(result, dust_cleaner)
|
||||
@@ -1051,12 +1053,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
},
|
||||
)?;
|
||||
|
||||
Self::deposit_event(Event::ReserveRepatriated(
|
||||
slashed.clone(),
|
||||
beneficiary.clone(),
|
||||
actual,
|
||||
status,
|
||||
));
|
||||
Self::deposit_event(Event::ReserveRepatriated {
|
||||
from: slashed.clone(),
|
||||
to: beneficiary.clone(),
|
||||
amount: actual,
|
||||
destination_status: status,
|
||||
});
|
||||
Ok(actual)
|
||||
}
|
||||
}
|
||||
@@ -1109,7 +1111,7 @@ impl<T: Config<I>, I: 'static> fungible::Mutate<T::AccountId> for Pallet<T, I> {
|
||||
Ok(())
|
||||
})?;
|
||||
TotalIssuance::<T, I>::mutate(|t| *t += amount);
|
||||
Self::deposit_event(Event::Deposit(who.clone(), amount));
|
||||
Self::deposit_event(Event::Deposit { who: who.clone(), amount });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1130,7 +1132,7 @@ impl<T: Config<I>, I: 'static> fungible::Mutate<T::AccountId> for Pallet<T, I> {
|
||||
},
|
||||
)?;
|
||||
TotalIssuance::<T, I>::mutate(|t| *t -= actual);
|
||||
Self::deposit_event(Event::Withdraw(who.clone(), amount));
|
||||
Self::deposit_event(Event::Withdraw { who: who.clone(), amount });
|
||||
Ok(actual)
|
||||
}
|
||||
}
|
||||
@@ -1151,7 +1153,11 @@ impl<T: Config<I>, I: 'static> fungible::Unbalanced<T::AccountId> for Pallet<T,
|
||||
fn set_balance(who: &T::AccountId, amount: Self::Balance) -> DispatchResult {
|
||||
Self::mutate_account(who, |account| {
|
||||
account.free = amount;
|
||||
Self::deposit_event(Event::BalanceSet(who.clone(), account.free, account.reserved));
|
||||
Self::deposit_event(Event::BalanceSet {
|
||||
who: who.clone(),
|
||||
free: account.free,
|
||||
reserved: account.reserved,
|
||||
});
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1531,7 +1537,11 @@ where
|
||||
)?;
|
||||
|
||||
// Emit transfer event.
|
||||
Self::deposit_event(Event::Transfer(transactor.clone(), dest.clone(), value));
|
||||
Self::deposit_event(Event::Transfer {
|
||||
from: transactor.clone(),
|
||||
to: dest.clone(),
|
||||
amount: value,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1595,10 +1605,10 @@ where
|
||||
},
|
||||
) {
|
||||
Ok((imbalance, not_slashed)) => {
|
||||
Self::deposit_event(Event::Slashed(
|
||||
who.clone(),
|
||||
value.saturating_sub(not_slashed),
|
||||
));
|
||||
Self::deposit_event(Event::Slashed {
|
||||
who: who.clone(),
|
||||
amount: value.saturating_sub(not_slashed),
|
||||
});
|
||||
return (imbalance, not_slashed)
|
||||
},
|
||||
Err(_) => (),
|
||||
@@ -1625,7 +1635,7 @@ where
|
||||
|account, is_new| -> Result<Self::PositiveImbalance, DispatchError> {
|
||||
ensure!(!is_new, Error::<T, I>::DeadAccount);
|
||||
account.free = account.free.checked_add(&value).ok_or(ArithmeticError::Overflow)?;
|
||||
Self::deposit_event(Event::Deposit(who.clone(), value));
|
||||
Self::deposit_event(Event::Deposit { who: who.clone(), amount: value });
|
||||
Ok(PositiveImbalance::new(value))
|
||||
},
|
||||
)
|
||||
@@ -1658,7 +1668,7 @@ where
|
||||
None => return Ok(Self::PositiveImbalance::zero()),
|
||||
};
|
||||
|
||||
Self::deposit_event(Event::Deposit(who.clone(), value));
|
||||
Self::deposit_event(Event::Deposit { who: who.clone(), amount: value });
|
||||
Ok(PositiveImbalance::new(value))
|
||||
},
|
||||
)
|
||||
@@ -1696,7 +1706,7 @@ where
|
||||
|
||||
account.free = new_free_account;
|
||||
|
||||
Self::deposit_event(Event::Withdraw(who.clone(), value));
|
||||
Self::deposit_event(Event::Withdraw { who: who.clone(), amount: value });
|
||||
Ok(NegativeImbalance::new(value))
|
||||
},
|
||||
)
|
||||
@@ -1729,7 +1739,11 @@ where
|
||||
SignedImbalance::Negative(NegativeImbalance::new(account.free - value))
|
||||
};
|
||||
account.free = value;
|
||||
Self::deposit_event(Event::BalanceSet(who.clone(), account.free, account.reserved));
|
||||
Self::deposit_event(Event::BalanceSet {
|
||||
who: who.clone(),
|
||||
free: account.free,
|
||||
reserved: account.reserved,
|
||||
});
|
||||
Ok(imbalance)
|
||||
},
|
||||
)
|
||||
@@ -1773,7 +1787,7 @@ where
|
||||
Self::ensure_can_withdraw(&who, value.clone(), WithdrawReasons::RESERVE, account.free)
|
||||
})?;
|
||||
|
||||
Self::deposit_event(Event::Reserved(who.clone(), value));
|
||||
Self::deposit_event(Event::Reserved { who: who.clone(), amount: value });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1805,7 +1819,7 @@ where
|
||||
},
|
||||
};
|
||||
|
||||
Self::deposit_event(Event::Unreserved(who.clone(), actual.clone()));
|
||||
Self::deposit_event(Event::Unreserved { who: who.clone(), amount: actual.clone() });
|
||||
value - actual
|
||||
}
|
||||
|
||||
@@ -1846,10 +1860,10 @@ where
|
||||
(NegativeImbalance::new(actual), value - actual)
|
||||
}) {
|
||||
Ok((imbalance, not_slashed)) => {
|
||||
Self::deposit_event(Event::Slashed(
|
||||
who.clone(),
|
||||
value.saturating_sub(not_slashed),
|
||||
));
|
||||
Self::deposit_event(Event::Slashed {
|
||||
who: who.clone(),
|
||||
amount: value.saturating_sub(not_slashed),
|
||||
});
|
||||
return (imbalance, not_slashed)
|
||||
},
|
||||
Err(_) => (),
|
||||
@@ -1992,7 +2006,7 @@ where
|
||||
// `actual <= to_change` and `to_change <= amount`; qed;
|
||||
reserves[index].amount -= actual;
|
||||
|
||||
Self::deposit_event(Event::Slashed(who.clone(), actual));
|
||||
Self::deposit_event(Event::Slashed { who: who.clone(), amount: actual });
|
||||
(imb, value - actual)
|
||||
},
|
||||
Err(_) => (NegativeImbalance::zero(), value),
|
||||
|
||||
@@ -314,7 +314,7 @@ macro_rules! decl_tests {
|
||||
<$ext_builder>::default().monied(true).build().execute_with(|| {
|
||||
assert_eq!(Balances::total_balance(&1), 10);
|
||||
assert_ok!(Balances::deposit_into_existing(&1, 10).map(drop));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Deposit(1, 10)));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 10 }));
|
||||
assert_eq!(Balances::total_balance(&1), 20);
|
||||
assert_eq!(<TotalIssuance<$test>>::get(), 120);
|
||||
});
|
||||
@@ -342,7 +342,7 @@ macro_rules! decl_tests {
|
||||
fn balance_works() {
|
||||
<$ext_builder>::default().build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&1, 42);
|
||||
System::assert_has_event(Event::Balances(crate::Event::Deposit(1, 42)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 42 }));
|
||||
assert_eq!(Balances::free_balance(1), 42);
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
assert_eq!(Balances::total_balance(&1), 42);
|
||||
@@ -444,7 +444,7 @@ macro_rules! decl_tests {
|
||||
let _ = Balances::withdraw(
|
||||
&2, 11, WithdrawReasons::TRANSFER, ExistenceRequirement::KeepAlive
|
||||
);
|
||||
System::assert_last_event(Event::Balances(crate::Event::Withdraw(2, 11)));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Withdraw { who: 2, amount: 11 }));
|
||||
assert_eq!(Balances::free_balance(2), 100);
|
||||
assert_eq!(<TotalIssuance<$test>>::get(), 100);
|
||||
});
|
||||
@@ -505,7 +505,7 @@ macro_rules! decl_tests {
|
||||
assert_ok!(Balances::reserve(&1, 110));
|
||||
assert_ok!(Balances::repatriate_reserved(&1, &2, 41, Status::Free), 0);
|
||||
System::assert_last_event(
|
||||
Event::Balances(crate::Event::ReserveRepatriated(1, 2, 41, Status::Free))
|
||||
Event::Balances(crate::Event::ReserveRepatriated { from: 1, to: 2, amount: 41, destination_status: Status::Free })
|
||||
);
|
||||
assert_eq!(Balances::reserved_balance(1), 69);
|
||||
assert_eq!(Balances::free_balance(1), 0);
|
||||
@@ -724,18 +724,18 @@ macro_rules! decl_tests {
|
||||
System::set_block_number(2);
|
||||
assert_ok!(Balances::reserve(&1, 10));
|
||||
|
||||
System::assert_last_event(Event::Balances(crate::Event::Reserved(1, 10)));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Reserved { who: 1, amount: 10 }));
|
||||
|
||||
System::set_block_number(3);
|
||||
assert!(Balances::unreserve(&1, 5).is_zero());
|
||||
|
||||
System::assert_last_event(Event::Balances(crate::Event::Unreserved(1, 5)));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 }));
|
||||
|
||||
System::set_block_number(4);
|
||||
assert_eq!(Balances::unreserve(&1, 6), 1);
|
||||
|
||||
// should only unreserve 5
|
||||
System::assert_last_event(Event::Balances(crate::Event::Unreserved(1, 5)));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -751,8 +751,8 @@ macro_rules! decl_tests {
|
||||
events(),
|
||||
[
|
||||
Event::System(system::Event::NewAccount(1)),
|
||||
Event::Balances(crate::Event::Endowed(1, 100)),
|
||||
Event::Balances(crate::Event::BalanceSet(1, 100, 0)),
|
||||
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
|
||||
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -763,8 +763,8 @@ macro_rules! decl_tests {
|
||||
events(),
|
||||
[
|
||||
Event::System(system::Event::KilledAccount(1)),
|
||||
Event::Balances(crate::Event::DustLost(1, 99)),
|
||||
Event::Balances(crate::Event::Slashed(1, 1)),
|
||||
Event::Balances(crate::Event::DustLost { account: 1, amount: 99 }),
|
||||
Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }),
|
||||
]
|
||||
);
|
||||
});
|
||||
@@ -782,8 +782,8 @@ macro_rules! decl_tests {
|
||||
events(),
|
||||
[
|
||||
Event::System(system::Event::NewAccount(1)),
|
||||
Event::Balances(crate::Event::Endowed(1, 100)),
|
||||
Event::Balances(crate::Event::BalanceSet(1, 100, 0)),
|
||||
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
|
||||
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -794,7 +794,7 @@ macro_rules! decl_tests {
|
||||
events(),
|
||||
[
|
||||
Event::System(system::Event::KilledAccount(1)),
|
||||
Event::Balances(crate::Event::Slashed(1, 100)),
|
||||
Event::Balances(crate::Event::Slashed { who: 1, amount: 100 }),
|
||||
]
|
||||
);
|
||||
});
|
||||
@@ -814,7 +814,7 @@ macro_rules! decl_tests {
|
||||
assert_eq!(Balances::slash(&1, 900), (NegativeImbalance::new(900), 0));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Slashed(1, 900)));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Slashed { who: 1, amount: 900 }));
|
||||
|
||||
// SCENARIO: Slash will kill account because not enough balance left.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
|
||||
|
||||
@@ -164,8 +164,8 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
|
||||
events(),
|
||||
[
|
||||
Event::System(system::Event::NewAccount(1)),
|
||||
Event::Balances(crate::Event::Endowed(1, 100)),
|
||||
Event::Balances(crate::Event::BalanceSet(1, 100, 0)),
|
||||
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
|
||||
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -173,7 +173,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
|
||||
assert_eq!(res, (NegativeImbalance::new(98), 0));
|
||||
|
||||
// no events
|
||||
assert_eq!(events(), [Event::Balances(crate::Event::Slashed(1, 98))]);
|
||||
assert_eq!(events(), [Event::Balances(crate::Event::Slashed { who: 1, amount: 98 })]);
|
||||
|
||||
let res = Balances::slash(&1, 1);
|
||||
assert_eq!(res, (NegativeImbalance::new(1), 0));
|
||||
@@ -182,8 +182,8 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
|
||||
events(),
|
||||
[
|
||||
Event::System(system::Event::KilledAccount(1)),
|
||||
Event::Balances(crate::Event::DustLost(1, 1)),
|
||||
Event::Balances(crate::Event::Slashed(1, 1)),
|
||||
Event::Balances(crate::Event::DustLost { account: 1, amount: 1 }),
|
||||
Event::Balances(crate::Event::Slashed { who: 1, amount: 1 })
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -169,9 +169,16 @@ fn transfer_dust_removal_tst1_should_work() {
|
||||
// Verify the events
|
||||
assert_eq!(System::events().len(), 12);
|
||||
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 3, 450)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::Deposit(1, 50)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer {
|
||||
from: 2,
|
||||
to: 3,
|
||||
amount: 450,
|
||||
}));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost {
|
||||
account: 2,
|
||||
amount: 50,
|
||||
}));
|
||||
System::assert_has_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -197,9 +204,16 @@ fn transfer_dust_removal_tst2_should_work() {
|
||||
// Verify the events
|
||||
assert_eq!(System::events().len(), 10);
|
||||
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 1, 450)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::Deposit(1, 50)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::Transfer {
|
||||
from: 2,
|
||||
to: 1,
|
||||
amount: 450,
|
||||
}));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost {
|
||||
account: 2,
|
||||
amount: 50,
|
||||
}));
|
||||
System::assert_has_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -234,13 +248,18 @@ fn repatriating_reserved_balance_dust_removal_should_work() {
|
||||
// Verify the events
|
||||
assert_eq!(System::events().len(), 11);
|
||||
|
||||
System::assert_has_event(Event::Balances(crate::Event::ReserveRepatriated(
|
||||
2,
|
||||
1,
|
||||
450,
|
||||
Status::Free,
|
||||
)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
|
||||
System::assert_last_event(Event::Balances(crate::Event::Deposit(1, 50)));
|
||||
System::assert_has_event(Event::Balances(crate::Event::ReserveRepatriated {
|
||||
from: 2,
|
||||
to: 1,
|
||||
amount: 450,
|
||||
destination_status: Status::Free,
|
||||
}));
|
||||
|
||||
System::assert_has_event(Event::Balances(crate::Event::DustLost {
|
||||
account: 2,
|
||||
amount: 50,
|
||||
}));
|
||||
|
||||
System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 }));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user