mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 05:57:59 +00:00
Changed query_account_balances return type (#2455)
This commit is contained in:
@@ -31,11 +31,16 @@ pub enum FungiblesAccessError {
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// The API for querying account's balances from runtime.
|
||||
#[api_version(2)]
|
||||
pub trait FungiblesApi<AccountId>
|
||||
where
|
||||
AccountId: Codec,
|
||||
{
|
||||
/// Returns the list of all [`MultiAsset`] that an `AccountId` has.
|
||||
#[changed_in(2)]
|
||||
fn query_account_balances(account: AccountId) -> Result<Vec<MultiAsset>, FungiblesAccessError>;
|
||||
|
||||
/// Returns the list of all [`MultiAsset`] that an `AccountId` has.
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedMultiAssets, FungiblesAccessError>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -951,7 +951,7 @@ impl_runtime_apis! {
|
||||
AccountId,
|
||||
> for Runtime
|
||||
{
|
||||
fn query_account_balances(account: AccountId) -> Result<Vec<xcm::latest::MultiAsset>, assets_common::runtime_api::FungiblesAccessError> {
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedMultiAssets, assets_common::runtime_api::FungiblesAccessError> {
|
||||
use assets_common::fungible_conversion::{convert, convert_balance};
|
||||
Ok([
|
||||
// collect pallet_balance
|
||||
@@ -976,7 +976,7 @@ impl_runtime_apis! {
|
||||
.filter(|(_, balance)| balance > &0)
|
||||
)?,
|
||||
// collect ... e.g. other tokens
|
||||
].concat())
|
||||
].concat().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -383,7 +383,11 @@ fn test_assets_balances_api_works() {
|
||||
0
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0);
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE)).unwrap().is_empty());
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_as::<MultiAssets>()
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
||||
// Drip some balance
|
||||
use frame_support::traits::fungible::Mutate;
|
||||
@@ -437,24 +441,27 @@ fn test_assets_balances_api_works() {
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency);
|
||||
|
||||
let result = Runtime::query_account_balances(AccountId::from(ALICE)).unwrap();
|
||||
let result: MultiAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
assert_eq!(result.len(), 3);
|
||||
|
||||
// check currency
|
||||
assert!(result.iter().any(|asset| asset.eq(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(
|
||||
&assets_common::fungible_conversion::convert_balance::<KsmLocation, Balance>(
|
||||
some_currency
|
||||
)
|
||||
.unwrap()
|
||||
)));
|
||||
// check trusted asset
|
||||
assert!(result.iter().any(|asset| asset.eq(&(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(),
|
||||
minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
// check foreign asset
|
||||
assert!(result.iter().any(|asset| asset.eq(&(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
Identity::reverse_ref(foreign_asset_id_multilocation).unwrap(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
)
|
||||
|
||||
@@ -855,7 +855,7 @@ impl_runtime_apis! {
|
||||
AccountId,
|
||||
> for Runtime
|
||||
{
|
||||
fn query_account_balances(account: AccountId) -> Result<Vec<xcm::latest::MultiAsset>, assets_common::runtime_api::FungiblesAccessError> {
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedMultiAssets, assets_common::runtime_api::FungiblesAccessError> {
|
||||
use assets_common::fungible_conversion::{convert, convert_balance};
|
||||
Ok([
|
||||
// collect pallet_balance
|
||||
@@ -874,7 +874,7 @@ impl_runtime_apis! {
|
||||
.filter(|(_, balance)| balance > &0)
|
||||
)?,
|
||||
// collect ... e.g. pallet_assets ForeignAssets
|
||||
].concat())
|
||||
].concat().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -389,7 +389,11 @@ fn test_assets_balances_api_works() {
|
||||
// check before
|
||||
assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0);
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE)).unwrap().is_empty());
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_as::<MultiAssets>()
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
||||
// Drip some balance
|
||||
use frame_support::traits::fungible::Mutate;
|
||||
@@ -421,18 +425,21 @@ fn test_assets_balances_api_works() {
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency);
|
||||
|
||||
let result = Runtime::query_account_balances(AccountId::from(ALICE)).unwrap();
|
||||
let result: MultiAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
assert_eq!(result.len(), 2);
|
||||
|
||||
// check currency
|
||||
assert!(result.iter().any(|asset| asset.eq(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(
|
||||
&assets_common::fungible_conversion::convert_balance::<DotLocation, Balance>(
|
||||
some_currency
|
||||
)
|
||||
.unwrap()
|
||||
)));
|
||||
// check trusted asset
|
||||
assert!(result.iter().any(|asset| asset.eq(&(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(),
|
||||
minimum_asset_balance
|
||||
)
|
||||
|
||||
@@ -963,7 +963,7 @@ impl_runtime_apis! {
|
||||
AccountId,
|
||||
> for Runtime
|
||||
{
|
||||
fn query_account_balances(account: AccountId) -> Result<Vec<xcm::latest::MultiAsset>, assets_common::runtime_api::FungiblesAccessError> {
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedMultiAssets, assets_common::runtime_api::FungiblesAccessError> {
|
||||
use assets_common::fungible_conversion::{convert, convert_balance};
|
||||
Ok([
|
||||
// collect pallet_balance
|
||||
@@ -988,7 +988,7 @@ impl_runtime_apis! {
|
||||
.filter(|(_, balance)| balance > &0)
|
||||
)?,
|
||||
// collect ... e.g. other tokens
|
||||
].concat())
|
||||
].concat().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -388,7 +388,11 @@ fn test_assets_balances_api_works() {
|
||||
0
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0);
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE)).unwrap().is_empty());
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_as::<MultiAssets>()
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
||||
// Drip some balance
|
||||
use frame_support::traits::fungible::Mutate;
|
||||
@@ -442,24 +446,27 @@ fn test_assets_balances_api_works() {
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency);
|
||||
|
||||
let result = Runtime::query_account_balances(AccountId::from(ALICE)).unwrap();
|
||||
let result: MultiAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
assert_eq!(result.len(), 3);
|
||||
|
||||
// check currency
|
||||
assert!(result.iter().any(|asset| asset.eq(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(
|
||||
&assets_common::fungible_conversion::convert_balance::<WestendLocation, Balance>(
|
||||
some_currency
|
||||
)
|
||||
.unwrap()
|
||||
)));
|
||||
// check trusted asset
|
||||
assert!(result.iter().any(|asset| asset.eq(&(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(),
|
||||
minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
// check foreign asset
|
||||
assert!(result.iter().any(|asset| asset.eq(&(
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
Identity::reverse_ref(foreign_asset_id_multilocation).unwrap(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user