-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
418aa63
commit 92a8465
Showing
31 changed files
with
2,244 additions
and
1,904 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...i/examples/trust_backed_assets/Cargo.toml → pop-api/examples/fungibles/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
|
||
// Fungibles wrapper contract to allow contracts to interact with local fungibles without the pop api. | ||
use pop_api::{primitives::{AccountId as AccountId32, AssetId}, assets::fungibles::*}; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] | ||
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | ||
pub enum FungiblesError { | ||
// AssetsError(Error), | ||
// /// The origin of the call doesn't have the right permission. | ||
// BadOrigin, | ||
// /// Custom error type for cases in which an implementation adds its own restrictions. | ||
// Custom(String), | ||
/// Not enough balance to fulfill a request is available. | ||
InsufficientBalance, | ||
/// Not enough allowance to fulfill a request is available. | ||
InsufficientAllowance, | ||
/// The asset status is not the expected status. | ||
IncorrectStatus, | ||
/// The asset ID is already taken. | ||
InUse, | ||
/// Minimum balance should be non-zero. | ||
MinBalanceZero, | ||
/// The signing account has no permission to do the operation. | ||
NoPermission, | ||
// /// Safe transfer check fails (e.g. if the receiving contract does not accept tokens). | ||
// SafeTransferCheckFailed(String), | ||
/// The given asset ID is unknown. | ||
Unknown, | ||
/// Recipient's address is zero. | ||
ZeroRecipientAddress, | ||
/// Sender's address is zero. | ||
ZeroSenderAddress, | ||
} | ||
|
||
impl From<Error> for FungiblesError { | ||
fn from(error: Error) -> Self { | ||
match error { | ||
// Error::BalanceLow => Err(InsufficientBalance), | ||
Error::InUse => FungiblesError::InUse, | ||
Error::MinBalanceZero => FungiblesError::MinBalanceZero, | ||
Error::Unknown => FungiblesError::Unknown, | ||
_ => todo!() | ||
} | ||
} | ||
} | ||
|
||
/// The fungibles result type. | ||
pub type Result<T> = core::result::Result<T, FungiblesError>; | ||
|
||
#[ink::contract(env = pop_api::Environment)] | ||
mod fungibles { | ||
use super::*; | ||
|
||
#[ink(storage)] | ||
#[derive(Default)] | ||
pub struct Fungibles; | ||
|
||
impl Fungibles { | ||
#[ink(constructor, payable)] | ||
pub fn new() -> Self { | ||
ink::env::debug_println!("PopApiAssetsExample::new"); | ||
Default::default() | ||
} | ||
|
||
#[ink(message)] | ||
pub fn total_supply(&self, id: AssetId) -> Result<Balance> { | ||
total_supply(id).map_err(From::from) | ||
} | ||
|
||
#[ink(message)] | ||
pub fn balance_of(&self, id: AssetId, owner: AccountId32) -> Result<Balance> { | ||
balance_of(id, owner).map_err(From::from) | ||
} | ||
|
||
#[ink(message)] | ||
pub fn allowance(&self, id: AssetId, owner: AccountId32, spender: AccountId32) -> Result<Balance> { | ||
allowance(id, owner, spender).map_err(From::from) | ||
} | ||
|
||
// #[ink(message)] | ||
// pub fn token_name(id: AssetId) -> Result<Option<Vec<u8>>> { | ||
// token_name(id) | ||
// } | ||
// | ||
// #[ink(message)] | ||
// pub fn mint_asset( | ||
// &mut self, | ||
// id: u32, | ||
// beneficiary: AccountId, | ||
// amount: Balance, | ||
// ) -> Result<()> { | ||
// ink::env::debug_println!( | ||
// "PopApiAssetsExample::mint_asset_through_runtime: id: {:?} beneficiary: {:?} amount: {:?}", | ||
// id, | ||
// beneficiary, | ||
// amount | ||
// ); | ||
// | ||
// // Check if asset doesn't exist. | ||
// if !asset_exists(id)? { | ||
// return Err(FungiblesError::UnknownAsset); | ||
// } | ||
// | ||
// // Mint asset via pop api. | ||
// mint(id, beneficiary, amount)?; | ||
// ink::env::debug_println!( | ||
// "PopApiAssetsExample::mint_asset_through_runtime: asset(s) minted successfully" | ||
// ); | ||
// Ok(()) | ||
// } | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[ink::test] | ||
fn default_works() { | ||
PopApiAssetsExample::new(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.