-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Return account's asset balances #13352
Changes from all commits
20eb6d4
2465123
bbe9efb
45d7303
14a9cd2
668838d
e7a3271
86e373c
f69a356
3785aef
1a2ed63
1689507
ea653a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2018-2022 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! Runtime API definition for assets. | ||
|
||
use codec::Codec; | ||
use sp_std::vec::Vec; | ||
|
||
sp_api::decl_runtime_apis! { | ||
pub trait AssetsApi<AccountId, AssetBalance, AssetId> | ||
where | ||
AccountId: Codec, | ||
AssetBalance: Codec, | ||
AssetId: Codec, | ||
{ | ||
/// Returns the list of `AssetId`s and corresponding balance that an `AccountId` has. | ||
fn account_balances(account: AccountId) -> Vec<(AssetId, AssetBalance)>; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -924,4 +924,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> { | |||||
Ok(()) | ||||||
}) | ||||||
} | ||||||
|
||||||
/// Returns all the non-zero balances for all assets of the given `account`. | ||||||
pub fn account_balances(account: T::AccountId) -> Vec<(T::AssetId, T::Balance)> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then the node implementing this can decide up to how many iterations it wants to support. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The node does not augments calls to the runtime. So, what ever calls this would need to set this value. But I'm fine with the idea in general There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think this approach will work in general. This will need to have proper paging support to be exhaustive and this kind of API is simply impossible for ERC20 tokens implementation. |
||||||
Asset::<T, I>::iter_keys() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.filter_map(|id| Self::maybe_balance(id, account.clone()).map(|balance| (id, balance))) | ||||||
.collect::<Vec<_>>() | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this re-defined in every single runtime in Cumulus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is just one common definition for all statemine/t runtimes (statemine/statemint/westmint),
but lets discuss it here: paritytech/cumulus#2180 (comment)