From d27125767337801f0bd7785f9e149c79423919f3 Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Wed, 14 Aug 2024 13:25:51 +0200 Subject: [PATCH 1/6] docs: pop api --- pop-api/src/lib.rs | 9 +++ pop-api/src/v0/assets/fungibles.rs | 100 +++++++++++++++-------------- pop-api/src/v0/assets/mod.rs | 1 + pop-api/src/v0/mod.rs | 1 + 4 files changed, 64 insertions(+), 47 deletions(-) diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index 78a79f80..e90f09cc 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -1,3 +1,10 @@ +//! The `pop-api` crate provides an API for smart contracts to interact with the Pop network runtime. +//! +//! This crate abstracts away complexities to deliver a streamlined developer experience while supporting +//! multiple API versions to ensure backward compatibility. It is designed with a focus on stability, +//! future-proofing, and storage efficiency, allowing developers to easily integrate powerful runtime +//! features into their contracts without unnecessary overhead. + #![cfg_attr(not(feature = "std"), no_std, no_main)] use constants::DECODING_FAILED; @@ -5,7 +12,9 @@ use ink::env::chain_extension::{ChainExtensionMethod, FromStatusCode}; #[cfg(feature = "assets")] pub use v0::assets; +/// Module providing primitives types. pub mod primitives; +/// Version zero of the API. pub mod v0; /// A result type used by the API, with the `StatusCode` as the error type. diff --git a/pop-api/src/v0/assets/fungibles.rs b/pop-api/src/v0/assets/fungibles.rs index 323db2b6..e80c686e 100644 --- a/pop-api/src/v0/assets/fungibles.rs +++ b/pop-api/src/v0/assets/fungibles.rs @@ -1,3 +1,10 @@ +//! The `fungibles` module provides an API for interacting and managing with fungible assets on Pop network. +//! +//! 1. PSP-22 Interface +//! 2. PSP-22 Metadata Interface +//! 3. Asset Management +//! 4. PSP-22 Mintable & Burnable Interface + use crate::{ constants::{ASSETS, BALANCES, FUNGIBLES}, primitives::{AccountId, AssetId, Balance}, @@ -8,28 +15,22 @@ use constants::*; use ink::{env::chain_extension::ChainExtensionMethod, prelude::vec::Vec}; pub use metadata::*; -/// Helper method to build a dispatch call `ChainExtensionMethod` for fungibles `v0`. -/// -/// Parameters: -/// - 'dispatchable': The index of the module dispatchable functions. +// Helper method to build a dispatch call `ChainExtensionMethod` for fungibles `v0`. +// +// Parameters: +// - 'dispatchable': The index of the module dispatchable functions. fn build_dispatch(dispatchable: u8) -> ChainExtensionMethod<(), (), (), false> { crate::v0::build_dispatch(FUNGIBLES, dispatchable) } -/// Helper method to build a dispatch call `ChainExtensionMethod` for fungibles `v0`. -/// -/// Parameters: -/// - 'state_query': The index of the runtime state query. +// Helper method to build a dispatch call `ChainExtensionMethod` for fungibles `v0`. +// +// Parameters: +// - 'state_query': The index of the runtime state query. fn build_read_state(state_query: u8) -> ChainExtensionMethod<(), (), (), false> { crate::v0::build_read_state(FUNGIBLES, state_query) } -/// Local Fungibles: -/// 1. PSP-22 Interface -/// 2. PSP-22 Metadata Interface -/// 3. Asset Management -/// 4. PSP-22 Mintable & Burnable Interface - mod constants { /// 1. PSP-22 Interface: pub(super) const TOTAL_SUPPLY: u8 = 0; @@ -323,9 +324,46 @@ pub fn burn(id: AssetId, account: AccountId, value: Balance) -> Result<()> { .call(&(id, account, value)) } +/// The interface for managing metadata of fungible assets. It includes the PSP-22 Metadata interface +/// for querying metadata. +// TODO: if reviewers agree with replacing metadata related apis here, the dispatchable index has to +// be changed (quick fix). pub mod metadata { use super::*; + /// Set the metadata for a token with a given asset ID. + /// + /// # Parameters + /// - `id`: The identifier of the asset to update. + /// - `name`: The user friendly name of this asset. Limited in length by `StringLimit`. + /// - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`. + /// - `decimals`: The number of decimals this asset uses to represent one unit. + /// + /// # Returns + /// Returns `Ok(())` if successful, or an error if the operation fails. + pub fn set_metadata(id: AssetId, name: Vec, symbol: Vec, decimals: u8) -> Result<()> { + build_dispatch(SET_METADATA) + .input::<(AssetId, Vec, Vec, u8)>() + .output::, true>() + .handle_error_code::() + .call(&(id, name, symbol, decimals)) + } + + /// Clear the metadata for a token with a given asset ID. + /// + /// # Parameters + /// - `id` - The ID of the asset. + /// + /// # Returns + /// Returns `Ok(())` if successful, or an error if the operation fails. + pub fn clear_metadata(id: AssetId) -> Result<()> { + build_dispatch(CLEAR_METADATA) + .input::() + .output::, true>() + .handle_error_code::() + .call(&(id)) + } + /// Returns the token name for a given asset ID. /// /// # Parameters @@ -375,6 +413,7 @@ pub mod metadata { } } +/// The interface for creating and destroying fungible assets. pub mod asset_management { use super::*; @@ -410,39 +449,6 @@ pub mod asset_management { .call(&(id)) } - /// Set the metadata for a token with a given asset ID. - /// - /// # Parameters - /// - `id`: The identifier of the asset to update. - /// - `name`: The user friendly name of this asset. Limited in length by `StringLimit`. - /// - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`. - /// - `decimals`: The number of decimals this asset uses to represent one unit. - /// - /// # Returns - /// Returns `Ok(())` if successful, or an error if the operation fails. - pub fn set_metadata(id: AssetId, name: Vec, symbol: Vec, decimals: u8) -> Result<()> { - build_dispatch(SET_METADATA) - .input::<(AssetId, Vec, Vec, u8)>() - .output::, true>() - .handle_error_code::() - .call(&(id, name, symbol, decimals)) - } - - /// Clear the metadata for a token with a given asset ID. - /// - /// # Parameters - /// - `id` - The ID of the asset. - /// - /// # Returns - /// Returns `Ok(())` if successful, or an error if the operation fails. - pub fn clear_metadata(id: AssetId) -> Result<()> { - build_dispatch(CLEAR_METADATA) - .input::() - .output::, true>() - .handle_error_code::() - .call(&(id)) - } - /// Checks if token with a given asset ID exists. /// /// # Parameters diff --git a/pop-api/src/v0/assets/mod.rs b/pop-api/src/v0/assets/mod.rs index 197db710..e24473a4 100644 --- a/pop-api/src/v0/assets/mod.rs +++ b/pop-api/src/v0/assets/mod.rs @@ -1,2 +1,3 @@ +/// APIs for fungibles assets. #[cfg(feature = "fungibles")] pub mod fungibles; diff --git a/pop-api/src/v0/mod.rs b/pop-api/src/v0/mod.rs index 0fd06c89..816011d4 100644 --- a/pop-api/src/v0/mod.rs +++ b/pop-api/src/v0/mod.rs @@ -6,6 +6,7 @@ use crate::{ }; use ink::env::chain_extension::ChainExtensionMethod; +/// APIs for assets related use cases. #[cfg(feature = "assets")] pub mod assets; From 65e2139143c444345f9627d12ef74555be9abc1a Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Thu, 15 Aug 2024 14:56:53 +0200 Subject: [PATCH 2/6] style: general --- pop-api/src/lib.rs | 18 +++++++++--------- pop-api/src/v0/assets/fungibles.rs | 15 ++++++++------- pop-api/src/v0/assets/mod.rs | 2 +- pop-api/src/v0/mod.rs | 22 +++++++++++----------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index e90f09cc..cc785c14 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -1,4 +1,4 @@ -//! The `pop-api` crate provides an API for smart contracts to interact with the Pop network runtime. +//! The `pop-api` crate provides an API for smart contracts to interact with the Pop Network runtime. //! //! This crate abstracts away complexities to deliver a streamlined developer experience while supporting //! multiple API versions to ensure backward compatibility. It is designed with a focus on stability, @@ -14,7 +14,7 @@ pub use v0::assets; /// Module providing primitives types. pub mod primitives; -/// Version zero of the API. +/// The first version of the API. pub mod v0; /// A result type used by the API, with the `StatusCode` as the error type. @@ -36,13 +36,13 @@ mod constants { pub(crate) const FUNGIBLES: u8 = 150; } -/// Helper method to build `ChainExtensionMethod`. -/// -/// Parameters: -/// - 'version': The version of the chain extension. -/// - 'function': The ID of the function. -/// - 'module': The index of the runtime module. -/// - 'dispatchable': The index of the module dispatchable functions. +// Helper method to build a dispatch call or a call to read state. +// +// Parameters: +// - 'version': The version of the chain extension. +// - 'function': The ID of the function. +// - 'module': The index of the runtime module. +// - 'dispatchable': The index of the module dispatchable functions. fn build_extension_method( version: u8, function: u8, diff --git a/pop-api/src/v0/assets/fungibles.rs b/pop-api/src/v0/assets/fungibles.rs index e80c686e..04031686 100644 --- a/pop-api/src/v0/assets/fungibles.rs +++ b/pop-api/src/v0/assets/fungibles.rs @@ -1,9 +1,10 @@ -//! The `fungibles` module provides an API for interacting and managing with fungible assets on Pop network. +//! The `fungibles` module provides an API for interacting and managing fungible assets on Pop Network. //! -//! 1. PSP-22 Interface -//! 2. PSP-22 Metadata Interface +//! The API includes the following interfaces: +//! 1. PSP-22 +//! 2. PSP-22 Metadata //! 3. Asset Management -//! 4. PSP-22 Mintable & Burnable Interface +//! 4. PSP-22 Mintable & Burnable use crate::{ constants::{ASSETS, BALANCES, FUNGIBLES}, @@ -15,15 +16,15 @@ use constants::*; use ink::{env::chain_extension::ChainExtensionMethod, prelude::vec::Vec}; pub use metadata::*; -// Helper method to build a dispatch call `ChainExtensionMethod` for fungibles `v0`. +// Helper method to build a dispatch call. // // Parameters: -// - 'dispatchable': The index of the module dispatchable functions. +// - 'dispatchable': The index of the dispatchable function within the module. fn build_dispatch(dispatchable: u8) -> ChainExtensionMethod<(), (), (), false> { crate::v0::build_dispatch(FUNGIBLES, dispatchable) } -// Helper method to build a dispatch call `ChainExtensionMethod` for fungibles `v0`. +// Helper method to build a call to read state. // // Parameters: // - 'state_query': The index of the runtime state query. diff --git a/pop-api/src/v0/assets/mod.rs b/pop-api/src/v0/assets/mod.rs index e24473a4..2d5ae236 100644 --- a/pop-api/src/v0/assets/mod.rs +++ b/pop-api/src/v0/assets/mod.rs @@ -1,3 +1,3 @@ -/// APIs for fungibles assets. +/// APIs for fungible assets. #[cfg(feature = "fungibles")] pub mod fungibles; diff --git a/pop-api/src/v0/mod.rs b/pop-api/src/v0/mod.rs index 816011d4..a4824327 100644 --- a/pop-api/src/v0/mod.rs +++ b/pop-api/src/v0/mod.rs @@ -6,7 +6,7 @@ use crate::{ }; use ink::env::chain_extension::ChainExtensionMethod; -/// APIs for assets related use cases. +/// APIs for asset-related use cases. #[cfg(feature = "assets")] pub mod assets; @@ -18,20 +18,20 @@ impl From for Error { } } -/// Helper method to build a dispatch call `ChainExtensionMethod` -/// -/// Parameters: -/// - 'module': The index of the runtime module -/// - 'dispatchable': The index of the module dispatchable functions +// Helper method to build a dispatch call. +// +// Parameters: +// - 'module': The index of the runtime module. +// - 'dispatchable': The index of the module dispatchable functions. fn build_dispatch(module: u8, dispatchable: u8) -> ChainExtensionMethod<(), (), (), false> { build_extension_method(V0, DISPATCH, module, dispatchable) } -/// Helper method to build a dispatch call `ChainExtensionMethod` -/// -/// Parameters: -/// - 'module': The index of the runtime module -/// - 'state_query': The index of the runtime state query +// Helper method to build a call to read state. +// +// Parameters: +// - 'module': The index of the runtime module. +// - 'state_query': The index of the runtime state query. fn build_read_state(module: u8, state_query: u8) -> ChainExtensionMethod<(), (), (), false> { build_extension_method(V0, READ_STATE, module, state_query) } From 7731a26a58ce514a36ea0a6f3ec3a15274047553 Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Thu, 15 Aug 2024 15:00:44 +0200 Subject: [PATCH 3/6] style: remove return docs --- pop-api/src/v0/assets/fungibles.rs | 51 ------------------------------ 1 file changed, 51 deletions(-) diff --git a/pop-api/src/v0/assets/fungibles.rs b/pop-api/src/v0/assets/fungibles.rs index 04031686..39522fff 100644 --- a/pop-api/src/v0/assets/fungibles.rs +++ b/pop-api/src/v0/assets/fungibles.rs @@ -149,9 +149,6 @@ pub mod events { /// /// # Parameters /// - `id` - The ID of the asset. -/// -/// # Returns -/// The total supply of the token, or an error if the operation fails. #[inline] pub fn total_supply(id: AssetId) -> Result { build_read_state(TOTAL_SUPPLY) @@ -167,9 +164,6 @@ pub fn total_supply(id: AssetId) -> Result { /// # Parameters /// - `id` - The ID of the asset. /// - `owner` - The account whose balance is being queried. -/// -/// # Returns -/// The balance of the specified account, or an error if the operation fails. #[inline] pub fn balance_of(id: AssetId, owner: AccountId) -> Result { build_read_state(BALANCE_OF) @@ -186,9 +180,6 @@ pub fn balance_of(id: AssetId, owner: AccountId) -> Result { /// - `id` - The ID of the asset. /// - `owner` - The account that owns the tokens. /// - `spender` - The account that is allowed to spend the tokens. -/// -/// # Returns -/// The remaining allowance, or an error if the operation fails. #[inline] pub fn allowance(id: AssetId, owner: AccountId, spender: AccountId) -> Result { build_read_state(ALLOWANCE) @@ -205,9 +196,6 @@ pub fn allowance(id: AssetId, owner: AccountId, spender: AccountId) -> Result Result<()> { build_dispatch(TRANSFER) @@ -225,9 +213,6 @@ pub fn transfer(id: AssetId, to: AccountId, value: Balance) -> Result<()> { /// - `from` - The account from which the tokens are transferred. /// - `to` - The recipient account. /// - `value` - The number of tokens to transfer. -/// -/// # Returns -/// Returns `Ok(())` if successful, or an error if the transfer fails. #[inline] pub fn transfer_from(id: AssetId, from: AccountId, to: AccountId, value: Balance) -> Result<()> { build_dispatch(TRANSFER_FROM) @@ -243,9 +228,6 @@ pub fn transfer_from(id: AssetId, from: AccountId, to: AccountId, value: Balance /// - `id` - The ID of the asset. /// - `spender` - The account that is allowed to spend the tokens. /// - `value` - The number of tokens to approve. -/// -/// # Returns -/// Returns `Ok(())` if successful, or an error if the approval fails. #[inline] pub fn approve(id: AssetId, spender: AccountId, value: Balance) -> Result<()> { build_dispatch(APPROVE) @@ -261,9 +243,6 @@ pub fn approve(id: AssetId, spender: AccountId, value: Balance) -> Result<()> { /// - `id` - The ID of the asset. /// - `spender` - The account that is allowed to spend the tokens. /// - `value` - The number of tokens to increase the allowance by. -/// -/// # Returns -/// Returns `Ok(())` if successful, or an error if the operation fails. #[inline] pub fn increase_allowance(id: AssetId, spender: AccountId, value: Balance) -> Result<()> { build_dispatch(INCREASE_ALLOWANCE) @@ -279,9 +258,6 @@ pub fn increase_allowance(id: AssetId, spender: AccountId, value: Balance) -> Re /// - `id` - The ID of the asset. /// - `spender` - The account that is allowed to spend the tokens. /// - `value` - The number of tokens to decrease the allowance by. -/// -/// # Returns -/// Returns `Ok(())` if successful, or an error if the operation fails. #[inline] pub fn decrease_allowance(id: AssetId, spender: AccountId, value: Balance) -> Result<()> { build_dispatch(DECREASE_ALLOWANCE) @@ -297,9 +273,6 @@ pub fn decrease_allowance(id: AssetId, spender: AccountId, value: Balance) -> Re /// - `id` - The ID of the asset. /// - `account` - The account to be credited with the created tokens. /// - `value` - The number of tokens to mint. -/// -/// # Returns -/// Returns `Ok(())` if successful, or an error if the operation fails. pub fn mint(id: AssetId, account: AccountId, value: Balance) -> Result<()> { build_dispatch(MINT) .input::<(AssetId, AccountId, Balance)>() @@ -314,9 +287,6 @@ pub fn mint(id: AssetId, account: AccountId, value: Balance) -> Result<()> { /// - `id` - The ID of the asset. /// - `account` - The account from which the tokens will be destroyed. /// - `value` - The number of tokens to destroy. -/// -/// # Returns -/// Returns `Ok(())` if successful, or an error if the operation fails. pub fn burn(id: AssetId, account: AccountId, value: Balance) -> Result<()> { build_dispatch(BURN) .input::<(AssetId, AccountId, Balance)>() @@ -339,9 +309,6 @@ pub mod metadata { /// - `name`: The user friendly name of this asset. Limited in length by `StringLimit`. /// - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`. /// - `decimals`: The number of decimals this asset uses to represent one unit. - /// - /// # Returns - /// Returns `Ok(())` if successful, or an error if the operation fails. pub fn set_metadata(id: AssetId, name: Vec, symbol: Vec, decimals: u8) -> Result<()> { build_dispatch(SET_METADATA) .input::<(AssetId, Vec, Vec, u8)>() @@ -354,9 +321,6 @@ pub mod metadata { /// /// # Parameters /// - `id` - The ID of the asset. - /// - /// # Returns - /// Returns `Ok(())` if successful, or an error if the operation fails. pub fn clear_metadata(id: AssetId) -> Result<()> { build_dispatch(CLEAR_METADATA) .input::() @@ -369,9 +333,6 @@ pub mod metadata { /// /// # Parameters /// - `id` - The ID of the asset. - /// - /// # Returns - /// The name of the token as a byte vector, or an error if the operation fails. #[inline] pub fn token_name(id: AssetId) -> Result> { build_read_state(TOKEN_NAME) @@ -385,9 +346,6 @@ pub mod metadata { /// /// # Parameters /// - `id` - The ID of the asset. - /// - /// # Returns - /// The symbol of the token as a byte vector, or an error if the operation fails. #[inline] pub fn token_symbol(id: AssetId) -> Result> { build_read_state(TOKEN_SYMBOL) @@ -401,9 +359,6 @@ pub mod metadata { /// /// # Parameters /// - `id` - The ID of the asset. - /// - /// # Returns - /// The number of decimals of the token, or an error if the operation fails. #[inline] pub fn token_decimals(id: AssetId) -> Result { build_read_state(TOKEN_DECIMALS) @@ -424,9 +379,6 @@ pub mod asset_management { /// - `id` - The ID of the asset. /// - `admin` - The account that will administer the asset. /// - `min_balance` - The minimum balance required for accounts holding this asset. - /// - /// # Returns - /// Returns `Ok(())` if successful, or an error if the creation fails. pub fn create(id: AssetId, admin: AccountId, min_balance: Balance) -> Result<()> { build_dispatch(CREATE) .input::<(AssetId, AccountId, Balance)>() @@ -439,9 +391,6 @@ pub mod asset_management { /// /// # Parameters /// - `id` - The ID of the asset. - /// - /// # Returns - /// Returns `Ok(())` if successful, or an error if the operation fails. pub fn start_destroy(id: AssetId) -> Result<()> { build_dispatch(START_DESTROY) .input::() From d3ca674d8519310cc7c913f2207370fb309a316d Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Thu, 15 Aug 2024 15:13:39 +0200 Subject: [PATCH 4/6] fix: consistent inline --- pop-api/src/v0/assets/fungibles.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pop-api/src/v0/assets/fungibles.rs b/pop-api/src/v0/assets/fungibles.rs index 39522fff..5b567496 100644 --- a/pop-api/src/v0/assets/fungibles.rs +++ b/pop-api/src/v0/assets/fungibles.rs @@ -273,6 +273,7 @@ pub fn decrease_allowance(id: AssetId, spender: AccountId, value: Balance) -> Re /// - `id` - The ID of the asset. /// - `account` - The account to be credited with the created tokens. /// - `value` - The number of tokens to mint. +#[inline] pub fn mint(id: AssetId, account: AccountId, value: Balance) -> Result<()> { build_dispatch(MINT) .input::<(AssetId, AccountId, Balance)>() @@ -287,6 +288,7 @@ pub fn mint(id: AssetId, account: AccountId, value: Balance) -> Result<()> { /// - `id` - The ID of the asset. /// - `account` - The account from which the tokens will be destroyed. /// - `value` - The number of tokens to destroy. +#[inline] pub fn burn(id: AssetId, account: AccountId, value: Balance) -> Result<()> { build_dispatch(BURN) .input::<(AssetId, AccountId, Balance)>() @@ -309,6 +311,7 @@ pub mod metadata { /// - `name`: The user friendly name of this asset. Limited in length by `StringLimit`. /// - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`. /// - `decimals`: The number of decimals this asset uses to represent one unit. + #[inline] pub fn set_metadata(id: AssetId, name: Vec, symbol: Vec, decimals: u8) -> Result<()> { build_dispatch(SET_METADATA) .input::<(AssetId, Vec, Vec, u8)>() @@ -321,6 +324,7 @@ pub mod metadata { /// /// # Parameters /// - `id` - The ID of the asset. + #[inline] pub fn clear_metadata(id: AssetId) -> Result<()> { build_dispatch(CLEAR_METADATA) .input::() @@ -379,6 +383,7 @@ pub mod asset_management { /// - `id` - The ID of the asset. /// - `admin` - The account that will administer the asset. /// - `min_balance` - The minimum balance required for accounts holding this asset. + #[inline] pub fn create(id: AssetId, admin: AccountId, min_balance: Balance) -> Result<()> { build_dispatch(CREATE) .input::<(AssetId, AccountId, Balance)>() @@ -391,6 +396,7 @@ pub mod asset_management { /// /// # Parameters /// - `id` - The ID of the asset. + #[inline] pub fn start_destroy(id: AssetId) -> Result<()> { build_dispatch(START_DESTROY) .input::() From 66e68896933315ca24a24c06d3471efe529bba18 Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Thu, 15 Aug 2024 15:17:59 +0200 Subject: [PATCH 5/6] refactor: conforming to psp22 metadata standard --- pop-api/src/v0/assets/fungibles.rs | 65 ++++++++++++++---------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/pop-api/src/v0/assets/fungibles.rs b/pop-api/src/v0/assets/fungibles.rs index 5b567496..f76e9699 100644 --- a/pop-api/src/v0/assets/fungibles.rs +++ b/pop-api/src/v0/assets/fungibles.rs @@ -297,42 +297,10 @@ pub fn burn(id: AssetId, account: AccountId, value: Balance) -> Result<()> { .call(&(id, account, value)) } -/// The interface for managing metadata of fungible assets. It includes the PSP-22 Metadata interface -/// for querying metadata. -// TODO: if reviewers agree with replacing metadata related apis here, the dispatchable index has to -// be changed (quick fix). +/// The PSP-22 Metadata interface for querying metadata. pub mod metadata { use super::*; - /// Set the metadata for a token with a given asset ID. - /// - /// # Parameters - /// - `id`: The identifier of the asset to update. - /// - `name`: The user friendly name of this asset. Limited in length by `StringLimit`. - /// - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`. - /// - `decimals`: The number of decimals this asset uses to represent one unit. - #[inline] - pub fn set_metadata(id: AssetId, name: Vec, symbol: Vec, decimals: u8) -> Result<()> { - build_dispatch(SET_METADATA) - .input::<(AssetId, Vec, Vec, u8)>() - .output::, true>() - .handle_error_code::() - .call(&(id, name, symbol, decimals)) - } - - /// Clear the metadata for a token with a given asset ID. - /// - /// # Parameters - /// - `id` - The ID of the asset. - #[inline] - pub fn clear_metadata(id: AssetId) -> Result<()> { - build_dispatch(CLEAR_METADATA) - .input::() - .output::, true>() - .handle_error_code::() - .call(&(id)) - } - /// Returns the token name for a given asset ID. /// /// # Parameters @@ -373,7 +341,7 @@ pub mod metadata { } } -/// The interface for creating and destroying fungible assets. +/// The interface for creating, managing and destroying fungible assets. pub mod asset_management { use super::*; @@ -405,6 +373,35 @@ pub mod asset_management { .call(&(id)) } + /// Set the metadata for a token with a given asset ID. + /// + /// # Parameters + /// - `id`: The identifier of the asset to update. + /// - `name`: The user friendly name of this asset. Limited in length by `StringLimit`. + /// - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`. + /// - `decimals`: The number of decimals this asset uses to represent one unit. + #[inline] + pub fn set_metadata(id: AssetId, name: Vec, symbol: Vec, decimals: u8) -> Result<()> { + build_dispatch(SET_METADATA) + .input::<(AssetId, Vec, Vec, u8)>() + .output::, true>() + .handle_error_code::() + .call(&(id, name, symbol, decimals)) + } + + /// Clear the metadata for a token with a given asset ID. + /// + /// # Parameters + /// - `id` - The ID of the asset. + #[inline] + pub fn clear_metadata(id: AssetId) -> Result<()> { + build_dispatch(CLEAR_METADATA) + .input::() + .output::, true>() + .handle_error_code::() + .call(&(id)) + } + /// Checks if token with a given asset ID exists. /// /// # Parameters From dfb7e3e665f196643cfb30962d70021ded40f0ca Mon Sep 17 00:00:00 2001 From: Daan van der Plas <93204684+Daanvdplas@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:23:44 +0200 Subject: [PATCH 6/6] Update pop-api/src/v0/assets/fungibles.rs Co-authored-by: Frank Bell <60948618+evilrobot-01@users.noreply.github.com> --- pop-api/src/v0/assets/fungibles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pop-api/src/v0/assets/fungibles.rs b/pop-api/src/v0/assets/fungibles.rs index f76e9699..c881f823 100644 --- a/pop-api/src/v0/assets/fungibles.rs +++ b/pop-api/src/v0/assets/fungibles.rs @@ -342,7 +342,7 @@ pub mod metadata { } /// The interface for creating, managing and destroying fungible assets. -pub mod asset_management { +pub mod management { use super::*; /// Create a new token with a given asset ID.