mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 23:18:01 +00:00
Add low level traits to retrieve name, symbol, decimals and allowance in pallet-assets (#9757)
* Add ERC20 compatible trait to retrieve name, symbol, decimals and allowance * delegate instead of spender * Remove erc20 trait and divide it into lower level traits * add import * approvals and metadata depend on fungibles Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -25,7 +25,9 @@ use crate::dispatch::{DispatchError, DispatchResult};
|
||||
use sp_runtime::traits::Saturating;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
pub mod approvals;
|
||||
mod balanced;
|
||||
pub mod metadata;
|
||||
pub use balanced::{Balanced, Unbalanced};
|
||||
mod imbalance;
|
||||
pub use imbalance::{CreditOf, DebtOf, HandleImbalanceDrop, Imbalance};
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Inspect and Mutate traits for Asset approvals
|
||||
|
||||
use crate::dispatch::DispatchResult;
|
||||
pub trait Inspect<AccountId>: super::Inspect<AccountId> {
|
||||
// Check the amount approved by an owner to be spent by a delegate
|
||||
fn allowance(asset: Self::AssetId, owner: &AccountId, delegate: &AccountId) -> Self::Balance;
|
||||
}
|
||||
|
||||
pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||
// Aprove a delegate account to spend an amount of tokens owned by an owner
|
||||
fn approve(
|
||||
asset: Self::AssetId,
|
||||
owner: &AccountId,
|
||||
delegate: &AccountId,
|
||||
amount: Self::Balance,
|
||||
) -> DispatchResult;
|
||||
|
||||
// Transfer from a delegate account an amount approved by the owner of the asset
|
||||
fn transfer_from(
|
||||
asset: Self::AssetId,
|
||||
owner: &AccountId,
|
||||
delegate: &AccountId,
|
||||
dest: &AccountId,
|
||||
amount: Self::Balance,
|
||||
) -> DispatchResult;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Inspect and Mutate traits for Asset metadata
|
||||
|
||||
use crate::dispatch::DispatchResult;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
pub trait Inspect<AccountId>: super::Inspect<AccountId> {
|
||||
// Get name for an AssetId.
|
||||
fn name(asset: Self::AssetId) -> Vec<u8>;
|
||||
// Get symbol for an AssetId.
|
||||
fn symbol(asset: Self::AssetId) -> Vec<u8>;
|
||||
// Get decimals for an AssetId.
|
||||
fn decimals(asset: Self::AssetId) -> u8;
|
||||
}
|
||||
|
||||
pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||
// Set name, symbol and decimals for a given assetId.
|
||||
fn set(
|
||||
asset: Self::AssetId,
|
||||
from: &AccountId,
|
||||
name: Vec<u8>,
|
||||
symbol: Vec<u8>,
|
||||
decimals: u8,
|
||||
) -> DispatchResult;
|
||||
}
|
||||
Reference in New Issue
Block a user