Skip to content

Commit

Permalink
Added create and transfer resolver (#821)
Browse files Browse the repository at this point in the history
## Describe your changes
Added create and transfer resolver.
  • Loading branch information
zktony committed Jun 23, 2023
2 parents 59a609b + 42951cb commit bd82a15
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 39 additions & 3 deletions primitives/polkadex/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

use crate::Balance;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::traits::{
tokens::{Fortitude, Precision, Preservation},
Get,
use frame_support::{
ensure,
traits::{
tokens::{Fortitude, Precision, Preservation},
Get,
},
};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -97,6 +100,39 @@ pub trait Resolver<
}
Ok(())
}

/// Create New Asset
fn resolve_create(
asset: AssetId,
admin: AccountId,
min_balance: Balance,
) -> Result<(), DispatchError> {
ensure!(asset != NativeAssetId::get(), DispatchError::Other("Cannot create Native Asset"));
ensure!(!Others::asset_exists(asset.into()), DispatchError::Other("Asset already exists"));
Others::create(asset.into(), admin, true, min_balance.saturated_into())?;
Ok(())
}

///Transfer Asset
fn resolve_transfer(
asset: AssetId,
from: &AccountId,
to: &AccountId,
amount: Balance,
) -> Result<(), DispatchError> {
if asset == NativeAssetId::get() {
Native::transfer(from, to, amount.saturated_into(), Preservation::Preserve)?;
} else {
Others::transfer(
asset.into(),
from,
to,
amount.saturated_into(),
Preservation::Preserve,
)?;
}
Ok(())
}
}

/// Enumerated asset on chain
Expand Down

0 comments on commit bd82a15

Please sign in to comment.