mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
pallet-contracts: Rent projection RPC (#4754)
* Initial approach * Introduce the pallet-contracts-common crate * Add rent::compute_rent_projection * Wire everything together * Fix build error. * Rename EvictionDate → EvictionAt. * Clean. * Renaming and cleaning. * Add documentation for rent_projection RPC. * Add documentation for rent_projection runtime API. * Refactor rent_budget. Merge it with subsistence_treshold. * Bump impl_version * Constrain RPC impl with Block::Header::Number. * Rename pallet-contracts-common into -primitives * Add a comment for `compute_rent_projection` on the usage * Small tidying
This commit is contained in:
@@ -128,6 +128,7 @@ use frame_support::{
|
||||
use frame_support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get, Time, Randomness};
|
||||
use frame_system::{self as system, ensure_signed, RawOrigin, ensure_root};
|
||||
use sp_core::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
|
||||
use pallet_contracts_primitives::{RentProjection, ContractAccessError};
|
||||
|
||||
pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
|
||||
pub type TrieId = Vec<u8>;
|
||||
@@ -680,14 +681,6 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
/// The possible errors that can happen querying the storage of a contract.
|
||||
pub enum GetStorageError {
|
||||
/// The given address doesn't point on a contract.
|
||||
ContractDoesntExist,
|
||||
/// The specified contract is a tombstone and thus cannot have any storage.
|
||||
IsTombstone,
|
||||
}
|
||||
|
||||
/// Public APIs provided by the contracts module.
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Perform a call to a specified contract.
|
||||
@@ -710,11 +703,11 @@ impl<T: Trait> Module<T> {
|
||||
pub fn get_storage(
|
||||
address: T::AccountId,
|
||||
key: [u8; 32],
|
||||
) -> sp_std::result::Result<Option<Vec<u8>>, GetStorageError> {
|
||||
) -> sp_std::result::Result<Option<Vec<u8>>, ContractAccessError> {
|
||||
let contract_info = <ContractInfoOf<T>>::get(&address)
|
||||
.ok_or(GetStorageError::ContractDoesntExist)?
|
||||
.ok_or(ContractAccessError::DoesntExist)?
|
||||
.get_alive()
|
||||
.ok_or(GetStorageError::IsTombstone)?;
|
||||
.ok_or(ContractAccessError::IsTombstone)?;
|
||||
|
||||
let maybe_value = AccountDb::<T>::get_storage(
|
||||
&DirectAccountDb,
|
||||
@@ -724,6 +717,12 @@ impl<T: Trait> Module<T> {
|
||||
);
|
||||
Ok(maybe_value)
|
||||
}
|
||||
|
||||
pub fn rent_projection(
|
||||
address: T::AccountId,
|
||||
) -> sp_std::result::Result<RentProjection<T::BlockNumber>, ContractAccessError> {
|
||||
rent::compute_rent_projection::<T>(&address)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
|
||||
Reference in New Issue
Block a user