-
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.
feat: pallet assets pop api integration
- Loading branch information
1 parent
5708c0d
commit 3fc65ba
Showing
17 changed files
with
1,222 additions
and
258 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore build artifacts from the local tests sub-crate. | ||
/target/ | ||
|
||
# Ignore backup files creates by cargo fmt. | ||
**/*.rs.bk | ||
|
||
# Remove Cargo.lock when creating an executable, leave it for libraries | ||
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
Cargo.lock |
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,25 @@ | ||
[package] | ||
name = "pop_api_trust_backed_assets_example" | ||
version = "0.1.0" | ||
authors = ["[your_name] <[your_email]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ink = { version = "5.0.0", default-features = false } | ||
pop-api = { path = "../../../pop-api", default-features = false } | ||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } | ||
|
||
[lib] | ||
path = "lib.rs" | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink/std", | ||
"pop-api/std", | ||
"scale/std", | ||
"scale-info/std", | ||
] | ||
ink-as-dependency = [] | ||
e2e-tests = [] |
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,69 @@ | ||
#![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
|
||
use pop_api::assets::trust_backed as trust_backed_assets; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] | ||
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | ||
pub enum ContractError { | ||
TrustBackedAssetsError(trust_backed_assets::Error), | ||
UnknownAsset, | ||
} | ||
|
||
impl From<trust_backed_assets::Error> for ContractError { | ||
fn from(value: trust_backed_assets::Error) -> Self { | ||
ContractError::TrustBackedAssetsError(value) | ||
} | ||
} | ||
|
||
#[ink::contract(env = pop_api::Environment)] | ||
mod pop_api_extension_demo { | ||
use super::*; | ||
|
||
#[ink(storage)] | ||
#[derive(Default)] | ||
pub struct PopApiExtensionDemo; | ||
|
||
impl PopApiExtensionDemo { | ||
#[ink(constructor, payable)] | ||
pub fn new() -> Self { | ||
ink::env::debug_println!("Contract::new"); | ||
Default::default() | ||
} | ||
|
||
#[ink(message)] | ||
pub fn mint_asset_through_runtime( | ||
&mut self, | ||
id: u32, | ||
beneficiary: AccountId, | ||
amount: Balance, | ||
) -> Result<(), ContractError> { | ||
ink::env::debug_println!( | ||
"Contract::mint_asset_through_runtime: id: {:?} beneficiary: {:?} amount: {:?}", | ||
id, | ||
beneficiary, | ||
amount | ||
); | ||
|
||
// Check if asset doesn't exist. | ||
if !trust_backed_assets::asset_exists(id)? { | ||
return Err(ContractError::UnknownAsset); | ||
} | ||
|
||
// Mint asset via pop api. | ||
trust_backed_assets::mint(id, beneficiary, amount)?; | ||
ink::env::debug_println!("Contract::mint_asset_through_runtime: asset(s) minted successfully"); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[ink::test] | ||
fn default_works() { | ||
PopApiExtensionDemo::new(); | ||
} | ||
} | ||
} | ||
|
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 @@ | ||
pub mod trust_backed; |
Oops, something went wrong.