Skip to content

Commit

Permalink
refactor: final bits
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Jul 5, 2024
1 parent 972e4c9 commit 47e2ea6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
10 changes: 5 additions & 5 deletions pop-api/src/v0/assets/fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn allowance(id: AssetId, owner: AccountId, spender: AccountId) -> Result<Ba
/// Returns `Ok(())` if successful, or an error if the transfer fails.
#[inline]
pub fn transfer(id: AssetId, to: AccountId, value: Balance) -> Result<()> {
assets::transfer(id, to, value)
assets::transfer_keep_alive(id, to, value)
}

/// Transfers `value` tokens on behalf of `from` to account `to` with additional `data`
Expand Down Expand Up @@ -279,7 +279,6 @@ pub fn token_decimals(id: AssetId) -> Result<u8> {
// assets::asset_exists(id)
// }

// TODO: further implement the rest of the interfaces and conclude on the FungiblesError.
#[derive(Debug, PartialEq, Eq)]
#[ink::scale_derive(Encode, Decode, TypeInfo)]
pub enum FungiblesError {
Expand All @@ -300,13 +299,14 @@ pub enum FungiblesError {
NoPermission,
/// The given asset ID is unknown.
Unknown,
// - Originally `InsufficientBalance` for the deposit but this would result in the same error
// as the error when there is insufficient balance for transferring an asset.
/// No balance for creation of assets or fees.
//
// Originally `pallet_balances::Error::InsufficientBalance` but collides with the
// `InsufficientBalance` error that is used for `pallet_assets::Error::BalanceLow` to adhere to
// standard.
NoBalance,
}

// TODO: include conversions from TokenError and add conversions based on added interfaces.
impl From<StatusCode> for FungiblesError {
fn from(value: StatusCode) -> Self {
let encoded = value.0.to_le_bytes();
Expand Down
17 changes: 2 additions & 15 deletions pop-api/src/v0/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ const TRANSFER_APPROVED: u8 = 25;
// }))
// }

/// Move some assets from the sender account to another.
/// Move some assets from the sender account to another, keeping the sender account alive.
#[inline]
pub fn transfer(id: AssetId, target: AccountId, amount: Balance) -> Result<()> {
pub fn transfer_keep_alive(id: AssetId, target: AccountId, amount: Balance) -> Result<()> {
ChainExtensionMethod::build(u32::from_le_bytes([
VERSION,
DISPATCH,
Expand All @@ -103,19 +103,6 @@ pub fn transfer(id: AssetId, target: AccountId, amount: Balance) -> Result<()> {
.call(&(id, target, amount))
}

// /// Move some assets from the sender account to another, keeping the sender account alive.
// pub(crate) fn transfer_keep_alive(
// id: AssetId,
// target: impl Into<MultiAddress<AccountId, ()>>,
// amount: Balance,
// ) -> Result<()> {
// dispatch(RuntimeCall::Assets(AssetsCall::TransferKeepAlive {
// id: id.into(),
// target: target.into(),
// amount: Compact(amount),
// }))
// }

// /// Set the metadata for an asset.
// pub(crate) fn set_metadata(
// id: AssetId,
Expand Down
1 change: 1 addition & 0 deletions runtime/devnet/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ where
// - `error`: The `DispatchError` encountered during contract execution.
// - `version`: The version of the chain extension, used to determine the known errors.
pub(crate) fn convert_to_status_code(error: DispatchError, version: u8) -> u32 {
use sp_std::vec;
// "UnknownFunctionId" and "DecodingFailed" are mapped to specific errors in the API and will
// never change.
let mut encoded_error = match error {
Expand Down
1 change: 1 addition & 0 deletions runtime/devnet/src/extensions/v0/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::extensions::{
Balance, Compact, Decode, DispatchError, MultiAddress, Runtime, TrustBackedAssetsInstance,
};
use pop_primitives::AccountId;
use sp_std::vec::Vec;

pub(crate) fn construct_assets_key(
call_index: u8,
Expand Down
1 change: 1 addition & 0 deletions runtime/testnet/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ where
RuntimeStateKeys::ParachainSystem(key) => {
read_parachain_system_state::<T, E>(key, &mut env)
},
_ => Ok(vec![0]),
}?
.encode();

Expand Down

0 comments on commit 47e2ea6

Please sign in to comment.