From da09507ffc1f136dca97e13b59ef0164179f08b6 Mon Sep 17 00:00:00 2001 From: devdanco Date: Mon, 4 Sep 2023 13:30:05 +0200 Subject: [PATCH] remove rpc vesting method --- frame/vesting-mangata/rpc/Cargo.toml | 36 ------ frame/vesting-mangata/rpc/README.md | 3 - .../rpc/runtime-api/Cargo.toml | 30 ----- .../vesting-mangata/rpc/runtime-api/README.md | 3 - .../rpc/runtime-api/src/lib.rs | 39 ------ frame/vesting-mangata/rpc/src/lib.rs | 114 ------------------ frame/vesting-mangata/src/lib.rs | 16 --- 7 files changed, 241 deletions(-) delete mode 100644 frame/vesting-mangata/rpc/Cargo.toml delete mode 100644 frame/vesting-mangata/rpc/README.md delete mode 100644 frame/vesting-mangata/rpc/runtime-api/Cargo.toml delete mode 100644 frame/vesting-mangata/rpc/runtime-api/README.md delete mode 100644 frame/vesting-mangata/rpc/runtime-api/src/lib.rs delete mode 100644 frame/vesting-mangata/rpc/src/lib.rs diff --git a/frame/vesting-mangata/rpc/Cargo.toml b/frame/vesting-mangata/rpc/Cargo.toml deleted file mode 100644 index f525b4cd3f074..0000000000000 --- a/frame/vesting-mangata/rpc/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "pallet-vesting-mangata-rpc" -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 = "RPC interface for the transaction payment pallet." -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0" } -jsonrpsee = { version = "0.16.2", features = ["server", "macros"] } -pallet-vesting-mangata-rpc-runtime-api = { version = "4.0.0-dev", path = "./runtime-api" } -pallet-vesting-mangata = { version = "4.0.0-dev", default-features = false, path = "../../vesting-mangata" } -sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" } -sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } -sp-core = { version = "7.0.0", path = "../../../primitives/core" } -sp-rpc = { version = "6.0.0", path = "../../../primitives/rpc" } -sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } -sp-std = { version = "5.0.0", default-features = false, path = "../../../primitives/std" } - -[features] -default = ["std"] -std = [ - "sp-api/std", - "sp-core/std", - "sp-std/std", - "sp-runtime/std", - "pallet-vesting-mangata-rpc-runtime-api/std", - "pallet-vesting-mangata/std" -] diff --git a/frame/vesting-mangata/rpc/README.md b/frame/vesting-mangata/rpc/README.md deleted file mode 100644 index fd0c840e1d48d..0000000000000 --- a/frame/vesting-mangata/rpc/README.md +++ /dev/null @@ -1,3 +0,0 @@ -RPC interface for the vesting-mangata pallet. - -License: Apache-2.0 diff --git a/frame/vesting-mangata/rpc/runtime-api/Cargo.toml b/frame/vesting-mangata/rpc/runtime-api/Cargo.toml deleted file mode 100644 index a3706fcb5626a..0000000000000 --- a/frame/vesting-mangata/rpc/runtime-api/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "pallet-vesting-mangata-rpc-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 = "RPC runtime API for transaction payment FRAME pallet" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -pallet-vesting-mangata = { version = "4.0.0-dev", default-features = false, path = "../../../vesting-mangata" } -sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../../primitives/api" } -sp-runtime = { version = "7.0.0", default-features = false, path = "../../../../primitives/runtime" } -sp-std = { version = "5.0.0", default-features = false, path = "../../../../primitives/std" } - -[features] -default = ["std"] -std = [ - "codec/std", - "pallet-vesting-mangata/std", - "sp-api/std", - "sp-std/std", - "sp-runtime/std", -] diff --git a/frame/vesting-mangata/rpc/runtime-api/README.md b/frame/vesting-mangata/rpc/runtime-api/README.md deleted file mode 100644 index 0d81abdb1eeb3..0000000000000 --- a/frame/vesting-mangata/rpc/runtime-api/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Runtime API definition for transaction payment pallet. - -License: Apache-2.0 diff --git a/frame/vesting-mangata/rpc/runtime-api/src/lib.rs b/frame/vesting-mangata/rpc/runtime-api/src/lib.rs deleted file mode 100644 index 4ad785c62cb6e..0000000000000 --- a/frame/vesting-mangata/rpc/runtime-api/src/lib.rs +++ /dev/null @@ -1,39 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-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 transaction payment pallet. - -#![cfg_attr(not(feature = "std"), no_std)] - -use codec::{Codec, Decode, Encode}; - -#[cfg(not(feature = "std"))] -use sp_std::{vec, vec::Vec}; - -use sp_runtime::traits::{MaybeDisplay, MaybeFromStr}; - -sp_api::decl_runtime_apis! { - pub trait VestingMangataApi where - AccountId: Codec + MaybeDisplay + MaybeFromStr, - Balance: Codec + MaybeDisplay + MaybeFromStr, - TokenId: Codec + MaybeDisplay + MaybeFromStr, - BlockNumber: Codec + MaybeDisplay + MaybeFromStr, - { - fn get_vesting_locked_at(who: AccountId, token_id: TokenId, at_block_number: Option) -> Vec; - } -} - diff --git a/frame/vesting-mangata/rpc/src/lib.rs b/frame/vesting-mangata/rpc/src/lib.rs deleted file mode 100644 index 58e99297cd9ad..0000000000000 --- a/frame/vesting-mangata/rpc/src/lib.rs +++ /dev/null @@ -1,114 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-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. - -//! RPC interface for the transaction payment pallet. - -use std::{convert::TryInto, sync::Arc}; - -use codec::{Codec, Decode}; -use jsonrpsee::{ - core::{async_trait, Error as JsonRpseeError, RpcResult}, - proc_macros::rpc, - types::error::{CallError, ErrorCode, ErrorObject}, -}; -use sp_core::U256; -pub use pallet_vesting_mangata::{VestingInfo}; -use sp_api::ProvideRuntimeApi; -use sp_blockchain::HeaderBackend; -use sp_core::Bytes; -use sp_rpc::number::NumberOrHex; -use sp_runtime::{ - generic::BlockId, - traits::{Block as BlockT, MaybeDisplay, MaybeFromStr}, -}; - -pub use pallet_vesting_mangata_rpc_runtime_api::VestingMangataApi as VestingMangataRuntimeApi; - -#[rpc(client, server)] -pub trait VestingMangataApi { - #[method(name = "vesting_getVestingLockedAt")] - fn get_vesting_locked_at(&self, who: AccountId, token_id: TokenId, at_block_number: Option, at: Option) -> RpcResult>; -} - -/// Provides RPC methods to query a dispatchable's class, weight and fee. -pub struct VestingMangata { - /// Shared reference to the client. - client: Arc, - _marker: std::marker::PhantomData

, -} - -impl VestingMangata { - /// Creates a new instance of the TransactionPayment Rpc helper. - pub fn new(client: Arc) -> Self { - Self { client, _marker: Default::default() } - } -} - -trait TryIntoBalance { - fn try_into_balance(self) -> RpcResult; -} - -impl> TryIntoBalance for NumberOrHex { - fn try_into_balance(self) -> RpcResult { - self.into_u256().try_into().or(Err(JsonRpseeError::Call(CallError::Custom( - ErrorObject::owned( - 1, - "Unable to serve the request", - Some(String::from("input parameter doesnt fit into u128")), - ), - )))) - } -} - -#[async_trait] -impl - VestingMangataApiServer< - ::Hash, - AccountId, - TokenId, - Balance, - BlockNumber> - for VestingMangata -where - Block: BlockT, - C: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static, - C::Api: VestingMangataRuntimeApi, - Balance: Codec + MaybeDisplay + MaybeFromStr + TryFrom + Into, - TokenId: Codec + MaybeDisplay + MaybeFromStr, - BlockNumber: Codec + MaybeDisplay + MaybeFromStr, - AccountId: Codec + MaybeDisplay + MaybeFromStr, -{ - fn get_vesting_locked_at(&self, who: AccountId, token_id: TokenId, at_block_number: Option, at: Option<::Hash>) - -> RpcResult> { - let api = self.client.runtime_api(); - let at = self.client.info().best_hash; - - let runtime_api_result = api.get_vesting_locked_at( - at, - who, - token_id, - at_block_number, - ); - runtime_api_result.map_err(|e| { - JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( - 1, - "Unable to serve the request", - Some(format!("{:?}", e)), - ))) - }) - } -} diff --git a/frame/vesting-mangata/src/lib.rs b/frame/vesting-mangata/src/lib.rs index 44533fc354661..a3a9fd0280383 100644 --- a/frame/vesting-mangata/src/lib.rs +++ b/frame/vesting-mangata/src/lib.rs @@ -435,22 +435,6 @@ pub mod pallet { } impl Pallet { - pub fn get_vesting_locked_at( - who: &T::AccountId, - token_id: TokenIdOf, - at_block_number: Option, - ) -> Result>, DispatchError> { - let at_block_number = at_block_number.unwrap_or(>::block_number()); - Ok(Self::vesting(&who, token_id) - .ok_or(Error::::NotVesting)? - .to_vec() - .into_iter() - .map(|x| { - BalanceOf::::from(x.locked_at::(at_block_number)) - }) - .collect::>>()) - } - // Create a new `VestingInfo`, based off of two other `VestingInfo`s. // NOTE: We assume both schedules have had funds unlocked up through the current block. fn merge_vesting_info(