From 20eb6d4708e5b74ab8b807cb12b37f24e7c0710d Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Thu, 9 Feb 2023 18:40:15 +0200 Subject: [PATCH 1/9] Runtime method to get user's assets balances --- Cargo.lock | 10 +++++++++ Cargo.toml | 1 + bin/node/runtime/Cargo.toml | 2 ++ bin/node/runtime/src/lib.rs | 14 ++++++++++++ frame/assets/runtime-api/Cargo.toml | 26 +++++++++++++++++++++ frame/assets/runtime-api/README.md | 3 +++ frame/assets/runtime-api/src/lib.rs | 35 +++++++++++++++++++++++++++++ frame/assets/src/functions.rs | 7 ++++++ frame/assets/src/tests.rs | 5 ++++- 9 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 frame/assets/runtime-api/Cargo.toml create mode 100644 frame/assets/runtime-api/README.md create mode 100644 frame/assets/runtime-api/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3e5ab65c0ce20..da652db046ea0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3531,6 +3531,7 @@ dependencies = [ "pallet-alliance", "pallet-asset-tx-payment", "pallet-assets", + "pallet-assets-runtime-api", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", @@ -5348,6 +5349,15 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-assets-runtime-api" +version = "4.0.0-dev" +dependencies = [ + "parity-scale-codec", + "sp-api", + "sp-std", +] + [[package]] name = "pallet-atomic-swap" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index aaa1c2a211183..bcf7a89d66e6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,7 @@ members = [ "client/utils", "frame/alliance", "frame/assets", + "frame/assets/runtime-api", "frame/atomic-swap", "frame/aura", "frame/authority-discovery", diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 1d2e6f057d517..e2b5a645bc2af 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -53,6 +53,7 @@ frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false frame-try-runtime = { version = "0.10.0-dev", default-features = false, path = "../../../frame/try-runtime", optional = true } pallet-alliance = { version = "4.0.0-dev", default-features = false, path = "../../../frame/alliance" } pallet-assets = { version = "4.0.0-dev", default-features = false, path = "../../../frame/assets" } +pallet-assets-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/assets/runtime-api" } pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authority-discovery" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authorship" } pallet-babe = { version = "4.0.0-dev", default-features = false, path = "../../../frame/babe" } @@ -128,6 +129,7 @@ std = [ "frame-election-provider-support/std", "sp-authority-discovery/std", "pallet-assets/std", + "pallet-assets-runtime-api/std", "pallet-authority-discovery/std", "pallet-authorship/std", "sp-consensus-babe/std", diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 4298a6eced430..05978b20f0e3b 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -2045,6 +2045,20 @@ impl_runtime_apis! { } } + impl pallet_assets_runtime_api::AssetsApi< + Block, + AccountId, + Balance, + u32, + > for Runtime + { + fn account_balances(instance: u8, account: AccountId) -> Vec<(u32, Balance)> { + match instance { + _ => Assets::account_balances(instance, account), + } + } + } + impl pallet_contracts::ContractsApi for Runtime { fn call( diff --git a/frame/assets/runtime-api/Cargo.toml b/frame/assets/runtime-api/Cargo.toml new file mode 100644 index 0000000000000..cd470ff4c579a --- /dev/null +++ b/frame/assets/runtime-api/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "pallet-assets-runtime-api" +version = "4.0.0-dev" +authors = ["Parity Technologies "] +edition = "2021" +license = "Apache-2.0" +homepage = "https://substrate.io" +repository = "https://github.com/paritytech/substrate/" +description = "Runtime API for assets FRAME pallet" +readme = "README.md" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" } +sp-std = { version = "5.0.0", default-features = false, path = "../../../primitives/std" } + +[features] +default = ["std"] +std = [ + "codec/std", + "sp-api/std", + "sp-std/std", +] diff --git a/frame/assets/runtime-api/README.md b/frame/assets/runtime-api/README.md new file mode 100644 index 0000000000000..5a04412685222 --- /dev/null +++ b/frame/assets/runtime-api/README.md @@ -0,0 +1,3 @@ +Runtime API definition for assets pallet. + +License: Apache-2.0 diff --git a/frame/assets/runtime-api/src/lib.rs b/frame/assets/runtime-api/src/lib.rs new file mode 100644 index 0000000000000..ee15c0e9cdc8b --- /dev/null +++ b/frame/assets/runtime-api/src/lib.rs @@ -0,0 +1,35 @@ +// This file is part of Substrate. + +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Runtime API definition for assets pallet. +//! Currently supports only one rpc endpoint. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::Codec; +use sp_std::vec::Vec; + +sp_api::decl_runtime_apis! { + pub trait AssetsApi where + AccountId: Codec, + AssetBalance: Codec, + AssetId: Codec + { + /// Returns the list of asset id and non-zero balance the AccountId has. + fn account_balances(instance: u8, account: AccountId) -> Vec<(AssetId, AssetBalance)>; + } +} diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index b540f02b87c82..66d0e15355939 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -924,4 +924,11 @@ impl, I: 'static> Pallet { Ok(()) }) } + + /// Used by the RPC service to provide account balances. + pub fn account_balances(_instance: u8, account: T::AccountId) -> Vec<(T::AssetId, T::Balance)> { + Asset::::iter_keys() + .filter_map(|id| Self::maybe_balance(id, account.clone()).map(|balance| (id, balance))) + .collect::>() + } } diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index f7007ff3ccf17..3d33f84b6e3ff 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -37,11 +37,14 @@ fn asset_ids() -> Vec { fn basic_minting_should_work() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, true, 1)); + assert_ok!(Assets::force_create(RuntimeOrigin::root(), 1, 1, true, 1)); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 1, 100)); assert_eq!(Assets::balance(0, 1), 100); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 0, 2, 100)); assert_eq!(Assets::balance(0, 2), 100); - assert_eq!(asset_ids(), vec![0, 999]); + assert_eq!(asset_ids(), vec![0, 1, 999]); + assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 1, 1, 100)); + assert_eq!(Assets::account_balances(1), vec![(0, 100), (999, 100), (1, 100)]); }); } From 2465123e2b6639154f1538566f6ba2b7baa1c267 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Thu, 9 Feb 2023 18:54:19 +0200 Subject: [PATCH 2/9] Fix test (typo) --- frame/assets/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index 3d33f84b6e3ff..3e00e3711da59 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -44,7 +44,7 @@ fn basic_minting_should_work() { assert_eq!(Assets::balance(0, 2), 100); assert_eq!(asset_ids(), vec![0, 1, 999]); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 1, 1, 100)); - assert_eq!(Assets::account_balances(1), vec![(0, 100), (999, 100), (1, 100)]); + assert_eq!(Assets::account_balances(0, 1), vec![(0, 100), (999, 100), (1, 100)]); }); } From bbe9efb2a1f26d4c31e89a82ceef9b1a57b17e84 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> Date: Thu, 9 Feb 2023 19:00:41 +0200 Subject: [PATCH 3/9] Update frame/assets/src/functions.rs --- frame/assets/src/functions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index 66d0e15355939..56d4247def2c0 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -926,7 +926,7 @@ impl, I: 'static> Pallet { } /// Used by the RPC service to provide account balances. - pub fn account_balances(_instance: u8, account: T::AccountId) -> Vec<(T::AssetId, T::Balance)> { + pub fn account_balances(_: u8, account: T::AccountId) -> Vec<(T::AssetId, T::Balance)> { Asset::::iter_keys() .filter_map(|id| Self::maybe_balance(id, account.clone()).map(|balance| (id, balance))) .collect::>() From 45d73031c31e8b5a7f09ed5e2faeb8507b0e224f Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Thu, 9 Feb 2023 19:07:23 +0200 Subject: [PATCH 4/9] Remove instance param --- bin/node/runtime/src/lib.rs | 2 +- frame/assets/src/functions.rs | 2 +- frame/assets/src/tests.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 05978b20f0e3b..dbd1fcc00661e 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -2054,7 +2054,7 @@ impl_runtime_apis! { { fn account_balances(instance: u8, account: AccountId) -> Vec<(u32, Balance)> { match instance { - _ => Assets::account_balances(instance, account), + _ => Assets::account_balances(account), } } } diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index 56d4247def2c0..4d6bd6d4e9bc3 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -926,7 +926,7 @@ impl, I: 'static> Pallet { } /// Used by the RPC service to provide account balances. - pub fn account_balances(_: u8, account: T::AccountId) -> Vec<(T::AssetId, T::Balance)> { + pub fn account_balances(account: T::AccountId) -> Vec<(T::AssetId, T::Balance)> { Asset::::iter_keys() .filter_map(|id| Self::maybe_balance(id, account.clone()).map(|balance| (id, balance))) .collect::>() diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index 3e00e3711da59..3d33f84b6e3ff 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -44,7 +44,7 @@ fn basic_minting_should_work() { assert_eq!(Assets::balance(0, 2), 100); assert_eq!(asset_ids(), vec![0, 1, 999]); assert_ok!(Assets::mint(RuntimeOrigin::signed(1), 1, 1, 100)); - assert_eq!(Assets::account_balances(0, 1), vec![(0, 100), (999, 100), (1, 100)]); + assert_eq!(Assets::account_balances(1), vec![(0, 100), (999, 100), (1, 100)]); }); } From 14a9cd2e628977ef5652cccaafb585b9f3aef91c Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> Date: Fri, 10 Feb 2023 16:59:54 +0200 Subject: [PATCH 5/9] Update frame/assets/src/functions.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- frame/assets/src/functions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index 4d6bd6d4e9bc3..f23679645e557 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -925,7 +925,7 @@ impl, I: 'static> Pallet { }) } - /// Used by the RPC service to provide account balances. + /// 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)> { Asset::::iter_keys() .filter_map(|id| Self::maybe_balance(id, account.clone()).map(|balance| (id, balance))) From 668838d9d5dd4fd85e4685f972f0d677ba102458 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Fri, 10 Feb 2023 17:05:28 +0200 Subject: [PATCH 6/9] Remove instance param --- bin/node/runtime/src/lib.rs | 6 ++---- frame/assets/runtime-api/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index dbd1fcc00661e..6406803cb2f58 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -2052,10 +2052,8 @@ impl_runtime_apis! { u32, > for Runtime { - fn account_balances(instance: u8, account: AccountId) -> Vec<(u32, Balance)> { - match instance { - _ => Assets::account_balances(account), - } + fn account_balances(account: AccountId) -> Vec<(u32, Balance)> { + Assets::account_balances(account) } } diff --git a/frame/assets/runtime-api/src/lib.rs b/frame/assets/runtime-api/src/lib.rs index ee15c0e9cdc8b..5782bebf3b943 100644 --- a/frame/assets/runtime-api/src/lib.rs +++ b/frame/assets/runtime-api/src/lib.rs @@ -29,7 +29,7 @@ sp_api::decl_runtime_apis! { AssetBalance: Codec, AssetId: Codec { - /// Returns the list of asset id and non-zero balance the AccountId has. - fn account_balances(instance: u8, account: AccountId) -> Vec<(AssetId, AssetBalance)>; + /// Returns the list of asset id and non-zero balances the AccountId has. + fn account_balances(account: AccountId) -> Vec<(AssetId, AssetBalance)>; } } From e7a32712f9cc04b2bc17a0e8fd70b0e1d800cf3c Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Mon, 13 Feb 2023 12:30:24 +0200 Subject: [PATCH 7/9] Refactor --- Cargo.lock | 10 -------- Cargo.toml | 1 - bin/node/runtime/Cargo.toml | 2 -- bin/node/runtime/src/assets_api.rs | 36 +++++++++++++++++++++++++++++ bin/node/runtime/src/lib.rs | 5 +++- frame/assets/runtime-api/Cargo.toml | 26 --------------------- frame/assets/runtime-api/README.md | 3 --- frame/assets/runtime-api/src/lib.rs | 35 ---------------------------- 8 files changed, 40 insertions(+), 78 deletions(-) create mode 100644 bin/node/runtime/src/assets_api.rs delete mode 100644 frame/assets/runtime-api/Cargo.toml delete mode 100644 frame/assets/runtime-api/README.md delete mode 100644 frame/assets/runtime-api/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index da652db046ea0..3e5ab65c0ce20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3531,7 +3531,6 @@ dependencies = [ "pallet-alliance", "pallet-asset-tx-payment", "pallet-assets", - "pallet-assets-runtime-api", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", @@ -5349,15 +5348,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-assets-runtime-api" -version = "4.0.0-dev" -dependencies = [ - "parity-scale-codec", - "sp-api", - "sp-std", -] - [[package]] name = "pallet-atomic-swap" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index bcf7a89d66e6d..aaa1c2a211183 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,6 @@ members = [ "client/utils", "frame/alliance", "frame/assets", - "frame/assets/runtime-api", "frame/atomic-swap", "frame/aura", "frame/authority-discovery", diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index e2b5a645bc2af..1d2e6f057d517 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -53,7 +53,6 @@ frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false frame-try-runtime = { version = "0.10.0-dev", default-features = false, path = "../../../frame/try-runtime", optional = true } pallet-alliance = { version = "4.0.0-dev", default-features = false, path = "../../../frame/alliance" } pallet-assets = { version = "4.0.0-dev", default-features = false, path = "../../../frame/assets" } -pallet-assets-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/assets/runtime-api" } pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authority-discovery" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authorship" } pallet-babe = { version = "4.0.0-dev", default-features = false, path = "../../../frame/babe" } @@ -129,7 +128,6 @@ std = [ "frame-election-provider-support/std", "sp-authority-discovery/std", "pallet-assets/std", - "pallet-assets-runtime-api/std", "pallet-authority-discovery/std", "pallet-authorship/std", "sp-consensus-babe/std", diff --git a/bin/node/runtime/src/assets_api.rs b/bin/node/runtime/src/assets_api.rs new file mode 100644 index 0000000000000..09a12154b559d --- /dev/null +++ b/bin/node/runtime/src/assets_api.rs @@ -0,0 +1,36 @@ +// 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 . + +//! Runtime API definition for assets. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::Codec; +use sp_std::vec::Vec; + +sp_api::decl_runtime_apis! { + pub trait AssetsApi + where + AccountId: Codec, + AssetBalance: Codec, + AssetId: Codec, + { + /// Returns the list of asset id and non-zero balances the AccountId has. + fn account_balances(account: AccountId) -> Vec<(AssetId, AssetBalance)>; + } +} diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 6406803cb2f58..0b3a66e33e144 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -107,6 +107,9 @@ use sp_runtime::generic::Era; /// Generated voter bag information. mod voter_bags; +/// Runtime API definition for assets. +pub mod assets_api; + // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -2045,7 +2048,7 @@ impl_runtime_apis! { } } - impl pallet_assets_runtime_api::AssetsApi< + impl assets_api::AssetsApi< Block, AccountId, Balance, diff --git a/frame/assets/runtime-api/Cargo.toml b/frame/assets/runtime-api/Cargo.toml deleted file mode 100644 index cd470ff4c579a..0000000000000 --- a/frame/assets/runtime-api/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "pallet-assets-runtime-api" -version = "4.0.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "Apache-2.0" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -description = "Runtime API for assets FRAME pallet" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" } -sp-std = { version = "5.0.0", default-features = false, path = "../../../primitives/std" } - -[features] -default = ["std"] -std = [ - "codec/std", - "sp-api/std", - "sp-std/std", -] diff --git a/frame/assets/runtime-api/README.md b/frame/assets/runtime-api/README.md deleted file mode 100644 index 5a04412685222..0000000000000 --- a/frame/assets/runtime-api/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Runtime API definition for assets pallet. - -License: Apache-2.0 diff --git a/frame/assets/runtime-api/src/lib.rs b/frame/assets/runtime-api/src/lib.rs deleted file mode 100644 index 5782bebf3b943..0000000000000 --- a/frame/assets/runtime-api/src/lib.rs +++ /dev/null @@ -1,35 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Runtime API definition for assets pallet. -//! Currently supports only one rpc endpoint. - -#![cfg_attr(not(feature = "std"), no_std)] - -use codec::Codec; -use sp_std::vec::Vec; - -sp_api::decl_runtime_apis! { - pub trait AssetsApi where - AccountId: Codec, - AssetBalance: Codec, - AssetId: Codec - { - /// Returns the list of asset id and non-zero balances the AccountId has. - fn account_balances(account: AccountId) -> Vec<(AssetId, AssetBalance)>; - } -} From 86e373cbb43bbcddba64114248894d26f4b0ebe2 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Mon, 13 Feb 2023 12:38:08 +0200 Subject: [PATCH 8/9] Chore --- bin/node/runtime/src/assets_api.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/node/runtime/src/assets_api.rs b/bin/node/runtime/src/assets_api.rs index 09a12154b559d..5461a05427b41 100644 --- a/bin/node/runtime/src/assets_api.rs +++ b/bin/node/runtime/src/assets_api.rs @@ -18,8 +18,6 @@ //! Runtime API definition for assets. -#![cfg_attr(not(feature = "std"), no_std)] - use codec::Codec; use sp_std::vec::Vec; From 3785aeff56682430aa4972c4db4da4d0d581b768 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Mon, 13 Feb 2023 14:26:24 +0200 Subject: [PATCH 9/9] Update doc --- bin/node/runtime/src/assets_api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/assets_api.rs b/bin/node/runtime/src/assets_api.rs index 5461a05427b41..cf1a663d70300 100644 --- a/bin/node/runtime/src/assets_api.rs +++ b/bin/node/runtime/src/assets_api.rs @@ -28,7 +28,7 @@ sp_api::decl_runtime_apis! { AssetBalance: Codec, AssetId: Codec, { - /// Returns the list of asset id and non-zero balances the AccountId has. + /// Returns the list of `AssetId`s and corresponding balance that an `AccountId` has. fn account_balances(account: AccountId) -> Vec<(AssetId, AssetBalance)>; } }