Skip to content

Commit

Permalink
Update upgradeable-polymesh-ink to use AssetID (#1729)
Browse files Browse the repository at this point in the history
* Update upgradeable-polymesh-ink to use AssetID

* Fix create_and_issue

* Update dependencies

* Add GetNextAssetId chain extension

* Add unimplemented get_asset_id in contracts

* Add chain_extension_get_next_asset_id weights

* Add account as a parameter in get_next_asset_id

* Add call to new chain extension method

* Update cargo lock

* Update runtime-tester and cargo update polymesh-api.

* Remove extra import and fix Vec import issue.

---------

Co-authored-by: Adam Dossa <[email protected]>
Co-authored-by: Robert G. Jakabosky <[email protected]>
  • Loading branch information
3 people authored Oct 28, 2024
1 parent a1e591b commit 16cf9e9
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 185 deletions.
20 changes: 10 additions & 10 deletions contracts/runtime-tester/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/runtime-tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink = { version = "4.3", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

polymesh-api = { version = "3.7", default-features = false, features = ["ink"] }
polymesh-api = { version = "3.9", default-features = false, features = ["ink", "polymesh_v7"] }

[lib]
path = "lib.rs"
Expand Down
38 changes: 24 additions & 14 deletions contracts/runtime-tester/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ extern crate alloc;
use alloc::vec::Vec;

use polymesh_api::{
ink::{basic_types::IdentityId, extension::PolymeshEnvironment, Error as PolymeshInkError},
ink::{basic_types::{AssetId, IdentityId},
extension::PolymeshEnvironment, Error as PolymeshInkError},
polymesh::types::{
polymesh_contracts::Api as ContractRuntimeApi,
polymesh_primitives::{
Expand Down Expand Up @@ -70,6 +71,14 @@ mod runtime_tester {
.map_err(|err| Error::PolymeshRuntime(err))
}

#[ink(message)]
pub fn get_next_asset_id(&self, account: AccountId) -> Result<AssetId> {
let api = Api::new();
api.runtime()
.get_next_asset_id(account)
.map_err(|err| Error::PolymeshRuntime(err))
}

#[ink(message)]
pub fn get_spec_version(&self) -> Result<u32> {
Self::env()
Expand All @@ -95,33 +104,33 @@ mod runtime_tester {
}

#[ink(message)]
pub fn asset_balance_of(&self, ticker: Ticker, did: IdentityId) -> Result<u128> {
pub fn asset_balance_of(&self, asset: AssetId, did: IdentityId) -> Result<u128> {
let api = Api::new();
api.query()
.asset()
.balance_of(ticker, did)
.balance_of(asset, did)
.map_err(|err| Error::PolymeshRuntime(err))
}

#[ink(message)]
pub fn portfolio_asset_balance(
&self,
portfolio: PortfolioId,
ticker: Ticker,
asset: AssetId,
) -> Result<u128> {
let api = Api::new();
api.query()
.portfolio()
.portfolio_asset_balances(portfolio, ticker)
.portfolio_asset_balances(portfolio, asset)
.map_err(|err| Error::PolymeshRuntime(err))
}

#[ink(message)]
pub fn register_ticker(&mut self, ticker: Ticker) -> Result<()> {
pub fn register_unique_ticker(&mut self, ticker: Ticker) -> Result<()> {
let api = Api::new();
api.call()
.asset()
.register_ticker(ticker)
.register_unique_ticker(ticker)
.submit()
.map_err(|err| Error::PolymeshRuntime(err))
}
Expand Down Expand Up @@ -149,19 +158,22 @@ mod runtime_tester {
fn create_asset(
&mut self,
name: AssetName,
ticker: Ticker,
asset_type: AssetType,
supply: u128,
) -> Result<()> {
let api = Api::new();
let account = ink::env::account_id::<PolymeshEnvironment>();
let asset = api.runtime()
.get_next_asset_id(account)
.map_err(|err| Error::PolymeshRuntime(err))?;
api.call()
.asset()
.create_asset(name, ticker.clone(), true, asset_type, vec![], None)
.create_asset(name, true, asset_type, vec![], None)
.submit()
.map_err(|err| Error::PolymeshRuntime(err))?;
api.call()
.asset()
.issue(ticker, supply, PortfolioKind::Default)
.issue(asset, supply, PortfolioKind::Default)
.submit()
.map_err(|err| Error::PolymeshRuntime(err))
}
Expand All @@ -171,27 +183,25 @@ mod runtime_tester {
pub fn create_asset_and_issue(
&mut self,
name: AssetName,
ticker: Ticker,
asset_type: AssetType,
supply: u128,
) -> Result<()> {
self.create_asset(name, ticker, asset_type, supply)
self.create_asset(name, asset_type, supply)
}

#[ink(message, payable)]
/// Create asset where the caller need to pay the asset creation fees (3k POLYX).
pub fn payable_create_asset_and_issue(
&mut self,
name: AssetName,
ticker: Ticker,
asset_type: AssetType,
supply: u128,
) -> Result<()> {
let transferred = Self::env().transferred_value();
if transferred < CREATE_ASSET_FEE {
return Err(Error::InsufficientTransferValue(CREATE_ASSET_FEE));
}
self.create_asset(name, ticker, asset_type, supply)
self.create_asset(name, asset_type, supply)
}

#[ink(message)]
Expand Down
21 changes: 10 additions & 11 deletions contracts/upgradeable-polymesh-ink/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions contracts/upgradeable-polymesh-ink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polymesh-ink"
version = "3.3.0"
version = "3.4.0"
authors = ["PolymeshAssociation"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -11,14 +11,11 @@ homepage = "https://github.com/PolymeshAssociation/Polymesh"

[dependencies]
ink = { version = "4.3", default-features = false }

paste = "1.0"
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

polymesh-api = { version = "3.7", default-features = false, features = ["ink"] }
polymesh-api-ink = { version = "1.3.0", default-features = false, features = ["use_call_runtime_with_error"] }

paste = "1.0"
polymesh-api = { version = "3.9.1", default-features = false, features = ["ink", "polymesh_v7"] }

[lib]
path = "src/lib.rs"
Expand All @@ -34,8 +31,8 @@ as-library = []

std = [
"ink/std",
"polymesh-api/std",
"scale/std",
"scale-info/std",
"polymesh-api/std",
]
ink-as-dependency = []
Loading

0 comments on commit 16cf9e9

Please sign in to comment.