Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: apply modular approach to fungible example contract #401

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions pop-api/examples/fungibles/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

mod traits;
pub use traits::{Api, ApiImpl};
use ink::prelude::{string::String, vec::Vec};
use pop_api::{
primitives::TokenId,
Expand Down Expand Up @@ -206,17 +207,13 @@ mod fungibles {
/// Returns the token name.
#[ink(message)]
fn token_name(&self) -> Option<String> {
api::token_name(self.id)
.unwrap_or_default()
.and_then(|v| String::from_utf8(v).ok())
ApiImpl.token_name(self.id)
}

/// Returns the token symbol.
#[ink(message)]
fn token_symbol(&self) -> Option<String> {
api::token_symbol(self.id)
.unwrap_or_default()
.and_then(|v| String::from_utf8(v).ok())
ApiImpl::token_symbol(self.id)
}

/// Returns the token decimals.
Expand Down
64 changes: 64 additions & 0 deletions pop-api/examples/fungibles/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

use ink::prelude::string::String;
use pop_api::{
primitives::TokenId ,
v0::fungibles::{
self as api,
},
};

pub trait Api{
fn token_name(&self, id: TokenId) -> Option<String>;
fn token_symbol(id: TokenId) -> Option<String>;
fn token_decimals(&self, id: TokenId) -> u8;
/*fn mint(&self, id: TokenId, account: AccountId, value: u128) -> Result<(), Psp22Error>;
fn burn(&self, id: TokenId, account: AccountId, value: u128) -> Result<(), Psp22Error>;*/
}

pub struct ApiImpl;

impl Api for ApiImpl{

fn token_name(&self, id: TokenId) -> Option<String> {
api::token_name(id)
.unwrap_or_default()
.and_then(|v| String::from_utf8(v).ok())
}


fn token_symbol(id: TokenId) -> Option<String> {
api::token_symbol(id)
.unwrap_or_default()
.and_then(|v| String::from_utf8(v).ok())
}


fn token_decimals(&self, id: TokenId) -> u8 {
api::token_decimals(id).unwrap_or_default()
}

/*
fn mint(&self, id: TokenId, account: AccountId, value: u128) -> Result<(), Psp22Error> {
self.ensure_owner()?;
// No-op if `value` is zero.
if value == 0 {
return Ok(());
}
api::mint(id, account, value).map_err(Psp22Error::from)?;
self.env().emit_event(Transfer { from: None, to: Some(account), value });
Ok(())
}


fn burn(&self, id: TokenId, account: AccountId, value: u128) -> Result<(), Psp22Error>{
self.ensure_owner()?;
// No-op if `value` is zero.
if value == 0 {
return Ok(());
}
api::burn(id, account, value).map_err(Psp22Error::from)?;
self.env().emit_event(Transfer { from: Some(account), to: None, value });
Ok(())
}*/

}
Loading