mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 10:01:02 +00:00
Pallet assets improvements (#13543)
This commit is contained in:
@@ -91,12 +91,44 @@ impl pallet_balances::Config for Test {
|
||||
|
||||
pub struct AssetsCallbackHandle;
|
||||
impl AssetsCallback<AssetId, AccountId> for AssetsCallbackHandle {
|
||||
fn created(_id: &AssetId, _owner: &AccountId) {
|
||||
storage::set(b"asset_created", &().encode());
|
||||
fn created(_id: &AssetId, _owner: &AccountId) -> Result<(), ()> {
|
||||
if Self::should_err() {
|
||||
Err(())
|
||||
} else {
|
||||
storage::set(Self::CREATED.as_bytes(), &().encode());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(_id: &AssetId) {
|
||||
storage::set(b"asset_destroyed", &().encode());
|
||||
fn destroyed(_id: &AssetId) -> Result<(), ()> {
|
||||
if Self::should_err() {
|
||||
Err(())
|
||||
} else {
|
||||
storage::set(Self::DESTROYED.as_bytes(), &().encode());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AssetsCallbackHandle {
|
||||
pub const CREATED: &'static str = "asset_created";
|
||||
pub const DESTROYED: &'static str = "asset_destroyed";
|
||||
|
||||
const RETURN_ERROR: &'static str = "return_error";
|
||||
|
||||
// Configures `Self` to return `Ok` when callbacks are invoked
|
||||
pub fn set_return_ok() {
|
||||
storage::clear(Self::RETURN_ERROR.as_bytes());
|
||||
}
|
||||
|
||||
// Configures `Self` to return `Err` when callbacks are invoked
|
||||
pub fn set_return_error() {
|
||||
storage::set(Self::RETURN_ERROR.as_bytes(), &().encode());
|
||||
}
|
||||
|
||||
// If `true`, callback should return `Err`, `Ok` otherwise.
|
||||
fn should_err() -> bool {
|
||||
storage::exists(Self::RETURN_ERROR.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user